2

I am new to C++ for just one project.

C++ is needed for an plugin and here I have to create an UUID. That is nearly the only thing were i need to create the plugin for.

My conversion from guid to str results in chineese letters. The big Problem is, that there is no option to debug the plugin.

UUID guid;
CoCreateGuid(&guid);

char guidStr[40];
sprintf_s(
    guidStr,
    "%08X-%04hX-%04hX-%02X%02X-%02X%02X%02X%02X%02X%02X",
    guid.Data1, guid.Data2, guid.Data3,
    guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
    guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
std::string s(guidStr);

pUID->szFieldValue.Set(LPCTSTR(guidStr));

When I put in a string instead of this uuid, the string looks normal.

Display Sample with the problem

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • Take a look [here](http://stackoverflow.com/questions/3452272/convert-boostuuid-to-char) may be it could help you. – Zelnes May 09 '17 at 14:51

1 Answers1

0

You are incorrectly casting guidStr which is an array of char to LPCTSTR which is a pointer to wchar_t if you are compiling for Unicode.

Use wchar_t array and wide versions of the functions, so you can remove the cast:

UUID  guid;
CoCreateGuid(&guid);
wchar_t guidStr[40];
swprintf_s(
    guidStr,
    L"%08X-%04hX-%04hX-%02X%02X-%02X%02X%02X%02X%02X%02X",
    guid.Data1, guid.Data2, guid.Data3,
    guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
    guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
std::wstring s(guidStr);


pUID->szFieldValue.Set(guidStr);

Alternatively, use StringFromCLSID() to convert to string.

Community
  • 1
  • 1
zett42
  • 25,437
  • 3
  • 35
  • 72