读取网卡MAC地址(2)
用iphlpapi.h
TCHAR szmacaddress[6][MAX_PATH];
int count = 0;
PIP_ADAPTER_INFO pinfo=NULL;
unsigned long len=0;
void GetInfo()
{
if (pinfo!=NULL)
delete (pinfo);
unsigned long nError;
nError = GetAdaptersInfo(pinfo,&len);
if (nError==0)
{
ParseData();
}
if (nError==ERROR_NO_DATA)
{
//AfxMessageBox("No adapter information exists for the local computer");
}
if (nError==ERROR_NOT_SUPPORTED)
{
//AfxMessageBox("GetAdaptersInfo is not supported by the operating system running on the local computer");
}
if (nError==ERROR_BUFFER_OVERFLOW)
{
pinfo= (PIP_ADAPTER_INFO)malloc(len);
nError = GetAdaptersInfo(pinfo,&len);
if (nError==0)
{
ParseData();
}
}
void ParseData()
{
count = 0;
while (pinfo!=NULL)
{
sprintf(szmacaddress[count++], "%02X:%02X:%02X:%02X:%02X:%02X",pinfo->Address[0],pinfo->Address[1],pinfo->Address[2],pinfo->Address[3],pinfo->Address[4],pinfo->Address[5]);
pinfo = pinfo->Next;
}
}
TCHAR szmacaddress[6][MAX_PATH];
int count = 0;
PIP_ADAPTER_INFO pinfo=NULL;
unsigned long len=0;
void GetInfo()
{
if (pinfo!=NULL)
delete (pinfo);
unsigned long nError;
nError = GetAdaptersInfo(pinfo,&len);
if (nError==0)
{
ParseData();
}
if (nError==ERROR_NO_DATA)
{
//AfxMessageBox("No adapter information exists for the local computer");
}
if (nError==ERROR_NOT_SUPPORTED)
{
//AfxMessageBox("GetAdaptersInfo is not supported by the operating system running on the local computer");
}
if (nError==ERROR_BUFFER_OVERFLOW)
{
pinfo= (PIP_ADAPTER_INFO)malloc(len);
nError = GetAdaptersInfo(pinfo,&len);
if (nError==0)
{
ParseData();
}
}
void ParseData()
{
count = 0;
while (pinfo!=NULL)
{
sprintf(szmacaddress[count++], "%02X:%02X:%02X:%02X:%02X:%02X",pinfo->Address[0],pinfo->Address[1],pinfo->Address[2],pinfo->Address[3],pinfo->Address[4],pinfo->Address[5]);
pinfo = pinfo->Next;
}
}