如:
using Microsoft.Win32;
using System.Runtime.InteropServices;
public class APILib
{
public APILib()
{
//
// TODO: Add constructor logic here
//
}
[DllImport("User32.dll",EntryPoint="MessageBox",CharSet=CharSet.Auto,ExactSpelling=false)]
public static extern int MsgBox(int hWnd,String text,String caption,uint type);
}使用APILib.MsgBox(0,"adasfsdfsfs","Caption",0);
using Microsoft.Win32;
using System.Runtime.InteropServices;
public class APILib
{
public APILib()
{
//
// TODO: Add constructor logic here
//
}
[DllImport("User32.dll",EntryPoint="MessageBox",CharSet=CharSet.Auto,ExactSpelling=false)]
public static extern int MsgBox(int hWnd,String text,String caption,uint type);
}使用APILib.MsgBox(0,"adasfsdfsfs","Caption",0);
namespace 获得MAC地址
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
}
///////引用 [DllImport("Iphlpapi.dll")]
public static extern int SendARP (Int32 dest,Int32 host,ref Int64 mac,ref Int32 length);//dest为目标机器的IP;Host为本机器的IP [DllImport("Ws2_32.dll")]
public static extern Int32 inet_addr (string ip);
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
this.textBox1.Text="192.168.0.1";
this.textBox2.Text="";
} private void button1_Click(object sender, System.EventArgs e)
{
string s;
this.button1.Enabled=false;
IPHostEntry myin=Dns.GetHostByName(System.Environment.MachineName);
Int32 mysource=inet_addr(myin.AddressList[0].ToString());
Int32 iptest=inet_addr(this.textBox1.Text.Trim());
Int64 macinfo=new Int64();
Int32 len=6;
//调用API
SendARP(iptest,mysource,ref macinfo,ref len);
}.... }
}
你可以到网上去查找API的辅助工具,如【API精灵】,
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Long) As Integer但是注意在vb6中很多参数是any类型。.net中必须确定数据类型,如果要用多种类型可以重载
。
用[DllImport("keinal.dll")]
public static extern int ExitWindowEX(Int32 length); //声明
2004年08月09日
刘侃ClassLibrary - Version 2004.8.9.18 所有的API调用都在其中了
附说明
这个就不错,说得挺详细的。
应用namespace即可
再写出声明
using System.Runtime.InteropServices;[DllImport("User32.dll")]
public static extern int MessageBox(int h,string m,string c,int type); //声明