1、GetGPUId.h文件
#pragma once
#include <windows.h>
#include <stdio.h>
#include <string>
class CGetCPUId
{
public:
CGetCPUId();
virtual ~CGetCPUId();
public:
std::string GetId();
};
2、GetCPUId.cpp文件
#include "stdafx.h"
#include "GetCPUId.h"
CGetCPUId::CGetCPUId()
{
}
CGetCPUId::~CGetCPUId()
{
}
std::string CGetCPUId::GetId()
{
std::string strCPUId;
unsigned long s1, s2;
char buf[32] = { 0 };
__asm
{
mov eax, 01h
xor edx, edx
cpuid
mov s1, edx
mov s2, eax
}
if (s1)
{
memset(buf, 0, 32);
sprintf_s(buf, 32, "%08X", s1);
strCPUId += buf;
}
if (s2)
{
memset(buf, 0, 32);
sprintf_s(buf, 32, "%08X", s2);
strCPUId += buf;
}
__asm
{
mov eax, 03h
xor ecx, ecx
xor edx, edx
cpuid
mov s1, edx
mov s2, ecx
}
if (s1)
{
memset(buf, 0, 32);
sprintf_s(buf, 32, "%08X", s1);
strCPUId += buf;
}
if (s2)
{
memset(buf, 0, 32);
sprintf_s(buf, 32, "%08X", s2);
strCPUId += buf;
}
return strCPUId;
}
3、调用示例。
#include "stdafx.h"
#include "GetCPUId.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
CGetCPUId GetCPUId;
cout << "CPUID:" << GetCPUId.GetId() << endl;
getchar();
return 0;
}
4、运行结果。
下载地址:https://download.csdn.net/download/sunriver2000/12089170
5、第三方软件对比。
下载地址:https://download.csdn.net/download/sunriver2000/12381311