Applications using the OLE Clipboard must tell OLE to create a clipboard window on startup and to free any OLE-owned renderings on shutdown. The following steps are handled in Cosmo's CCosmoFrame::Init and CCosmoFrame::~CCosmoFrame functions in COSMO.CPP, respectively:
At startup, call OleInitialize instead of CoInitialize so that OLE creates its clipboard window.
During shutdown, first call OleFlushClipboard to free the data object on the clipboard (which happens only if that data object belongs to the application), then destroy the data object, and then call OleUninitialize to destroy OLE's clipboard window.
At the time of initialization (CCosmoFrame::Init), Cosmo also obtains DataTran's class factory and calls IClassFactory::LockServer, which is reversed in the frame destructor. This is so later instantiations of DataTran will happen very quickly, improving the performance of clipboard (and later drag-and-drop) operations. This procedure exemplifies an intelligent use of IClassFactory::LockServer.