0

我一直在尝试更新到最新的 HDF5DotNet 包装器(1.8.7)并收到以下警告(从 VS2010 在 DEBUG 模式下运行时):

检测到 PInvokeStackImbalance 消息:对 PInvoke 函数 'HDF5DotNet!::H5Fopen' 的调用使堆栈不平衡。这可能是因为托管 PInvoke 签名与非托管目标签名不匹配。检查 PInvoke 签名的调用约定和参数是否与目标非托管签名匹配。

我正在使用预编译的二进制文件(.NET Framework 4.0 32 位的 HDF5DotNet 程序集),但是当我从源代码编译时得到了相同的结果。

奇怪的是,当我在非调试模式下执行调用 HDF5DotNet 包装器的应用程序时,我没有发现任何问题。我确实注意到在 1.8.6 和 1.8.7 之间所有的调用约定都从 Cdecl 切换到了 StdCall。这可能是造成这种情况的原因吗?我看过其他论坛说 CallingConvention 应该是 Cdecl ......

谢谢!

4

1 回答 1

2

Yes, calling a stdcall function as cdecl or the other way round causes a stack imbalance. The main difference between these conventions is that with cdecl the caller is responsible for removing the arguments from the stack, with stdcall the callee is responsible.

I guess in release mode you have the same bug. But you don't get the error because some runtime checks are disabled. A native program would crash in most cases where you use the wrong calling convention, but it seems like the .net interop code has a more robust stack handling that masks this problem.

于 2011-05-26T22:25:38.013 回答