【发布时间】:2010-11-13 09:12:34
【问题描述】:
我已经编写了一个 VC++ dll。 dll中其中一个方法的声明如下:
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 中完美运行。所以,这让我认为抛出的错误是误导。
请帮忙。
谢谢
【问题讨论】:
-
你的一台机器是 x86 而另一台是 x64 吗?
-
不,两者都是 x86。只是那个运行Win7和其他XP
标签: c# visual-c++ dll pinvoke