c#种怎么直接调用win32 api啊??

如题所述

使用DIIImport特性可以指示CLR从哪个DLL导出想要调用的函数。GDI32.dll、Kernel32.dll和User32.dll是最常用的三个DLL。如果不确定哪个DLL定义了需要使用的WindowsAPI函数,可以参考PlateformSDK文档。
例子:(需要引入命名空间using System.Runtime.InteropServices)
//声明非托管函数
[Dlllmport("user32.dll",EnterPoint="MessageBoxA")]
public static extern int MsgBox(int h,string m,string c,int type);
public static int Main()
{
retrn MsgBox(0,"Hello World!","MessageBoxA in c#",0);//消息框
}
使用前需要先确定你要调用的方法就在你引用的DLL中
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-11-03
[DllImport("user32.dll ", EntryPoint = "要调用的API函数名字")]