A GUID is a "Globally Unique Identifier", a very large number which is used to uniquely identify every interface, every class, and every COM application or library which exists anywhere in the world. GUID's identify the specific components, wherever and whenever they may be used. A GUID is a 16-byte (128-bit) value, which could be represented as an integer or a string. This item is large enough to represent all the possible values needed.
The PowerBASIC GUID$() function (or a hot-key in the PowerBASIC IDE) can generate a random GUID which is statistically guaranteed to be unique from any other generated GUID.
When a GUID is written in text, it takes the form:
{00CC0098-0000-0000-0000-0000000000FF}
When a GUID is used in a PowerBASIC program, it is typically assigned to a string equate, as that makes it easier to reference.
$MyLibGuid =
GUID$("{00000099-0000-0000-0000-000000000007}")
$MyClassGuid = GUID$("{00000099-0000-0000-0000-000000000008}")
$MyIfaceGuid = GUID$("{00000099-0000-0000-0000-000000000009}")
Every COM COMPONENT, every CLASS, and every INTERFACE is assigned a GUID to uniquely identify it,and set it apart from another similar item. As the programmer, you can assign each of these identifiers, or they will be randomly assigned by the PowerBASIC compiler.
When you create objects just for internal use within your programs, it's common to ignore the GUID's completely. PowerBASIC will assign them for you automatically, so you don't need to give it a thought. However, if you plan to publish an object for any external use through COM services, it's very important that you assign an explicit identifier to each item in your code. Otherwise, the compiler will assign new identifiers randomly, every time you compile the source. No other application could possibly keep track of the changes.
The APPID or LIBID identifies the entire application or library. You specify this item with the #COM GUID metastatement:
#COM GUID $MyLibGuid
The CLSID identifies each CLASS. You specify this item in the CLASS statement:
CLASS MyClass $MyClassGuid AS COM
...
END CLASS
The IID identifies each INTERFACE. You specify this item in the INTERFACE statement:
INTERFACE MyInterface $MyIfaceGuid
...
END INTERFACE
See Also