首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

在xpe下获取mac地址失败,但是在xp下是正常的,帮小弟我看一下

2012-02-12 
在xpe下获取mac地址失败,但是在xp下是正常的,帮我看一下C/C++ codeAnsiString __fastcall TMainForm::GetL

在xpe下获取mac地址失败,但是在xp下是正常的,帮我看一下

C/C++ code
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!";    }}

netbios反回值是0x23,指ncb.ncb_lana_num=0无效

但是此函数在xp下都是正常的,在XPE下失败

[解决办法]
试试这段代码可以么,没有xpe下执行过,我也不知道结果

C/C++ code
//----------------------------// 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;} 

热点排行