Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a guid in MFC

Tags:

c++

guid

mfc

I need to be able to create guids on the fly. Is there a way to do that in MFC? I see how to do it in .net, but we haven't gone there yet. If not, do you have pointers to some code I can use?

like image 322
JonDrnek Avatar asked Feb 17 '09 14:02

JonDrnek


People also ask

How do you create a GUID?

To Generate a GUID in Windows 10 with PowerShell, Type or copy-paste the following command: [guid]::NewGuid() . This will produce a new GUID in the output. Alternatively, you can run the command '{'+[guid]::NewGuid(). ToString()+'}' to get a new GUID in the traditional Registry format.

What is GUID generator?

A GUID (globally unique identifier) is a 128-bit text string that represents an identification (ID). Organizations generate GUIDs when a unique reference number is needed to identify information on a computer or network. A GUID can be used to ID hardware, software, accounts, documents and other items.

What is GUID example?

Types of GUIDs To identify the version of the GUID, just look at the version digit e.g version 4 GUIDs have the format xxxxxxxx-xxxx-4xxx-Nxxx-xxxxxxxxxxxx where N is one of 8,9,A, or B. This version is generated using both the current time and client MAC address.

What is GUID structure?

GUID structure (guiddef. A GUID is a 128-bit value consisting of one group of 8 hexadecimal digits, followed by three groups of 4 hexadecimal digits each, followed by one group of 12 hexadecimal digits.


1 Answers

   //don't forget to add Rpcrt4.lib to your project

    CString m_ListID(L"error");
    RPC_WSTR guidStr;
    GUID guid;
    HRESULT hr = CoCreateGuid(&guid);
    if (hr == S_OK)
    {
        if(UuidToString(&guid, &guidStr) == RPC_S_OK)
        {
            m_ListID = (LPTSTR)guidStr;
            RpcStringFree(&guidStr);
        }
    }
like image 128
wpqs Avatar answered Sep 17 '22 11:09

wpqs