1、新建一个类库。

5、生成dll,在菜单栏在生成里点击“生成dlltest”,或者按shfit+F6生成成功,在目录下能看到生成的Dll:

6、调用该dll,新建一个控制台应用程序,来实现该dll的调用。新建一个DLLExample。

9、在“查找范围里找到,我们生成的dll,点击确定。在解决方案中显示如下内容,说明你添加成功!

11、这时我就可以在程序中调用了。在program.cs中添加如下代码:using System;using System.Collections.Generic;using System.Text;//必须添加using System.Runtime.InteropServices;using DllTest;namespace DllExample{ class Program { //DllTest,我们的动态链接库 [DllImport("DllTest.dll")] //public static extern void ShowMessage(); static void Main(string[] args) { //实例化 DllTest.Class1 i = new Class1(); //调用动态链接库的方法 i.ShowMessage(); } }}
