C# 动态链接库的创建

首先在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);

 

posted @ 2015-12-23 18:48  一样菜  阅读(520)  评论(0编辑  收藏  举报