在xpe下获取mac地址失败,但是在xp下是正常的,帮我看一下
AnsiString __fastcall TMainForm::GetLocalMac(){ typedef struct _ASTAT { ADAPTER_STATUS adapt; NAME_BUFFER NameBuffer[30]; }ASTAT, *PASTAT; ASTAT Adapter; NCB ncb; UCHAR uRetCode; memset(&ncb,0,sizeof(ncb)); ncb.ncb_command=NCBRESET; ncb.ncb_lana_num=0; Netbios(&ncb); memset(&ncb,0,sizeof(ncb)); ncb.ncb_command=NCBASTAT; ncb.ncb_lana_num=0; strcpy((char *)ncb.ncb_callname,"* "); ncb.ncb_buffer=(unsigned char *) &Adapter; ncb.ncb_length=sizeof(Adapter); uRetCode=Netbios(&ncb); AnsiString str=""; if(uRetCode == 0) { str.printf("%02x-%02x-%02x-%02x-%02x-%02x", Adapter.adapt.adapter_address[0], Adapter.adapt.adapter_address[1], Adapter.adapt.adapter_address[2], Adapter.adapt.adapter_address[3], Adapter.adapt.adapter_address[4], Adapter.adapt.adapter_address[5] ); return str; } else { return "MAC Error!"; }}
//----------------------------// Fetches the MAC address and prints it DWORD GetMACaddress(TStringList *MacList){ if(MacList == NULL) return -1; DWORD MACaddress = 0; IP_ADAPTER_INFO AdapterInfo[16]; // Allocate information // for up to 16 NICs DWORD dwBufLen = sizeof(AdapterInfo); // Save memory size of buffer DWORD dwStatus = GetAdaptersInfo( // Call GetAdapterInfo AdapterInfo, // [out] buffer to receive data &dwBufLen); // [in] size of receive data buffer assert(dwStatus == ERROR_SUCCESS); // Verify return value is // valid, no buffer overflow PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to // current adapter info do { if (MACaddress == 0) MACaddress = pAdapterInfo->Address [5] + pAdapterInfo->Address [4] * 256 + pAdapterInfo->Address [3] * 256 * 256 + pAdapterInfo->Address [2] * 256 * 256 * 256; PrintMACaddress(pAdapterInfo->Address,MacList); // Print MAC address pAdapterInfo = pAdapterInfo->Next; // Progress through linked list } while(pAdapterInfo); // Terminate if last adapter return MACaddress;}