c#调用win32 Api示例

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    class myApi
    {
        public const int MB_OK = 0;
        [DllImportAttribute("user32.dll")] //载入外部 api函数所在的动态链接库文件
        public static extern int MessageBox(IntPtr hwnd,string text,string caption,int type);  //调用外部 api函数的声明
    }

    class Program
    {
        static void Main(string[] args)
        {
            myApi.MessageBox(IntPtr.Zero,"调用的是win32api的MessageBox","提示信息",myApi.MB_OK); //设用外部api(MessageBox函数)
        }
    }
}
posted @ 2010-03-09 16:43  一笑解千愁  Views(229)  Comments(0)    收藏  举报