AccessViolationException when PInvoking C ++ DLL (problem calling cdecl call?)

I spent all day exploring this, and I'm no wiser:

I have a C # DLL, which has a PInvokes method in a C ++ DLL. I had no problems with this when compiling in Debug mode, but when compiling in Release mode, I get an AccessViolationException. Going to this problem tells me that this is probably a problem with incompatible calls. Now the C # code looks like this:

[return: MarshalAs(UnmanagedType.U1)] [DllImport("Native.dll", CallingConvention = CallingConvention.Cdecl)] internal static extern Boolean AMethod(Int32 mode, byte frame); 

and in C ++:

 extern "C" { DLL_EXPORT bool AMethod(int mode, BYTE frame) { ... } } 

I installed a C ++ project for compilation using the __cdecl declaration convention in VS2010, but I still get an AccessViolationException, and I have no idea what else I can do. I should note that my C ++ DLL uses third-party DLLs, and I donโ€™t know what calling convention they use.

Any help would be appreciated!

Oh, and I get no exception on my development machine, only on my target system.

+7
source share
1 answer

Try with this reordering of statements:

  [DllImport ("Native.dll", CallingConvention = CallingConvention.Cdecl)]
 [return: MarshalAs (UnmanagedType.U1)]
 internal static extern Boolean AMethod (Int32 mode, byte frame);
0
source

All Articles