//using System.Runtime.InteropServices; class ExternTest {
//通过dllimport导入user32.dll外部程序集
[DllImport("User32.dll", CharSet=CharSet.Unicode)] 外部程序集的方法messagebox,注意static与extern须一并出现
public static extern int MessageBox(IntPtr h, string m, string c, int type); static int Main() { string myString; Console.Write("Enter your message: "); myString = Console.ReadLine();
//调用来自于user32.dll中的方法messagebox
return MessageBox((IntPtr)0, myString, "My Message Box", 0); } }
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9240380/viewspace-707615/ ,如需转载,请注明出处,否则将追究法律责任。