pinvokestackimbalance - 我该如何解决这个问题,或把它关掉? [英] pinvokestackimbalance -- how can I fix this or turn it off?

查看:1068
本文介绍了pinvokestackimbalance - 我该如何解决这个问题,或把它关掉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚换从VS2008到VS2010。相同的解决方案,但现在一个C每一个呼叫++ DLL产生一个pinvokestackimbalance'例外。

I just switched to vs2010 from vs2008. Exact same solution, except now every single call to a C++ dll yields a 'pinvokestackimbalance' exception.

这异常不会在2008年被解雇我对C ++的dll和调用应用程序的完全访问权限。似乎没有要与PInvoke的任何问题,但此问题正在调试的其他问题是不可能的; IDE的不断停下来告诉我这些事情。

This exception does not get fired in 2008. I have complete access to the C++ dll and to the calling application. There does not appear to be any problem with the pinvoke, but this problem is making debugging other problems impossible; the IDE is stopping constantly to tell me about these things.

例如,这里的C#签名:

For instance, here's the C# signature:

    [DllImport("ImageOperations.dll")]
    static extern void FasterFunction(
        [MarshalAs(UnmanagedType.LPArray)]ushort[] inImage, //IntPtr inImage, 
        [MarshalAs(UnmanagedType.LPArray)]byte[] outImage, //IntPtr outImage, 
        int inTotalSize, int inWindow, int inLevel);

下面是它看起来像在C ++端:

Here's what it looks like on the C++ side:

#ifdef OPERATIONS_EXPORTS
#define OPERATIONS_API __declspec(dllexport)
#else
#define OPERATIONS_API __declspec(dllimport)
#endif
extern "C" {


OPERATIONS_API void __cdecl FasterFunction(unsigned short* inArray, 
                                       unsigned char* outRemappedImage,
                                       int inTotalSize, 
                                       int inWindow, int inLevel);

}

什么是VS2010和VS2008会导致这些例外抛出之间有什么不同?我应该加入不同的参数的指令的DllImport?

What's different between vs2010 and vs2008 that would cause these exceptions to get thrown? Should I be adding a different set of parameters to the DllImport directive?

推荐答案

首先,明白,code是错误的(而且一直)。在pInvokeStackImbalance也不例外本身,而是一个托管调试助手。这是默认关闭的VS2008,但很多人并没有打开它,所以它在默认情况下VS2010的上。 MDA的不发行模式下运行,所以如果你建立的释放不会触发。

First, understand that the code is wrong (and always has been). The "pInvokeStackImbalance" is not an exception per se, but a managed debugging assistant. It was off by default in VS2008, but a lot of people did not turn it on, so it's on by default in VS2010. The MDA does not run in Release mode, so it won't trigger if you build for release.

在你的情况,调用约定不正确。 的DllImport 默认为 CallingConvention.WinApi ,这等同于 CallingConvention.StdCall 适用于x86桌面code。它应该是 CallingConvention.Cdecl

In your case, the calling convention is incorrect. DllImport defaults to CallingConvention.WinApi, which is identical to CallingConvention.StdCall for x86 desktop code. It should be CallingConvention.Cdecl.

这篇关于pinvokestackimbalance - 我该如何解决这个问题,或把它关掉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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