尝试将UUID转换为字符串而不进行提升.我有以下但是将wszUuid分配给字符串guid不起作用.任何人都知道如何做到这一点,所以我可以返回一个字符串?
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;
}
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9236 次 |
| 最近记录: |