请查看PB帮助中的
Application Development / TCPIP / IPHelper Reference / IPHelper Functions
//IP_ADAPTER_INFO AdapterInfo;
TCHAR *szMacAddress = NULL;
TCHAR tempStr[10] = {0};
PIP_ADAPTER_INFO pAdapterInfo = NULL;//&AdapterInfo;
ULONG ulSizeAdapterInfo = 0;
DWORD dwReturnvalueGetAdapterInfo;
UINT index=0;
SetLastError(0);
dwReturnvalueGetAdapterInfo = GetAdaptersInfo( pAdapterInfo, &ulSizeAdapterInfo );
//Check whether the GetAdaptersInfo succeeded
if ( dwReturnvalueGetAdapterInfo == ERROR_BUFFER_OVERFLOW)
{
if (!(pAdapterInfo = (PIP_ADAPTER_INFO)malloc(ulSizeAdapterInfo)))
{
RETAILMSG(1,(L"Insufficient Memory\n "));
goto ERROR_TAG;
}
//Try GetAdaptersInfo again
SetLastError(0);
dwReturnvalueGetAdapterInfo = GetAdaptersInfo( pAdapterInfo, &ulSizeAdapterInfo);
if (dwReturnvalueGetAdapterInfo != ERROR_SUCCESS)
{
RETAILMSG(1,(L"Error in GetAdaptersInfo\n"));
goto ERROR_TAG;
}
}
//GetAdaptersInfo Failed
else if (dwReturnvalueGetAdapterInfo != ERROR_SUCCESS)
{
RETAILMSG(1,(L"Error in GetAdaptersInfo"));
goto ERROR_TAG;
}
if ( pAdapterInfo == NULL )
{
RETAILMSG(1,(L"PIP_ADAPTER_INFO is NULL after getAdapterInfo. Error Is:%d\n",GetLastError()));
goto ERROR_TAG;
}
szMacAddress = (TCHAR *)malloc(sizeof(TCHAR) * (pAdapterInfo->AddressLength+1)*2);
if (szMacAddress == NULL)
{
RETAILMSG(1,(L"The Out Parameter is not allocated"));
goto ERROR_TAG;
}
memset(szMacAddress,'\0',(pAdapterInfo->AddressLength+1)*sizeof(TCHAR)*2);
for (index = 0; index < pAdapterInfo->AddressLength; index++)
{
wsprintf(tempStr,L"%02x",pAdapterInfo->Address[index]);
wcscat(szMacAddress,tempStr);
}
wcscat(szMacAddress,L"\0");
if (pAdapterInfo != NULL)
free(pAdapterInfo);
m_mac = szMacAddress ;
// return szMacAddress;
ERROR_TAG:
// if(pAdapterInfo !=NULL)
// free(pAdapterInfo);
return ;