它来调用WIN32的API或者调用一下C或C++编写的DLL。
使用实例:
将编译好的C++ DLL拷贝到BIN目录(DLLImport会从程序启动目录BIN开始查找相应名称的DLL,未找到则转至system32下查找)
程序写法:
一、引用命名空间:函数
using System.Runtime.InteropServices;
二、建立函数名称blog
[DllImport("demo.dll")] public static extern bool OpenDemo();
三、DllImportAttribute属性用法get
[AttributeUsage(AttributeTargets.Method)] public class DllImportAttribute: System.Attribute { public DllImportAttribute(string dllName) {…} //定位参数为dllName public CallingConvention CallingConvention; //入口点调用约定 public CharSet CharSet; //入口点采用的字符接 public string EntryPoint; //入口点名称 public bool ExactSpelling; //是否必须与指示的入口点拼写彻底一致,默认false public bool PreserveSig; //方法的签名是被保留仍是被转换 public bool SetLastError; //FindLastError方法的返回值保存在这里 public string Value { get {…} } }