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?
Guid. NewGuid() initializes a new instance of the GUID class. using System; namespace GUIDTest { class MainClass { static void Main(string[] args) { System. Guid guid = System. Guid.
Guids are statistically unique. The odds of two different clients generating the same Guid are infinitesimally small (assuming no bugs in the Guid generating code).
Use guids when you have multiple independent systems or clients generating ID's that need to be unique. For example, if I have 5 client apps creating and inserting transactional data into a table that has a unique constraint on the ID, then use guids.
The random GUIDs you create with the Guid. NewGuid method are not known to be cryptographically secure. Thus, it's theoretically possible for a user to predict a GUID value that you generate for another user or task and use this to exploit weaknesses in your system.
I think CoCreateGuid
is what you're after. Example:
GUID gidReference; HRESULT hCreateGuid = CoCreateGuid( &gidReference );
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With