Reputation: 21548
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 a p/invoke unbalanced stack likely caused by the managed signature not matching the unmanaged signature.
Can anyone see what is wrong with this?
Upvotes: 0
Views: 329
Reputation: 613531
It's a calling convention mismatch. The C++ code uses cdecl
by default but the C# assumes stdcall
. You need to make them match, e.g.
[DllImport("capture.dll", EntryPoint = "setup",
CallingConvention = CallingConvention.Cdecl)]
public static extern void captureSetup(int rr);
Upvotes: 6