The COM Library

Any process that uses COM must both initialize and uninitialize the COM library. In addition to being a specification, COM also implements some important services in this library. Provided as a set of DLLs and EXEs (primarily OLE32.DLL and RPCSS.EXE) in Microsoft® Windows®, the COM library includes:

To use basic COM services, all COM threads of execution in clients and out-of-process servers must call either the CoInitialize or the CoInitializeEx function before calling any other COM function except memory allocation calls. CoInitializeEx replaces the other function, adding a parameter that allows you to specify the threading model of the thread — either apartment-threaded or free-threaded. A call to CoInitialize simply sets the threading model to apartment-threaded. OLE Compound Document applications call the OleInitialize function, which calls CoInitializeEx and also does some initialization required for compound documents. Since this is true, threads that call OleInitialize cannot be free-threaded. For information on threading in clients and servers, refer to Processes and Threads.

In-process servers do not call the initialization functions, because they are being loaded into a process that has already done so. As a result, in-process servers must set their threading model in the registry under the InprocServer32 key. For detailed information on threading issues in in-process servers, refer to In-Process Server Threading Issues.

It is also important to uninitialize the library. For each call to CoInitialize or CoInitializeEx, there must be a corresponding call to CoUninitialize. For each call to OleInitialize, there must be a corresponding call to OleUninitialize.

In-process servers can assume that the process they are being loaded into has already performed these steps.