要使用user32.dll的MessageBox弹窗消息,自然需要引入user32.dll到项目中。

一个最简单的实例如下:

using System;
using System.Runtime.InteropServices;

class Example
{
    // Use DllImport to import the Win32 MessageBox function.
    [DllImport("user32.dll", CharSet = CharSet.Unicode)]
    public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);

    static void Main()
    {
        // Call the MessageBox function using platform invoke.
        MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0);
    }
}

运行项目后,直接弹出弹窗消息。

【C#】使用user32.dll的MessageBox弹窗消息

这是C#使用外部DLL中的方法,项目的引用中并没有显示该user32.dll。

【C#】使用user32.dll的MessageBox弹窗消息

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2021-07-01
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-06
  • 2021-08-28
  • 2022-12-23
  • 2021-11-14
  • 2021-08-13
  • 2022-12-23
  • 2021-12-14
相关资源
相似解决方案