As described earlier, this chapter's version of Cosmo supports linking through a single File moniker, so the content object to which a container can link is an entire figure that makes up a single file. In this simple case, the changes required to support linking are not that extensive, as the following steps indicate:
When opening a file, create a file moniker and register it with the running object table. Remember to revoke the moniker from the table when closing the document. We saw how to do this in Chapter 9.
Re-create and reregister the file moniker when the document is renamed. This also means that you need to send the OnRename notification to any advise sinks obtained through IOleObject::Advise.
Call IRunningObjectTable::NoteChangeTime when the object is modified.
Include the CFSTR_LINKSOURCE and CFSTR_LINKSRCDESCRIPTOR formats when copying data to the clipboard or through drag and drop. Do not provide these formats for a clipboard Cut operation because cutting removes the data that would be linked to in the first place.
Implement moniker binding support by implementing IPersistFile (as we already know from Chapter 9). IPersistFile::QueryInterface must return any of the other object's interface pointers. Note that file moniker binding requires an association between the server's file type and its CLSID, as needed by GetClassFile (also described in Chapter 9). In addition, we do not change the server's user interface when activating a linked object in IOleObject::DoVerb.
Implement IOleObject::SetMoniker and IOleObject::GetMoniker, and remove OLEMISC_CANTLINKINSIDE.
The following sections look at these steps more closely.