Gold mine of Visual C++ tricks!
Archive for July 20, 2008
How to generate GUID Programmatically?
1![]()
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.