tags:

views:

407

answers:

3

I need to create a GUID in an unmanaged windows C++ project. I'm used to C#, where I'd use Guid.NewGuid(). What's the (unmanaged windows) C++ version?

+12  A: 

UuidCreate() in Win32 API has exactly the same effect. However you need to pass an address of the variable that will receive the generated value:

UUID newId;
UuidCreate( &newId );

I believe Guid.NewGuid() simply maps onto it inside the .NET runtime.

sharptooth
That makes a UUID structure, not a GUID structure.
Simon
They're the same, simply different typedef names!
Konrad Rudolph
+5  A: 

I think CoCreateGuid is what you're after. Example:

GUID gidReference;
HRESULT hCreateGuid = CoCreateGuid( &gidReference );
Alan
It calls UuidCreate() internally anyway.
sharptooth