简体   繁体   中英

p/invoke unbalanced stack error

I have the following C++ function and C# p/invoke decleration:

//C#
[DllImport("capture.dll", EntryPoint = "setup")]
public static extern void captureSetup(int rr);

//C++
extern "C" {
    __declspec(dllexport) void setup(int rr)

But I am getting an error about ap/invoke unbalanced stack likely caused by the managed signature not matching the unmanaged signature.

Can anyone see what is wrong with this?

It's a calling convention mismatch. The C++ code uses cdecl by default but the C# assumes stdcall . You need to make them match, eg

[DllImport("capture.dll", EntryPoint = "setup", 
    CallingConvention = CallingConvention.Cdecl)]
public static extern void captureSetup(int rr);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM