如何获得HWID

How to get HWID

我正在尝试通过 hwProfileInfo class 获得 HWID,但是 returns 我无法转换 WCHAR [39]到字符串。

string getHWID(){
  string hardware_guid

  HW_PROFILE_INFO hwProfileInfo;
  GetCurrentHwProfile(&hwProfileInfo);
  hardware_guid = hwProfileInfo.szHwProfileGuid;

  return hardware_guid;
}

我试过这种方法,但 returns 我只是 "{"

hardware_guid = (char*)hwProfileInfo.szHwProfileGuid;

我知道 Google 中还有更多方法,但我没有找到任何可用的变体。可能有些人,谁能说出100%的方法?

这就是我的问题的答案。

string getHWID(){  
  HW_PROFILE_INFO hwProfileInfo;
  GetCurrentHwProfile(&hwProfileInfo);
  wstring hwidWString = hwProfileInfo.szHwProfileGuid;  
  string hwid(hwidWString.begin(), hwidWString.end());

  return hwid;
}

有两种方法: 1st 您可以使用 std::wstring,它使用 wchar_t,而不是 std::string,它使用 char。 2nd 您可以使用 GetCurrentHwProfileA 而不是 GetCurrentHwProfileW,如果定义了 UNICODE,它将被定义为 GetCurrentHwProfile。