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++ vers
The documentation for Guid.NewGuid points out, how it is implemented:
This is a convenient static method that you can call to get a new Guid. The method wraps a call to the Windows CoCreateGuid function.
So the native equivalent to Guid.NewGuid()
is CoCreateGuide()
.
UuidCreate
returns a UUID, that is guaranteed to be unique to the computer that created it, CoCreateGuid
produces a GUID that is absolutely unique.
If you need to decide, which API to use, here are the relevant sections from the documentation.
UuidCreate:
For security reasons, it is often desirable to keep ethernet addresses on networks from becoming available outside a company or organization. The UuidCreate function generates a UUID that cannot be traced to the ethernet address of the computer on which it was generated. It also cannot be associated with other UUIDs created on the same computer.
CoCreateGuid:
The CoCreateGuid function calls the RPC function UuidCreate, which creates a GUID, a globally unique 128-bit integer. Use CoCreateGuid when you need an absolutely unique number that you will use as a persistent identifier in a distributed environment.