![]() |
![]() ![]() |
|
GUIDs, CLSIDs, and IIDs Continued from The Class Factory Creating and managing COM objects relies heavily on Globally Unique Identifiers, or GUIDs (pronounced "GOO-ids"). A GUID is a 128-bit number generated by the Windows API function CoCreateGUID. GUIDs should be globally unique: CoCreateGUID should never return the same GUID twice. As OLE maven Kraig Brockschmidt (of Microsoft's OLE design team) puts it, the likelihood of two calls to CoCreateGUID returning the same value is "about the same as two random atoms in the universe colliding to form a small California avocado mated to a New York City sewer rat." Every interface needs an Interface ID (IID), which is a GUID. Delphi's OLE2.PAS file defines dozens of IIDs. The example code for this article refers to IID_IUnknown and IID_IClassFactory; the Delphi-supplied OLE2.PAS file contains dozens more IIDs. In addition, every object class registered with the system needs a Class ID (CLSID). If you've ever looked at the Registry key HKEY_CLASSES_ROOT\CLSID with RegEdit, you've seen dozens or even hundreds of these unintelligible strings of numbers. These are the class IDs of all the COM objects registered on your system. No question about it; to do COM programming you'll have to work with existing GUIDs as well as create new GUIDs specific to your program. Free utilities, such as UUIDGEN.EXE, will generate GUIDs for you, but you'll then be faced with the tedious task of rewriting them in the correct form for a Delphi constant. Instead of UUIDGEN.EXE, use the text-mode "console" program available from PC Magazine Online. You can either load it into the Delphi IDE and compile it, or you can compile it with the command line Delphi compiler by entering DCC32 GUIDS.DPR. Run the resulting program, and you'll get a brand-new, never-before-seen GUID, expressed first as a string and then as a Delphi typed constant. When you start a new project, mentally count up the number of distinct GUIDs you'll need, add a few for good luck, then pass that number to GUIDS.EXE, redirecting the output of GUIDS.EXE to a file. The resulting file will contain as many GUIDs as you requested, and, normally, they will form a continuous block of numbers. Having all the GUIDs used by your project differ in just one digit makes them easier to recognize as related. Now you can cut GUIDs from this text file and paste them into your project as needed. Published as Power Programming in the 01/07/97 issue of PC Magazine. |
|
TOP | ![]() Copyright (c) 1997 Ziff-Davis Inc. |