How does the COM client call the process within the process
We start this section with the DLL component instead of the Exe component, because this program interacts to be simple. We will use pseudo code instead of hidden too many details, the MFC class library will be used in the future.
Client Clsid Clsid; IClassFactory * PCLF; IUNKNOWN * PUNK; Coinitialise (NULL); // Initialise COM CLSIDFROMPROGID ("ComponentName", & clsid;
COM COM Looking for CLSID in the registry through program easy-to-read "ComponentName"
Client CogetClassObject (CLSID, Clsctx_inproc_server, null, iid_iclassfactory, (void **) & pclf);
COM COM uses CLSID to find component IF in memory (component yet to load) {CoM get DLL filename COM from the registry COM to load the DLL component into the memory process}
Dll Component IF (if the component is loaded) {Global Factory object is implemented in the initial instantiation of the DLL (only for MFC)}
COM COM calls the global method DllgetClassObject of the DLL export, and passes the parameter CLSID passed to COGETCLASSOBJECT as a parameter to it.
Dll Component DllgetClassObject Return to Interface ICLASSFAACTORY *
Com COM returns iClassFactory * to the client
Client PCLF-> CreateInstance (NULL, IID_IUNKNOWN, (VOID **) & PUNK);
The CreateInstance method of the DLL Component Class Factory is called (this action directly through the component's virtual function table call) Start building the "ComponentName" object returns the interface pointer
Client PCLF-> Release (); punk-> release ();
DLL Component releases "componentname" is by calling the virtual function table if the IF (reference count == 0) {object you will be destroyed
Client cofreeunusedlibraries ();
COM COM Calling DLL Export Global Method DLLCanunloadNow
DLL Component DllcanunloadNow is called if (all DLL objects have been released) {return true}
Client Couninitialize (); // If the above DllcanunloadNow is launched, returns True, then COM will release the DLL
COM COM Releases Resources
Client client exits
Dll Component If the DLL is still in memory and no other programs are using it, Windows will uninstall the DLL
There are several important issues to pay attention: First, DllgetClassObject is to respond to customer program call CogetClassObject is executed; second, the return Class Factory interface address is the actual physical address of Class Factory in the DLL, Third, the customer program calls CREATEINSTANCE or all all interface methods are directly called (vTable voftable through components). The communication link between the client EXE program and the DLL component is very efficient. It is actually directly connected to the virtual function in the same process, but only the complete C parameter is added, and then returns, then returns, these are completed in the compile time. The only thing to be slower is that when the DLL is loaded, you need to find a CLSID in the registry. Next: How a comclient calls an out-of-process component