不平衡堆栈! [英] Unbalanced Stack!

查看:391
本文介绍了不平衡堆栈!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了VC ++ DLL。对于DLL中的方法之一的声明如下:

I have written a VC++ dll. The declaration for one of the methods in the dll is as follows:

extern "C" _declspec(dllexport)
void startIt(int number)
{
     capture = cvCaptureFromCAM(number);
}



我使用P / Invoke使用此DLL在C#代码。我作出声明如下:

I use this dll in a C# code using P/Invoke. I make the declaration as:

[DllImport("Tracking.dll", EntryPoint = "startIt")]
        public extern static void startIt(int number);

和我打电话的代码功能:

and I call the function in the code as:

startIt(0);

现在,当遇到这条线时,编译器抛出我这个错误:

Now, when this line is encountered, the compiler is throwing me this error:

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.



我不明白为什么它在托管和非托管代码抛出这个错误作为签名都是一样的。此外,在我的另一台机器中,相同的代码是完全在视觉工作室运行。所以,这让我觉得,抛出的错误是误领先。

I cannot understand why is it throwing this error as the signature in both managed and unmanaged code are the same. Moreover, in my another machine, the same code is running perfectly in visual studio. So, this makes me think that the error thrown is mis leading.

请帮忙。

感谢

推荐答案

在p /调用外部功能,的调用约定的使用默认为 __ STDCALL 。由于您的函数使用 __ CDECL 约定,你需要将其申报为这样的:

When you p/invoke an external function, the calling convention used defaults to __stdcall. Since your function uses the __cdecl convention, you need to declare it as such:

[DllImport("Tracking.dll", EntryPoint = "startIt",
    CallingConvention = CallingConvention.Cdecl)]
public extern static void startIt(int number);

这篇关于不平衡堆栈!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆