到PInvoke的函数调用'[...]'有不平衡栈 [英] A call to PInvoke function '[...]' has unbalanced the stack

查看:173
本文介绍了到PInvoke的函数调用'[...]'有不平衡栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿结果
我的一些东西,我已经使用了相当长一段时间得到这个奇怪的错误。这可能是在Visual Studio 2010中一个新的东西,但我不知道。结果
我试图调用从C#用C ++编写一个函数unamanged。结果
从我读过的互联网上的错误信息本身它有事情做的事实,在我的C#文件中的签名是不一样的从C ++中,但我真的无法看到它。结果
首先,这是我下面unamanged功能:结果
TEngine GCreateEngine(INT宽度,高度INT,INT深度,诠释的devicetype);
这里是我在C#中的功能:结果
函数[DllImport(Engine.dll,入口点=GCreateEngine,CallingConvention = CallingConvention.StdCall)]结果
        公共静态外部的IntPtr CreateEngine(INT宽度,高度INT,INT深度,诠释设备);
结果
当我进入调试C ++我看到的所有参数就好所以因此,我只能认为它有事情做与TEngine转变(这是一个指向名为CEngine一类)的IntPtr。我之前在VS2008没有问题用这个。结果
我希望我的问题是明确的足够你们理解。

Hey
I'm getting this weird error on some stuff I've been using for quite a while. It may be a new thing in Visual Studio 2010 but I'm not sure.
I'm trying to call a unamanged function written in C++ from C#.
From what I've read on the internet and the error message itself it's got something to do with the fact that the signature in my C# file is not the same as the one from C++ but I really can't see it.
First of all this is my unamanged function below:
TEngine GCreateEngine(int width,int height,int depth,int deviceType); And here is my function in C#:
[DllImport("Engine.dll", EntryPoint = "GCreateEngine", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr CreateEngine(int width,int height,int depth,int device);

When I debug into C++ I see all arguments just fine so thus I can only think it's got something to do with transforming from TEngine (which is a pointer to a class named CEngine) to IntPtr. I've used this before in VS2008 with no problem.
I hope my problem is clear enough for you guys to understand.

推荐答案

也许问题出在调用约定。你确定非托管函数被编译为STDCALL,而不是其他的东西(我会猜FASTCALL)?

Maybe the problem lies in the calling convention. Are you sure the unmanaged function was compiled as stdcall and not something else ( i would guess fastcall ) ?

这篇关于到PInvoke的函数调用'[...]'有不平衡栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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