创建一个名叫【Win32】的类,主要是用来存放所有要调用的方法声明:
public class Win32
{
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);
}
声明后在代码中直接使用即可。
Win32.MessageBox(new IntPtr(0), "Hello World", "Platform Invoke Sample", 0);