请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配

在c#中引入c++生成的dll,出现了如下问题:
对 PInvoke 函数“GAProject!GAProject.Form1::Add”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。

解决方案:
[DllImport("Dll.dll")] 改为[DllImport("Dll.dll", CallingConvention=CallingConvention.Cdecl)]
DllImport的CallingConvention的属性,默认值是CallingCovention.Stdcall,  此处更改成Cdecl(c/c++默认调用方式)就可以了。
  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 17
    评论
PInvoke插件 RedGate.PInvokeExtension VS平台调用插件 PInvoke 平台调用 调用C++ 调用系统 C#调C++, Search Module: Directory Constants Delegates Enums Interfaces Structures Desktop Functions: advapi32 avifil32 cards cfgmgr32 comctl32 comdlg32 credui crypt32 dbghelp dbghlp dbghlp32 dhcpsapi difxapi dmcl40 dnsapi dtl dwmapi faultrep fbwflib fltlib fwpuclnt gdi32 gdiplus getuname glu32 glut32 gsapi hhctrl hid hlink httpapi icmp imm32 iphlpapi iprop irprops kernel32 mapi32 MinCore mpr mqrt mscorsn msdelta msdrm msi msports msvcrt ncrypt netapi32 ntdll ntdsapi odbc32 odbccp32 ole32 oleacc oleaut32 opengl32 pdh powrprof printui propsys psapi pstorec query quickusb rasapi32 rpcrt4 scarddlg secur32 setupapi shell32 shlwapi twain_32 unicows urlmon user32 userenv uxtheme version wer wevtapi winfax winhttp wininet winmm winscard winspool wintrust winusb wlanapi ws2_32 wtsapi32 xolehlp xpsprint Smart Device Functions: aygshell coredll ipaqutil rapi Glossary distributed computing LibHolocaust Marshaling Marshalling Marshalling PInvoke test pinvoke Show Recent Changes Subscribe (RSS) Misc. Pages Comments FAQ Helpful Tools Playground Suggested Reading Website TODO List Support Forum Download Visual Studio Add-In Terms of Use Privacy Policy Create page PInvoke (glossary) Summary The mechanism provided by the CLR that enables managed code to call static DLL exports. Access PInvoke.net directly from VS: Terms of Use Edit This Page Find References Show Printable Version Revisions Show changes

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值