if you know other way to get mac address, please let me know.
Another method is with GetAdaptersAddresses
which is supported by UWP, according to the doc :
Minimum supported client : Windows XP [desktop apps | UWP apps]
If I do a test in UWP on Windows 10 21H1, I get :
At beginning :
#include <winsock2.h>
#include <iphlpapi.h>
Test code :
PIP_ADAPTER_ADDRESSES pAddresses = NULL;
ULONG nSize;
ULONG nRet = GetAdaptersAddresses(AF_INET, 0, NULL, pAddresses, &nSize);
pAddresses = (PIP_ADAPTER_ADDRESSES)new char[nSize];
nRet = GetAdaptersAddresses(AF_INET, 0, NULL, pAddresses, &nSize);
if (nRet == ERROR_SUCCESS)
{
PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
pCurrAddresses = pAddresses;
while (pCurrAddresses)
{
BYTE MACAddress[6] = { 0, 0, 0, 0, 0, 0 };
memcpy(&MACAddress, pCurrAddresses->PhysicalAddress, pCurrAddresses->PhysicalAddressLength);
WCHAR wsText[MAX_PATH] = TEXT("");
swprintf_s(wsText, MAX_PATH,
L"Adapter : %s (%s) - MAC Address : %02X-%02X-%02X-%02X-%02X-%02X\r\n",
pCurrAddresses->Description, pCurrAddresses->FriendlyName, MACAddress[0], MACAddress[1], MACAddress[2], MACAddress[3], MACAddress[4], MACAddress[5]);
OutputDebugString(wsText);
pCurrAddresses = pCurrAddresses->Next;
}
}
if (pAddresses)
delete pAddresses;
Result :
Adapter : Realtek PCIe GbE Family Controller (Ethernet) - MAC Address : 40-8D-5C-77-31-2D
Adapter : Qualcomm Atheros AR9287 Wireless Network Adapter (Wi-Fi) - MAC Address : F4-F2-6D-88-9F-CA
Adapter : Microsoft Wi-Fi Direct Virtual Adapter #3 (Connexion au réseau local* 2) - MAC Address : 16-F2-6D-88-9F-CA
Adapter : Microsoft Wi-Fi Direct Virtual Adapter #4 (Connexion au réseau local* 4) - MAC Address : 26-F2-6D-88-9F-CA
Adapter : Microsoft Hosted Network Virtual Adapter #2 (Connexion au réseau local* 15) - MAC Address : 56-F2-6D-88-9F-CA
Adapter : TAP-Windows Adapter V9 (Ethernet TAP) - MAC Address : 00-FF-25-CE-E5-E3
Adapter : TunnelBear Adapter V9 (Ethernet 2) - MAC Address : 00-FF-3D-F6-FB-9B
Adapter : Bluetooth Device (Personal Area Network) (Connexion réseau Bluetooth) - MAC Address : 00-50-F2-E4-CF-3D
Adapter : Software Loopback Interface 1 (Loopback Pseudo-Interface 1) - MAC Address : 00-00-00-00-00-00