(1)新建一个基于对话框的应用程序设计对话框如图
(2)处理GetMac按钮的单击事件,在程序中使用Netbios函数获取网卡地址
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff[30];
}ASTAT, * PASTAT;
void CGetMACDlg::OnGetmac()
{
// TODO: Add your control notification handler code here
NCB nInfo;
memset(&nInfo,0,sizeof(NCB));
nInfo.ncb_command=NCBRESET;
nInfo.ncb_lana_num=0;
Netbios(&nInfo);
ASTAT AdaINfo;
memset(&nInfo,0,sizeof(NCB));
nInfo.ncb_command=NCBASTAT;
nInfo.ncb_lana_num=0;
nInfo.ncb_buffer=(unsigned char*)&AdaINfo;
nInfo.ncb_length=sizeof(ASTAT);
strncpy((char*)nInfo.ncb_callname,"*",NCBNAMSZ);
Netbios(&nInfo);
CString macAddr;
macAddr.Format("%02X%02X-%02X%02X-%02X%02X",AdaINfo.adapt.adapter_address[0],
AdaINfo.adapt.adapter_address[1],
AdaINfo.adapt.adapter_address[2],
AdaINfo.adapt.adapter_address[3],
AdaINfo.adapt.adapter_address[4],
AdaINfo.adapt.adapter_address[5]
);
m_MacAddr.SetWindowText(macAddr);
}
注意
#include “nb30.h”
(3)运行程序