-4

I am trying to get HWID through the hwProfileInfo class, but it returns me that i can't convert WCHAR [39] to String.

string getHWID(){
  string hardware_guid

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

  return hardware_guid;
}

Than i tried this way, but it returns me just "{"

hardware_guid = (char*)hwProfileInfo.szHwProfileGuid;

I know there are some more ways in Google, but i didn't find any working variants. May be there are some people, who can say the 100% method?

Maor Bachar
  • 81
  • 1
  • 8
Csgo MlgCom
  • 1
  • 1
  • 2
  • 3
    Do you realize what is the difference between `WCHAR [39]` and `string`? – user7860670 Jun 18 '17 at 11:34
  • You need to use `std::wstring`. – Cody Gray - on strike Jun 18 '17 at 11:37
  • 1
    I'm assuming that `string` means `std::string`. `std::string` uses `char`s, while `WCHAR` is a Windows alias for `wchar_t`. You have a couple choices: (1) change `string` to `wstring`, or (2) convert the Unicode-encoded `WCHAR[39]` to a `std::string`. If you're using C++11 or later, you may want to look at `std::wstring_convert` ( http://en.cppreference.com/w/cpp/locale/wstring_convert ). Since you're on Windows, you can use `WideCharToMultiByte` ( https://msdn.microsoft.com/en-us/library/windows/desktop/dd374130.aspx ) but that can be tricky. – Max Lybbert Jun 18 '17 at 11:47
  • The above code doesn't even compile due to a missing semi-colon. – tambre Jun 18 '17 at 12:38

2 Answers2

0

There are two methods: 1st You can use std::wstring, which uses wchar_t, instead of std::string, which uses char. 2nd You can use GetCurrentHwProfileA instead of GetCurrentHwProfileW, which will be defined as GetCurrentHwProfile if UNICODE is defined.

Norbert Willhelm
  • 2,579
  • 1
  • 23
  • 33
-4

This is the answer to my question.

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

  return hwid;
}
Csgo MlgCom
  • 1
  • 1
  • 2
  • 4
    This is absolutely *not* the answer to your question. A `std::wstring` object cannot be converted into a `std::string` object using iterators. They are entirely different types. The iterators should not even be compatible. – Cody Gray - on strike Jun 18 '17 at 11:56
  • @Cody Gray lol but anyway it works and it gives me hwid that i want – Csgo MlgCom Jun 18 '17 at 12:35
  • like this {e29ac6c0-7037-11de-816d-806e6f6e6963} – Csgo MlgCom Jun 18 '17 at 12:36
  • 1
    "It works on my computer, so it must be correct" - not really. Now ship it and see how much it breaks on your consumers' computers! – tambre Jun 18 '17 at 12:39