convert from std::char to *char

I have been working on some code to get the hwid, so I can assign a value to it. My code goes like this

[Code]
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <iostream>

int main()
{
HW_PROFILE_INFO hwProfileInfo;
GetCurrentHwProfile(&hwProfileInfo);

HWID hWid = hwProfileInfo.szHwProfileGuid.c_str();
return 0;
}
[/code]

Now get some error like this
Cannot convert value in std::string to char, what's possibly wrong? What am I not getting correctly?
> convert from std::char to *char
> Cannot convert value in std::string to char
learn to copy-paste


> hwProfileInfo.szHwProfileGuid.c_str();
¿what is the data type of `szHwProfileGuid' ?
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724479(v=vs.85).aspx

also, ¿what's HWID?
hwProfileInfo.szHwProfileGuid is an array of TCHARs, not a std::string. TCHAR does not have a c_str() function.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/

Looks like you tried to use code tags, but the opening tag needs to be lower case.

The GUID is given as a string, so you can assign it to a std::string easily enough.

1
2
3
HW_PROFILE_INFO hwProfileInfo; 
GetCurrentHwProfile(&hwProfileInfo);
std::string hardware_guid = hwProfileInfo.szHwProfileGuid;

If you want to play with it as an actual GUID, you'll need to #include <rpc.h> and play with the GUID struct.

Use the CLSIDFromString() and StringFromCLSID() functions to convert between the struct and a char string.

(Google "msdn clsidfromstring" to get documentation.)

Hope this helps.
Topic archived. No new replies allowed.