开发者

AccessViolationException when PInvoking C++ DLL (cdecl calling convention problem?) [closed]

开发者 https://www.devze.com 2023-03-04 04:35 出处:网络
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.

Closed 4 years ago.

Improve this question

I've spent all day researching this, and I'm none the wiser:

I have a C# DLL which PInvokes a method in a C++ DLL. I have had no problems doing this when compiling in Debug mode, but when compiling in Release mode I get an AccessViolationException. Googling this problem tells me that it's probably an issue with incompliant calling conventions. The code now looks like this in C#:

[return: M开发者_运维百科arshalAs(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've set the C++ project to compile with the __cdecl calling convention in VS2010, but I still get the AccessViolationException and I have no idea what more I can do. I should note that my C++ DLL uses third-party DLLs, and I do not know what calling convention they use.

Any help would be appreciated!

Oh, and I don't get the exception on my development machine, only on my target system.


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

精彩评论

暂无评论...
验证码 换一张
取 消