1

Topic: How correctly to transfer object from C# in C library ++?

I welcome. There is a library on a C ++. There is a program on C# which uses it. As parameters the library accepts "structure from structure from links to functions": public enum CallbackResult {OPERATION_OK, OPERATION_ERR} public class LibraryMediatorClass {#region structures and classes [StructLayout (LayoutKind. Sequential, Pack = 1)] public struct LibraryInitialContext {//[MarshalAs (UnmanagedType. LPStruct)] public SetOfCallbacks callbacks;}; [StructLayout (LayoutKind. Sequential, Pack = 1)] public struct SetOfCallbacks {//[MarshalAs (UnmanagedType. LPStruct)] public SendAPDU sendAPDU;} ; #endregion #region variables [UnmanagedFunctionPointer (CallingConvention. Cdecl)] public delegate CallbackResult SendAPDU ([MarshalAs (UnmanagedType. LPStr)] String apdu, ulong apduLength, [MarshalAs (UnmanagedType. LPStr)] String response, ulong maxResponseLength, [MarshalAs (UnmanagedType. U8)] UInt64 responseLength); [DllImport ("com_ftc_library_lib_s.dll", CharSet = CharSet. Unicode, SetLastError = true, EntryPoint = "initializeLibrary", CallingConvention = CallingConvention. Cdecl)] private static extern int initializeLibrary ([In] LibraryInitialContext context); #endregion #region functions public LibraryMediatorClass () {SetOfCallbacks soc = new SetOfCallbacks (); soc.sendAPDU = new SendAPDU (_SendAPDU); LibraryInitialContext libraryInitialContext = new LibraryInitialContext (); libraryInitialContext.callbacks = soc; int qwe = initializeLibrary (libraryInitialContext);} public static CallbackResult _SendAPDU ([MarshalAs (UnmanagedType. LPStr)] String apdu, ulong apduLength, [MarshalAs (UnmanagedType. LPStr)] String response, ulong maxResponseLength, [MarshalAs (UnmanagedType. U8)] UInt64 responseLength) {return CallbackResult. OPERATION_OK;} #endregion} After start function initializeLibrary returns Exception type "read or write Attempt in the protected storage..." Predpologaju, what incorrectly I declare structures/classes in structures which are transferred in library (the commented out attributes)? Prompt how to transfer, please, the similar data in library With ++? What do I do not so? Thanks big!

2

Re: How correctly to transfer object from C# in C library ++?

Tried to declare structures so: [StructLayout (LayoutKind. Sequential, Pack = 1)] public struct LibraryInitialContext {[MarshalAs (UnmanagedType. Struct)] public SetOfCallbacks callbacks;}; [StructLayout (LayoutKind. Sequential, Pack = 1)] public struct SetOfCallbacks {[MarshalAs (UnmanagedType. FunctionPtr)] public SendAPDU sendAPDU;}; did not help. The same.

3

Re: How correctly to transfer object from C# in C library ++?

Hello, lesovick, you wrote: [Skip] L> did not help. The same. You did not try to make an interlayer on a C ++/CLI? Or it not a variant?

4

Re: How correctly to transfer object from C# in C library ++?

Hello, lesovick, you wrote: L> I Welcome. L> there is a library on a C ++. There is a program on C# which uses it. Normally write a component-wrapper on a C ++/CLI since she on the one hand is able to understand managed-types and them lifetime, and on the other hand it is capable to work from a C/C ++ memory model. Also it is very important to answer questions at first: who selects storage and who releases it (to avoid leaks or attempt to climb in already killed storage).  goes already following step (to avoid unnecessary copying, etc.).

5

Re: How correctly to transfer object from C# in C library ++?

Hello, lesovick, you wrote: L> As parameters the library accepts "structure from structure from links to functions": And what for to you the method address C# in the code on With ++?

6

Re: How correctly to transfer object from C# in C library ++?

Hello, Nikolay_Ch, you wrote: N_C> And what for to you the method address C# in the code on With ++? 1) Well as. So it is made, that it was possible to implement a functional which is necessary in any special case for the given functions. 2) the library on With ++ is written not by me. It only is used by me. Constructing it in another way or that in it something is organized not and it is necessary to make in another way speech does not go. It needs to be used such what it is. At my instruction is only dll and a heading file with the description.

7

Re: How correctly to transfer object from C# in C library ++?

Hello, lesovick, libraryInitialContext - has time to become rotten...?

8

Re: How correctly to transfer object from C# in C library ++?

Hello, buser, you wrote: B> Hello, lesovick, libraryInitialContext - has time to become rotten...? I Am sorry, I did not understand a question.