调用到PInvoke的功能失衡堆栈。这可能是因为管理的PInvoke ..(.NET 4) [英] A call to PInvoke function has unbalanced the stack. This is likely because the managed PInvoke .. (.NET 4)

查看:124
本文介绍了调用到PInvoke的功能失衡堆栈。这可能是因为管理的PInvoke ..(.NET 4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目成功运行,而不在.NET框架3.5的工作失误。但是,当我的目标是到.NET框架的工作4.我得到了错误:

My project run successful without errors in .NET Frame work 3.5. But, When I target it to .NET Frame work 4. I got the error:

的调用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)

你知道如何解决这个问题?

Do you know how to fix this error ?

推荐答案

将此与DLL的导入。

, CallingConvention = CallingConvention.Cdecl)]

由于取自这里

平台调用

要提高互操作性性能   非托管code,在一个平台上调用不正确的调用约定,现在   导致应用程序失败。在previous版本,封送处理   层解决这些错误堆栈。

To improve performance in interoperability with unmanaged code, incorrect calling conventions in a platform invoke now cause the application to fail. In previous versions, the marshaling layer resolved these errors up the stack.

调试应用程序   在Microsoft Visual Studio 2010将提醒您注意这些错误,所以你   可以纠正他们。如果你有二进制文件不能被更新,你可以   包括在该元件的   应用程序的配置文件,使调用错误是   解决了堆栈的早期版本。然而,这可能会影响   您的应用程序的性能。

Debugging your applications in Microsoft Visual Studio 2010 will alert you to these errors so you can correct them. If you have binaries that cannot be updated, you can include the element in your application's configuration file to enable calling errors to be resolved up the stack as in earlier versions. However, this may affect the performance of your application.

这篇关于调用到PInvoke的功能失衡堆栈。这可能是因为管理的PInvoke ..(.NET 4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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