博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
解决:对 PInvoke 函数的调用导致堆栈不对称问题
阅读量:6969 次
发布时间:2019-06-27

本文共 961 字,大约阅读时间需要 3 分钟。

解决:对 PInvoke 函数的调用导致堆栈不对称问题

问题描述:

在使用托管代码调用非托管代码时,发生“对 PInvoke 函数“UseTwiHikVisionDllTest!UseTwiHikVisionDllTest.TwiHikVision::GetFirstPic”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。”

解决方法:

添加属性:CallingConvention=CallingConvention.Cdecl

如:
[DllImport("TwiHikVision.dll", EntryPoint="GetFirstPic",CallingConvention=CallingConvention.Cdecl)]
public static extern string GetFirstPic(string videoFileName, string exportFilePath);
网络参考可能原因:
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b0637998-dc89-4ff9-b59d-5ad262a48bc6
You need to set the calling convention. The default convention (stdcall) is not correct, which will cause P/Invoke stack imbalances.

For example, your first call should look like:

[DllImport("Service.dll", CallingConvention=CallingConvention.Cdecl)] static private extern IntPtr CallCreateClass();
By default, C and C++ use cdecl - but marshalling uses stdcall to match the Windows API.

转载地址:http://fnisl.baihongyu.com/

你可能感兴趣的文章
XoftSpy 4.13的注册算法分析
查看>>
递归的隐含限制——处理对象小的可以、大的不可以
查看>>
Android APK反编译具体解释(附图)
查看>>
深入分析Java Web技术内幕(修订版)
查看>>
(转)Nginx反向代理设置 从80端口转向其他端口
查看>>
Java设计模式----初识适配器模式
查看>>
JavaScript定义类的几种方式
查看>>
【BZOJ】1682: [Usaco2005 Mar]Out of Hay 干草危机(kruskal)
查看>>
25、BroadCastRecevier
查看>>
MongoDB学习(二)Windows环境安装MongoDB
查看>>
MongoDB基本命令随便敲敲
查看>>
小程序员在安卓移动应用上的赚钱经历
查看>>
迁移到 Express 4.x
查看>>
用sql语句按周、按月、按季、按年统
查看>>
linux下的僵尸进程处理SIGCHLD信号
查看>>
分享JQuery动画插件Velocity.js的六种列表加载特效
查看>>
编写你自己的单点登录(SSO)服务
查看>>
执行游戏时出现0xc000007b错误的解决方法
查看>>
编译是报error: 'EVNET_COME_TO_FOREGROUND' was not declared in this scope
查看>>
maven
查看>>