C#调用Win32 API 的方法

创建一个名叫【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);

  

posted @ 2021-05-14 09:44  奥兰王子  阅读(438)  评论(0编辑  收藏  举报