Basic COM   «Prev 

Local and remote transparency

Recall from previous lessons that COM clients do not directly access a COM server. Instead they ask the COM runtime subsystem for a class factory that "knows how to create" a specific type of COM object by calling
CoGetClassObject

passing in the CLSID of the COM class. In response, the COM runtime subsystem looks the CLSID up in the registry to find the location of the server. COM loads the server and calls DllGetClassObject. We will discuss CoGetClassObject later in this module.
COM imposes itself as an intermediary between the client and the server. This is called Local/Remote Transparency because the details of how the server is activated, connecting the client and server, and of how a client's COM call is routed to server is transparent to both the client and the server. The code to make an in-process call looks just like the code that makes a remote call. As needed, COM will handle the details involved with managing local and remote connections between the client and the server.

CoGetClassObject function

Provides a pointer to an interface on a class object associated with a specified CLSID. CoGetClassObject locates, and if necessary, dynamically loads the executable code required to do this.
Call CoGetClassObject directly to create multiple objects through a class object for which there is a CLSID in the system registry. You can also retrieve a class object from a specific remote computer. Most class objects implement the IClassFactory interface. You would then call CreateInstance to create an uninitialized object. It is not always necessary to go through this process however. To create a single object, call the
CoCreateInstanceEx

function, which allows you to create an instance on a remote machine. This replaces the CoCreateInstance function, which can still be used to create an instance on a local computer. Both functions encapsulate connecting to the class object, creating the instance, and releasing the class object. Two other functions,
  1. CoGetInstanceFromFile and
  2. CoGetInstanceFromIStorage,
provide both instance creation on a remote system and object activation. There are numerous functions and interface methods whose purpose is to create objects of a single type and provide a pointer to an interface on that object.