对PInvoke函数的调用使堆栈失衡.这很可能是因为托管的PInvoke ..(.NET 4)

tai*_*ibc 18 .net c# pinvoke

我的项目在.NET Frame 3.5中成功运行且没有错误.但是,当我将它定位到.NET Frame工作4.我得到了错误:

" 对PInvoke函数的调用使堆栈失衡.这可能是因为托管的PInvoke签名与非托管目标签名不匹配. "

我使用了非托管库,如下所示:

[StructLayout(LayoutKind.Sequential )]
public class DGNElemCore
{
    public int offset;
    public int size;
    public int element_id;
    public int stype;          
    public int level;
    public int type;
    public int complex;
    public int deleted;
    public int graphic_group;
    public int properties;
    public int color;
    public int weight;
    public int style;
    public int attr_bytes;       
    public IntPtr attr_data;  
    public int raw_bytes;
    public IntPtr raw_data;                 

}

[DllImport("DgnLib.dll", EntryPoint = "DGNOpen")]           
public static extern IntPtr  DGNOpen(string fileName, int bUpdate)
Run Code Online (Sandbox Code Playgroud)

你知道如何解决这个错误吗?

Ehs*_*san 45

将其与dll导入一起添加.

, CallingConvention = CallingConvention.Cdecl)]
Run Code Online (Sandbox Code Playgroud)

这里开始.

平台调用

为了提高与非托管代码的互操作性能,平台调用中的错误调用约定现在导致应用程序失败.在以前的版本中,编组层在堆栈中解决了这些错误.

在Microsoft Visual Studio 2010中调试应用程序将提醒您这些错误,以便您可以更正它们.如果您有无法更新的二进制文件,则可以在应用程序的配置文件中包含该元素,以使调用错误能够像早期版本一样在堆栈中解析.但是,这可能会影响应用程序的性能.

  • 我不知道链接中的那些段落如何解释为什么需要指定调用约定?什么是"不正确"开始?使用Declare语句的VB代码不使用属性. (2认同)