首先自己用vs创建一个c++ dll,然后用depends查看导出的函数,如图:
这里是自己写的测试dll,下面有两个函数,创建c++dll的方法查看这篇博客:
https://blog.youkuaiyun.com/Alan_Program/article/details/93172050

以下是错误实例代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices; //dllimport需要的头文件
namespace csCallCPPDllDemo
{
class Program
{
[DllImport(@"MyMath.dll", EntryPoint = "my_add", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.stdcall)]
//[DllImport(@"E:\VS\VS_project\vs2013project_cs\csCallCPPDllDemo\csCallCPPDllDemo\testDll\MyMath.dll")]
extern static Int32 my_add(Int32 a, Int32 b);
[DllImport(@"MyMath.dll", EntryPoint = "my_sub", SetLastE

本文介绍了在VS2013中使用C#调用C++DLL时遇到的‘托管的PInvoke签名与非托管的目标签名不匹配’问题。通过分析错误实例代码,提出了两种解决方案:修改C#的DllImport声明添加CallingConvention参数或在C++DLL导出函数前声明__stdcall。正确修改调用约定后,成功调用DLL并指出了DLL导入路径的注意事项。
最低0.47元/天 解锁文章
2464

被折叠的 条评论
为什么被折叠?



