COM with Windows Registry
In the example of EX24A, in a clearly clear assumption environment, components are static links to the client. In the real COM, the component either DLL either independent EXE. When the customer program calls the CogetClassObject method, COM will enter and look up the correct components positioned at a disk. How does COM establish this connection? It will find the unique 128-bit id ID of the class in Window Registry, so this lookup class must be permanently registered into your computer.
If you run the Windwos Registry program (in Windows NT 3.51 is regedit32), you will see an interface similar to Figure 24-5. This figure shows the subdirectory of class IDs, three are associated with DLL class IDs, one of which is associated with EXE class ID (LocalServer32). The COGETCLASSOBJECT method finds the class ID in the registry, then loads the desired DLL or EXE.
If you don't want to remember the numbers of those who are difficult to understand, can you? no problem. COM supports another registration type database entry that helps us convert a person's easy-to-understand programming ID into a corresponding class ID, Figure 24-6 shows the location of this entry in the registry, CLSIDFROMPROGID method for COM This conversion is then performed by reading this database entry. Figures 24-5.
Figure 24-6. Focus: The first parameter of CLSIDFROMPROGID is a string used to store easy programming IDs, but this is not a string we often use. This is the first time you encountered in COM. All string parameters in the COM method (except Data Access Bjects [DAO]) are strings of Unicode characters, and its pointer type is OLECHAR *. You will worry about the frequent needle between the double-byte string and the normal string. If you need a double-byte string, then add the prefix character L before the string. Just like CLSIDFROMPROGID (L "spaceship", & clsid); you will start learning the MFC's Unicode string conversion function in Chapter 25.
How can you put the registration information in the registry? You can update the registry directly in the component write. MFC is already easy to include this method: ColeObjectFactory :: UpdateRegistryAll, which will find all Class Factory objects in this, and register their name and class ID (CLSID).
Registration of runtime objects
You already know how Windows Registry has registered COM classes on disk, and the Class Factory object must also be registered. More unfortunately "Register" will be used in all environments. The objects of the process external component module are registered by calling the CoregisterClassObject method at runtime, and Windows maintains registration information in memory through the DLL. If Class Factory is registered in some mode, this mode allows the single-real album to build multiple COM components, then when the client calls CogetClassObject, COM can directly use the existing process.
Next: How a comclient calls an in-process component