1.创建一个“类库”项目
2.写入对应代码
using System.Runtime.InteropServices;
namespace TestDll
{
public interface ITestClass
{
void Procedure(stirng param1);
}
[ClassInterface(ClassInterfaceType.None)]
public class TestClass :ITestClass
{
[DllImport(“User32.dll”, SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
public static extern int MessageBox(IntPtr handle, string message, string title, int type);
public void Procedure (stirng param1);
{ //自己的代码
AutoShutDown(param1);
}
}
}
3.完成之后,设置项目的属性->程序集信息->“Make assembly COM-Visible/使得程序集COM可见”为选中状态, 属性->生成->为COM互操作注册、Register for COM interop。
4.管理员模式运行Vs自带工具的命令行
5.Regasm 路径/xxxxx.dll 向系统注册此dll
注意 C++相关库请使用regsvr32注册dll
6.TlbExp 路径/xxxxxx.dll 生成tlb文件
x64的xxxxx.tlb在系统盘:/Window