C # C ++ Interop Delegate

I would like a preface to this with the fact that I don't have formal C ++ training, so if you have any suggestions, provide a way that super noob might have.
Thank you in advance.
What I'm trying to do is call the C ++ function from C # pass in structure and delegation.
My code works, but if I access the value in the delegate, I get this error:
Delegate error image
Here is my C # code:

public delegate void CallBackMethodDelegate(MP4CreateClipProcessingData data); [DllImport("libmp4v2.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] [return: MarshalAs(UnmanagedType.LPStr)] public extern static string MP4CreateClip(ref MP4CreateClipProcessingData data, CallBackMethodDelegate del); 

And here is my C ++ code:

 struct MP4CreateClipProcessingData { bool err; char* sourcePath; char* targetPath; char* error; uint32_t startTime; uint32_t duration; }; extern "C" __declspec(dllexport) void MP4CreateClip(MP4CreateClipProcessingData data, void (_stdcall *func)(MP4CreateClipProcessingData)) { func(data); } 

This is where, in my C # code, I call a function:

 var data = new NativeMethods.MP4CreateClipProcessingData(file, Path.Combine(targetPath, Path.GetFileName(file).ToString())); NativeMethods.CallBackMethodDelegate retDel = new NativeMethods.CallBackMethodDelegate(NativeMethods.returnCall); NativeMethods.MP4CreateClip(ref data, retDel); 
+4
source share

All Articles