This sample, from Dion Wiggins (dionwiggins@hotmail.com)
shows how to use the CoCreateGuid and StringFromGUID2 functions to create a GUID.
The code is compiled into an ActiveX DLL which gives the interesting possibility of using the
code from an ASP page, or from other ActiveX-enabled scripting tools.
A Little About GUIDs
A GUID, or Globally Unique Identifier is a 128bit number
(thus potentially allowing for a maximum of 2128 possible values, which is an undescribably
large number). The idea of a GUID is that no two machines can ever generate the same GUID value twice.
This is achieved by using a combination of the current time, your machine's Media Access Control (MAC)
address (a unique number built into all network cards) if it has one, and other routines.
You can read about how GUIDs are generated in detail
here.
To make it easier to write a GUID, it is normally expressed as a hexadecimal
number with some formatting applied. This form of a GUID is also referred to as a CLSID
when it is used as the identification number of an OLE object.
An example CLSID looks like this (this is the CLSID
for the Microsoft Common Dialog control shipped with Service Pack 2 of VB5):
{F9043C85-F6F2-101A-A3C9-08002B2F49FB}
The formatting shown corresponds to the COM GUID type:
Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Whilst GUIDs are essential for the correct identification of COM components, they also have
potentially a number of other uses, for example, generating unique numbers on independent
machines.
The only thing to watch out for is the possibility you might be violating someones privacy
if you generate one of these numbers on their machine. Microsoft were forced to
change their Windows 98 Registration wizard to remove a number generated this way, and also
Intel were much in the news when it was announced all Pentium III processors included a
unique serial number.
15 November 1999: And again! Internet music consumers took RealNetworks to court in a
class action suit which accused RealNetworks of assigning a GUID to each
RealJukebox user without the user's knowledge, then compiling information
about people's music-listening habits. RealNetworks violated the federal
Computer Fraud and Abuse Act as well as state privacy laws and consumer
protection statutes, according to the complaint. The action is similar to a
suit filed last week in California against RealNetworks for invasion of
privacy, trespass, and unfair competition.
|