我写了一个VC++动态链接库。其中一个方法的声明如下:
extern "C" _declspec(dllexport)
void startIt(int number)
{
capture = cvCaptureFromCAM(number);
}
我在使用P/Invoke的C#代码中调用这个dll。我的声明如下:
[DllImport("Tracking.dll", EntryPoint = "startIt")]
public extern static void startIt(int number);
我会把函数写在代码里,然后这样调用:
startIt(0);
现在,当遇到这行代码时,编译器会抛出以下错误:
A call to PInvoke function 'UsingTracking!UsingTracking.Form1::startIt' has
unbalanced the stack. This is likely because the managed PInvoke signature does
not match the unmanaged target signature. Check that the calling convention
and parameters of the PInvoke signature match the target unmanaged signature.
我不明白为什么会出现这个错误,因为托管代码和非托管代码的签名是相同的。此外,在另一台机器上,相同的代码在 Visual Studio 中运行得很完美。所以,这让我认为抛出的错误是误导性的。
请帮忙解决。
谢谢。