這是運行結果:

Api函數是構築Windws應用程序的基石,每一種Windows應用程序開發工具,它提
供的底層函數都間接或直接地調用了Windows API函數,同時為了實現功能擴
展,一般也都提供了調用WindowsAPI函數的接口, 也就是說具備調用動態連接
庫的能力。Visual C#和其它開發工具一樣也能夠調用動態鏈接庫的API函
數。.NET框架本身提供了這樣一種服務,允許受管轄的代碼調用動態鏈接庫中實
現的非受管轄函數,包括操作系統提供的Windows API函數。它能夠定位和調用輸
出函數,根據需要,組織其各個參數(整型、字符串類型、數組、和結構等等)跨
越互操作邊界。
參考:http://hovertree.com/h/bjaf/tc63n4t2.htm
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace HoverTreeWinForm
{
public partial class FormHewenqi : Form
{
/// <summary>
/// http://hovertree.com/h/bjaf/v4y0b2l6.htm
/// </summary>
/// <param name="h"></param>
/// <param name="m"></param>
/// <param name="c"></param>
/// <param name="type"></param>
/// <returns></returns>
[DllImport("User32.dll")]
public static extern int MessageBox(int h, string m, string c, int type);
public FormHewenqi()
{
InitializeComponent();
}
private void button_hewenqi_Click(object sender, EventArgs e)
{
MessageBox(0, "Hello Win32 API HoverTree", "何問起網", 4);
}
private void linkLabel_help_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://hovertree.com/h/bjaf/v4y0b2l6.htm");
}
}
}
源碼下載