首先在C#工程下面安装第三方插件包
安装方法:Tools --> Library Package Manager --> Package Manager Console
Install-Package UnmanagedExports
并添加:
using System.Runtime.InteropServices;
using RGiesecke.DllExport;
class Test
{
[DllExport("add", CallingConvention = CallingConvention.Cdecl)]
public static int TestExport(int left, int right)
{
return left + right;
}
}
注意点击Project-->properties-->Application-->Output type-->Class Library
点击工程Build即可生成dll
调用的时候用普通的C++调用dll的方式即可
__declspec(dllimport) void getx(int a, int b);