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;
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With