Let's now take a look at how all of the mechanisms described earlier appear in code, which, being written in C++, illustrates how COM enables you to share language-specific implementations with the rest of the system through language-independent interfaces. We'll first look at the basic mechanisms and then at self-registration and licensing separately.
We'll use three separate samples for this discussion: a client named ObjectUser, found in CHAP05\OBJUSER, and two implementations of an object named Koala (yes, I have a certain penchant for these critters) for both DLL and EXE servers, found in CHAP05\DKOALA1 and CHAP05\EKOALA1, respectively. Before running ObjectUser, you will need to create the registry entries for both servers using the REG files found in their respective directories. The Koala object is assigned the CLSID of 00021146-0000-0000-C000-000000000046, which is given the name CLSID_Koala in INC\BOOKGUID.H.
The Koala object used in these samples is nothing more than a regular OLE object with only the IUnknown interface—so all that is really useful to do with this object is call AddRef and Release on it. For the record, Koala has no initialization interface, nor a need of one. In any case, Koala will illustrate the mechanisms through which each server makes this object available to ObjectUser. You can look at the Koala implementation in the KOALA.CPP and KOALA.H files in both the DKOALA1 and the EKOALA1 directories and notice that the code is identical in both. This shows how you can create an object independently of the server packaging around it.