COleLinkingDoc Class

The base class for OLE container documents that support linking to the embedded items they contain.

class COleLinkingDoc : public COleDocument


A container application that supports linking to embedded items is called a "link container." The OCLIENT sample application is an example of a link container.

When a linked item's source is an embedded item in another document, that containing document must be loaded in order for the embedded item to be edited. For this reason, a link container must be able to be launched by another container application when the user wants to edit the source of a linked item. Your application must also use the COleTemplateServer class so that it can create documents when launched programmatically.

To make your container a link container, derive your document class from COleLinkingDoc instead of COleDocument. As with any other OLE container, you must design your class for storing the application's native data as well as embedded or linked items. Also, you must design data structures for storing your native data. If you define a CDocItem-derived class for your application's native data, you can use the interface defined by COleDocument to store your native data as well as your OLE data.

To allow your application to be launched programmatically by another container, declare a COleTemplateServer object as a member of your application's CWinApp-derived class:

class COleContainerApp : public CWinApp
   COleTemplateServer m_server;
   // remainder of class declaration ommitted

In the InitInstance member function of your CWinApp-derived class, create a document template and specify your COleLinkingDoc-derived class as the document class:

   // CMyLinkDoc is derived from COleLinkingDoc
   CMultiDocTemplate* pDocTemplate = new CMultiDocTemplate(IDR_LINKDOCTYPE,
    if (!pDocTemplate)
        return FALSE;

Connect your COleTemplateServer object to your document templates by calling the object's ConnectTemplate member function, and register all class objects with the OLE system by calling COleTemplateServer::RegisterAll:

m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);

For a sample CWinApp-derived class definition and InitInstance function, see OCLIENT.H and OCLIENT.CPP in the MFC sample OCLIENT.

For more information on using COleLinkingDoc, see the articles Containers: Implementing a Container and Containers: Advanced Features.


Header: afxole.h

See Also


COleDocument Class

Hierarchy Chart

CDocTemplate Class



Other Resources

COleLinkingDoc Members