COM/OLE Task Requirements

Any and all applications (EXEs) that plan to use or implement components must ensure that the COM/OLE DLLs are properly initialized in the process before attempting to use almost any function in those libraries. Only a few scattered functions can be called before initialization is complete. A component that runs from a DLL need not be concerned with any of these requirements because they apply only to modules that define a task—EXEs.

For 32-bit components, there are two initialization steps. Absolutely all tasks (such as all the sample applications in this book that compile EXEs) must do the following:

During startup, call CoInitialize or OleInitialize.

During shutdown, call CoUninitialize or OleUninitialize if and only if step 1 succeeded.

The Co* functions control your access to COM functions. If you use API functions or interfaces related to any type library, the clipboard, drag and drop, OLE Documents, OLE Automation, or OLE Controls, you must use the Ole* functions instead of their Co* counterparts. The Ole* versions perform a few more specific operations and call the Co* versions. For the most part, it is safest to simply call OleInitialize and forget it.