在.net 4:PInvokeStackImbalance异常 [英] in .Net 4: PInvokeStackImbalance Exception

查看:176
本文介绍了在.net 4:PInvokeStackImbalance异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的是从 MSVCRT.DLL 的strlen 函数在.NET 3.5的项目。更具体地讲:

I was using the strlen function from msvcrt.dll in a .Net 3.5 project. More specifically:

私人不安全的静态外部INT的strlen(BYTE * PBYTE);

迁移到.NET 4.0之后,如果我使用这个功能,它抛出一个 PInvokeStackImbalance 例外。

After migrating to .NET 4.0, if I use this function it throws a PInvokeStackImbalance exception.

如何导入在.NET 3.5 MSVCRT.DLL 或修复此异常?

How can I import the .NET 3.5 msvcrt.dll or fix this exception?

推荐答案

我怀疑问题出在调用约定,你应该使用的cdecl。

I suspect that the problem is with the calling convention, you should be using Cdecl.

[DllImport("msvcrt.dll", CallingConvention=CallingConvention.Cdecl)]
private unsafe static extern int strlen(byte* pByte);

这篇关于在.net 4:PInvokeStackImbalance异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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