簡體   English   中英

C ++ UUID到stl字符串

[英]C++ UUID to stl string

嘗試將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;
}
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;
}

使用wstring代替字符串。

wstring  guid;
guid = wszUuid;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM