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.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: