(Full Servers) Add OLE 2 Clipboard Formats

If you have read through Chapter 17, you already know that a container can create an object if it is pasted from the clipboard or through a drag-and-drop operation using the OleCreateFromData function. (If you didn't know this, now you do.) For this to happen, something has to put the embedded object data on the clipboard in the first place. This is the responsibility of a server application, regardless of whether it's running to service an embedded object or running stand-alone.

Embedded object data is made of two formats: CFSTR_EMBEDSOURCE and CFSTR_OBJECTDESCRIPTOR.4 From Cosmo, we need to

provide these formats in the data object we place on the clipboard whenever we perform a Copy or a Cut. A miniserver might not have any clipboard user interface, which is why such a feature is generally only for full servers.

In Cosmo, this means modifying CCosmoDoc::TransferObjectCreate, which is used in calling OleSetClipboard, in a drag-and-drop operation and, as we saw in this chapter, in IOleObject::GetClipboardData. Creating the two formats we're adding here is accomplished in CCosmoDoc::RenderMedium, which uses helper functions in the INOLE.DLL library (for example, INOLE_CreateStorageOnHGlobal and INOLE_AllocObjectDescriptor) to create the necessary formats. These formats should be placed in the data object after your private data but before any presentations.

4 When you pass OleSetClipboard a data object that contains CF_EMBEDSOURCE, OLE will create the OLE 1 formats "Native" and "OwnerLink" and place those on the clipboard as well. This allows OLE 1 containers to also paste in your object, a fact of which you remain blissfully ignorant.