///////////////////////////////////////////////////////
/// This one works well if you only have one NIC
CString CFormatHtmNameView::GetMACAddr()
{
CString strReturn;
GUID uuid;
// In Win2k or higher, CoCreateGuid no longer returns a mac address, but UuidCreate
// Sequential does.
typedef RPC_STATUS (CALLBACK* UuidCreateSequential_t)(UUID*);
// This doesn't exist Pre win2k,
// in that case it uses CoCreateGuid (which will fail in 2k+) - mc
HMODULE hRpcrt4 = LoadLibrary("rpcrt4.dll"); // Attempt to load RPCRT4.DLL
if(hRpcrt4)
{
UuidCreateSequential_t fpUuidCreateSequential;
fpUuidCreateSequential = (UuidCreateSequential_t)
GetProcAddress(hRpcrt4, "UuidCreateSequential");
// Attempt dynamic load of UuidCreateSequential c
if(fpUuidCreateSequential)
{
// Create Sequential UUID for determination of MAC Address
fpUuidCreateSequential(&uuid);
}
else
{ // OS Doesn't support UuidCreateSequential, so fall back on CoCreateGuid
CoCreateGuid(&uuid);
}
FreeLibrary(hRpcrt4);
}
else
{ // OS Doesn't support UuidCreateSequential, so fall back on CoCreateGuid
CoCreateGuid(&uuid);
}
// Now Format The adapter address - mc
strReturn.Format("%2.2X-%2.2X-%2.2X-%2.2X-%2.2X-%2.2X",
uuid.Data4[2],
uuid.Data4[3],
uuid.Data4[4],
uuid.Data4[5],
uuid.Data4[6],
uuid.Data4[7]);
return strReturn;
}