Trying to convert a UUID to string without boost. I have the following but assigning the wszUuid to the string guid doesn't work. Anyone know how I can do this so I can return a stl string?
string Server::GetNewGUID()
{
UUID uuid;
::ZeroMemory(&uuid, sizeof(UUID));
// Create uuid or load from a string by UuidFromString() function
::UuidCreate(&uuid);
// If you want to convert uuid to string, use UuidToString() function
WCHAR* wszUuid = NULL;
::UuidToStringW(&uuid, (RPC_WSTR*)&wszUuid);
if (wszUuid != NULL)
{
::RpcStringFree((RPC_CSTR*)&wszUuid);
wszUuid = NULL;
}
string guid;
guid = wszUuid; // ERROR: no operator "=" matches these operands operand types are: std::string = WCHAR*
return guid;
}
string Server::GetNewGUID()
{
UUID uuid = {0};
string guid;
// Create uuid or load from a string by UuidFromString() function
::UuidCreate(&uuid);
// If you want to convert uuid to string, use UuidToString() function
RPC_CSTR szUuid = NULL;
if (::UuidToStringA(&uuid, &szUuid) == RPC_S_OK)
{
guid = (char*) szUuid;
::RpcStringFreeA(&szUuid);
}
return guid;
}
use wstring in place of string.
wstring guid;
guid = wszUuid;
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.