gpt4 book ai didi

c# - 对 PInvoke 函数的调用使堆栈不平衡。这可能是因为托管 PInvoke .. (.NET 4)

转载 作者:可可西里 更新时间:2023-11-01 03:04:21 26 4
gpt4 key购买 nike

我的项目在 .NET Frame work 3.5 中运行成功且没有错误。但是,当我将它定位到 .NET Frame work 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)

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

最佳答案

将其与 dll 导入一起添加。

, CallingConvention = CallingConvention.Cdecl)]

摘自 here .

Platform invoke

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.

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.

关于c# - 对 PInvoke 函数的调用使堆栈不平衡。这可能是因为托管 PInvoke .. (.NET 4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20372876/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com