locked
Tool to generate unique GUIDs? RRS feed

  • Question

  • Hi,

     

    Does Visual Studio 2008 contain a tool that can generate unique GUIDs? I remember there is such one but cannot find it. If there are no such tools, then is there a function to do the task?

     

    Thanks

    Friday, August 3, 2018 7:05 AM

Answers

    • Proposed as answer by Guido Franzke Friday, August 3, 2018 7:32 AM
    • Marked as answer by chcw Wednesday, August 8, 2018 1:38 AM
    Friday, August 3, 2018 7:26 AM
  • ... is there a function to do the task

    CoCreateGuid function

    StringFromGUID2 function

    • Proposed as answer by Baron Bi Tuesday, August 7, 2018 2:03 AM
    • Marked as answer by chcw Wednesday, August 8, 2018 1:38 AM
    Friday, August 3, 2018 10:18 AM
  • You also can use uuidCreate()

    or

    GUID guid;
    OLECHAR szGUID[40] ={0};
    if(::CoCreateGuid(&guid) == S_OK)
    {						
     if(::StringFromGUID2(guid,szGUID,GUID_STRING_LEN)!=0)
     {
    						 
        std::string strGUID = MBFromW(szGUID,CP_ACP); // This GUID contain open and close curly {} braces ,remove them before using it					
    			
     }
    }

    Thanks


    Rupesh Shukla

    • Proposed as answer by Baron Bi Tuesday, August 7, 2018 2:03 AM
    • Marked as answer by chcw Wednesday, August 8, 2018 1:38 AM
    Friday, August 3, 2018 3:04 PM

All replies

    • Proposed as answer by Guido Franzke Friday, August 3, 2018 7:32 AM
    • Marked as answer by chcw Wednesday, August 8, 2018 1:38 AM
    Friday, August 3, 2018 7:26 AM
  • ... is there a function to do the task

    CoCreateGuid function

    StringFromGUID2 function

    • Proposed as answer by Baron Bi Tuesday, August 7, 2018 2:03 AM
    • Marked as answer by chcw Wednesday, August 8, 2018 1:38 AM
    Friday, August 3, 2018 10:18 AM
  • You also can use uuidCreate()

    or

    GUID guid;
    OLECHAR szGUID[40] ={0};
    if(::CoCreateGuid(&guid) == S_OK)
    {						
     if(::StringFromGUID2(guid,szGUID,GUID_STRING_LEN)!=0)
     {
    						 
        std::string strGUID = MBFromW(szGUID,CP_ACP); // This GUID contain open and close curly {} braces ,remove them before using it					
    			
     }
    }

    Thanks


    Rupesh Shukla

    • Proposed as answer by Baron Bi Tuesday, August 7, 2018 2:03 AM
    • Marked as answer by chcw Wednesday, August 8, 2018 1:38 AM
    Friday, August 3, 2018 3:04 PM