Jay*_*esh 7 c# dll pinvoke visual-c++
我写了一个VC++ DLL.dll中某个方法的声明如下:
extern "C" _declspec(dllexport)
void startIt(int number)
{
capture = cvCaptureFromCAM(number);
}
Run Code Online (Sandbox Code Playgroud)
我使用P/Invoke在C#代码中使用此dll.我将声明作为:
[DllImport("Tracking.dll", EntryPoint = "startIt")]
public extern static void startIt(int number);
Run Code Online (Sandbox Code Playgroud)
我将代码中的函数调用为:
startIt(0);
Run Code Online (Sandbox Code Playgroud)
现在,遇到这一行时,编译器会抛出这个错误:
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.
Run Code Online (Sandbox Code Playgroud)
我不明白为什么它在托管和非托管代码引发此错误的签名是相同的.而且,在我的另一台机器上,相同的代码在visual studio中运行得很好.所以,这让我觉得抛出的错误是误导.
请帮忙.
谢谢
Fré*_*idi 13
当您调用外部函数时,使用的调用约定默认为__stdcall.由于您的函数使用__cdecl约定,因此您需要将其声明为:
[DllImport("Tracking.dll", EntryPoint = "startIt",
CallingConvention = CallingConvention.Cdecl)]
public extern static void startIt(int number);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2911 次 |
| 最近记录: |