+ Reply to Thread
Results 1 to 2 of 2

Thread: How to create GUID?

  1. #1

    How to create GUID?

    How to create GUID?

    Hot to convert GUID to string and vice-versa?

  2. #2
    Senior Member
    Join Date
    Feb 2012
    Posts
    109
    Use CoCreateGuid API to create a GUID.

    Example:

    Code:
    CString GenerateGUID()
    {
    	GUID guid ;
    	CoCreateGuid(&guid) ;
    
    	WCHAR* pszGUID ;
    	HRESULT hResult = StringFromCLSID(guid, &pszGUID) ;
    
    	CString strGUID = pszGUID ;
    
    	GUID guidTemp ;
    	CLSIDFromString(pszGUID, &guidTemp) ;
    
    	CoTaskMemFree(pszGUID) ;
    
    	return strGUID ;
    }
    Note:
    a. StringFromCLSID is used to convert GUID to string.
    b. CLSIDFromString is used to convert string to GUID.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts