tags:

views:

999

answers:

3

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?

+3  A: 

Use the function UuidCreate to generate GUIDs :

UUID generated;

if (::UuidCreate(&generated) != RPC_S_OK)
throw std::exception(...);
Edouard A.
+2  A: 

You can use the COM function CoCreateGuid, e.g.:

GUID guid;
HRESULT hr = CoCreateGuid(&guid);
John Sibly
+4  A: 
_TUCHAR * guidStr;

GUID guid;

HRESULT hr = CoCreateGuid(&guid); 

// Convert the GUID to a string
UuidToString(&guid, &guidStr);

The application is responsible for calling RpcStringFree to deallocate the memory allocated for the string returned in the StringUuid parameter.

Mitch Wheat