All Forums
 Microsoft Windows CE
 eVC Application Development
 Programmatically retrieve device MAC address
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Author Topic  

ctacke

877 Posts

Posted - 25 Apr 2003 :  14:12:57  Show Profile  Email Poster
Q: How can I programmatically retrieve my device's MAC address?

You can retrieve the on-board adapter's MAC address using the GetAdaptersInfo() API something like this:


PIP_ADAPTER_INFO pAdapterInfo = NULL;
ULONG OutBufLen = 0;
ULONG ret = 0;

// first get size of AdapterInfo
OutBufLen = 0;
ret = GetAdaptersInfo(pAdapterInfo, &OutBufLen);
if (ret == ERROR_BUFFER_OVERFLOW)
{
   // Allocate memory to get AdatperInfo
   pAdapterInfo = (PIP_ADAPTER_INFO) malloc(OutBufLen);
   ret = GetAdaptersInfo(pAdapterInfo, &OutBufLen);
   if (ret == ERROR_SUCCESS)
   {
      do
      {
         RETAILMSG(TRUE, (_T(" Adapter Name = %a\r\n"), pAdapterInfo->AdapterName));
         RETAILMSG(TRUE, (_T(" IP Address = %a\r\n"), pAdapterInfo->CurrentIpAddress->IpAddress.String));
         RETAILMSG(TRUE, (_T(" Gateway = %a\r\n"), pAdapterInfo->GatewayList.IpAddress.String));
         RETAILMSG(TRUE, (_T(" DHCP Server = %a\r\n"), pAdapterInfo->DhcpServer.IpAddress.String));
         RETAILMSG(TRUE, (_T(" MAC Address = 0x%02x-0x%02x-0x%02x-0x%02x-0x%02x-0x%02x\r\n"),
            pAdapterInfo->Address[0],
            pAdapterInfo->Address[1],
            pAdapterInfo->Address[2],
            pAdapterInfo->Address[3],
            pAdapterInfo->Address[4],
            pAdapterInfo->Address[5]));
      } while ((pAdapterInfo = pAdapterInfo->Next) != NULL);
   }
   free((PVOID)pAdapterInfo);
}
  Topic  
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Jump To:
Eurotech Support Forums © Eurotech Inc. Go To Top Of Page
This page was generated in 0.02 seconds. Snitz Forums 2000