调用本机代码时抛出 ExecutionEngineException

发布于 2024-09-28 06:56:42 字数 513 浏览 0 评论 0 原文

我有一个由 C 库导出的函数,其签名如下:

extern "C" BOOL Func()

该函数在 VB.NET 代码中声明如下:

Private Shared Function Func() As Boolean

End Function

问题是我得到一个当我从 .NET 代码调用该函数时,出现 ExecutionEngineException。

鉴于此 C 代码中 BOOL 的类型定义为 int,声明是否应该有所不同?如果是这样,我应该如何声明?作为 ShortInt32?我需要整理返回值吗?

I have a function that is exported by a C library with the following signature:

extern "C" BOOL Func()

The function is declared in VB.NET code like this:

<DllImport("mylib.dll", CallingConvention:=CallingConvention.Cdecl)>

Private Shared Function Func() As Boolean

End Function

The problem is that I get an ExecutionEngineException when I call the function from .NET code.

Given that BOOL is typedef'd as int in this C code, should the declaration be different? If so, how should I be declaring this? As Short or Int32? Do I need to marshal the return value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分開簡單 2024-10-05 06:56:42

C 函数不返回真布尔值,而是返回整数。您可能需要对其进行正确编组

编辑:另外,你应该使你的函数静态。

The C function doesn't return a true boolean, it returns an integer. You might need to marshall it propery.

Edit: Also, you should make your function static.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文