如果你是一位Windows程序员,那么必定会熟悉那无所不能的Win32API,伴随着一代Windows平台上的老程序员。至微软推出.NET平台后,依靠Windows SDK,Win32API编程的年代已经逐渐远去。然而,.NET如日中天,虽然她对Win32API进行了完美的封装,但必要时候,还是需要调用原始的Win32API,才能实现部分复杂的功能。下面就是最简单的调用方式。
using System;
using System.Collections.Generic;
using System.Text;using System.Runtime.InteropServices;
namespace win32API{
class Program {
[DllImport("User32.dll")]
public static extern int MessageBox(int h, string m, string c, int type);
static int Main(string[] args)
{
MessageBox(0,"hello win32api","就这么调的",4);
Console.ReadLine();
return 0;
}
}}