简体   繁体   中英

cannot convert from string to Uuid

I am trying to compile the following C++ code in Visual Studio 2017 C++ console application.

GUID patchId;
auto resa = UuidFromString("905EAA46-C9E3-4B5C-8133-0000165A4DDD", &patchId);

It gives me the following compilation error.

Error C2664 'RPC_STATUS UuidFromStringW(RPC_WSTR,UUID *)': cannot convert argument 1 from 'const char [37]' to 'RPC_WSTR'

How can I resolve this error?

There appears to be a bug in the system platform headers. If you define wchar_t to be a distinct type from unsigned short (which you should), https://social.msdn.microsoft.com/Forums/vstudio/en-US/d1b4550a-407b-4c09-8560-0ab9ef6ff754/error-while-compiling-c2664?forum=vclanguage kicks in; RPC_WSTR is unsigned short* and should be wchar_t* .

Do this:

UuidFromStringW((RPC_WSTR)L"905EAA46-C9E3-4B5C-8133-0000165A4DDD", &patchId);

as horrible as that is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM