How to generate GUID Programmatically?

20 07 2008


Guids are like humans… because are unique. 🙂 In several instance we have to generate unique strings or ids and Guids are perfect match for those situations. Well, how can you generate guid programmatically?


You can use the function – CoCreateGuid(). See the code snippet below.

// Initialize COM.
::CoInitialize( 0 );

// Generate GUID.
GUID Guid = { 0 };
::CoCreateGuid( &Guid );


Well, don’t forget to uninitialize COM by calling CoUninitialize().


Targeted Audience – Beginners.

Advertisements