Last active
November 20, 2020 00:45
-
-
Save MareArts/7c2c59a65044ab7beeaee0264f53128e to your computer and use it in GitHub Desktop.
Get MAC Address in MFC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://study.marearts.com/2017/01/get-mac-address-in-mfc.html | |
CString GetMACAddress() | |
{ | |
CString strGateWay = _T(""); | |
CString strMACAddress = _T(""); | |
IP_ADAPTER_INFO ipAdapterInfo[5]; | |
DWORD dwBuflen = sizeof(ipAdapterInfo); | |
DWORD dwStatus = GetAdaptersInfo(ipAdapterInfo, &dwBuflen); | |
if (dwStatus != ERROR_SUCCESS) | |
{ | |
strMACAddress.Format(_T("Error for GetAdaptersInfo : %d"), dwStatus); | |
AfxMessageBox(strMACAddress); | |
return _T(""); | |
} | |
PIP_ADAPTER_INFO pIpAdapterInfo = ipAdapterInfo; | |
do{ | |
strGateWay = (CString)pIpAdapterInfo->GatewayList.IpAddress.String; | |
if (strGateWay[0] == '0') | |
{ | |
pIpAdapterInfo = pIpAdapterInfo->Next; | |
} | |
else | |
{ | |
strMACAddress.Format(_T("%02X-%02X-%02X-%02X-%02X-%02X"), | |
pIpAdapterInfo->Address[0], | |
pIpAdapterInfo->Address[1], | |
pIpAdapterInfo->Address[2], | |
pIpAdapterInfo->Address[3], | |
pIpAdapterInfo->Address[4], | |
pIpAdapterInfo->Address[5] | |
); | |
break; | |
} | |
} while (pIpAdapterInfo); | |
return strMACAddress; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://study.marearts.com/2017/01/get-mac-address-in-mfc.html