Switch to Scribble.cpp and examine the OLE server code that AppWizard provided, beginning with CScribbleApp theApp
. (Note that the default class names differ from those you customized for Scribble.)
All MFC OLE applications — whether container, server, or Automation server — must call AfxOleInit and the static function COleTemplateServer::RegisterAll from the application’s InitInstance
to initialize framework support for OLE. For an application that is not an OLE server, the CDocTemplate object coordinates the creation of the frame window, view, and document object for the stand-alone application. The CDocTemplate uses menu, accelerator, and string resources passed to the constructor in InitInstance
code, to determine the menu, accelerators, and Windows shell registration of the stand-alone application.
In the case of an OLE server application, additional information is needed. The InitInstance
function passes this information as parameters to the CDocTemplate::SetServerInfo function, before it calls CWinApp::AddDocTemplate. Here is a description of the parameters:
pDocTemplate->SetServerInfo(
IDR_SCRIBBTYPE_SRVR_EMB, IDR_SCRIBBTYPE_SRVR_IP,
RUNTIME_CLASS(CInPlaceFrame));
IDR_SCRIBBTYPE_SRVR_EMB
is the common ID of the menu and accelerator resources loaded when Scribble is fully opened by the container application when it edits an embedded item.IDR_SCRIBBTYPE_SRVR_IP
is the common ID of the menu, accelerators, and toolbar bitmap resources that are loaded when Scribble is activated in place in the container application. The purpose and design of these resources specifically for the in-place activated server application, as well as the purpose and design of the above resources for the fully opened server application, are explained later in this tutorial.RUNTIME_CLASS
(CInPlaceFrame
) is the COleIPFrameWnd-derived class provided by AppWizard. This class defines the behavior of the window created by the framework on behalf of the server application when it is activated in place by the container. The AppWizard-provided implementation of this class adds the resize border to the in-place window so that the user can resize the object while it is activated in place.The following code, from Scribble.cpp, defines the OLE class ID for the Scribble application and registers the application. AppWizard provides a default ID that is randomly generated. The call to COleTemplateServer::ConnectTemplate registers the class ID with Windows.
Note The clsid below will differ from the unique one that is provided when you run AppWizard.
static const CLSID clsid =
{ 0x0002180f, 0x0, 0x0, { 0xC0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x46 } };
...
m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);
If the application was spawned by OLE as an in-place server or Automation server, then InitInstance
returns before performing additional initialization tasks that are appropriate only for stand-alone applications:
if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
{
return TRUE;
}