Created
June 13, 2014 03:45
-
-
Save wateroot/9b8a7167bb2d930fdd1f to your computer and use it in GitHub Desktop.
GetCpuID
This file contains hidden or 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
BOOL GetCpuID(char *szCPU, int nSize) | |
{ | |
BYTE szCpu[16] = {0}; | |
UINT uCpuID = 0U; | |
try { | |
_asm { | |
mov eax, 0 | |
cpuid | |
mov dword ptr szCpu[0], ebx | |
mov dword ptr szCpu[4], edx | |
mov dword ptr szCpu[8], ecx | |
mov eax, 1 | |
cpuid | |
mov uCpuID, edx | |
} | |
} catch (...) { | |
return FALSE; | |
} | |
#define BUF_SIZE 1024 | |
char szBuf[BUF_SIZE] = {0}; | |
sprintf_s(szBuf, BUF_SIZE, "CPU_ID=[%08X],CPU_INFO=[", uCpuID); | |
for (int i = 0; i < 12; i++) { | |
char szTmp[4] = {0}; | |
sprintf_s(szTmp, "%02X", szCpu[i]); | |
strcat_s(szBuf, BUF_SIZE, szTmp); | |
} | |
strcat_s(szBuf, BUF_SIZE, "],"); | |
strcpy_s(szCPU, nSize, szBuf); | |
return TRUE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment