Tip Use ClassView to open views to a project's AppWizard-generated files. If you are unfamiliar with ClassView, read Opening a Class with ClassView in the Scribble tutorial.
The work of enabling an MFC Automation server application is done mostly in the InitInstance
member function of your application’s CWinApp-derived class. AutoClik’s application class is found in AutoClik.cpp. AppWizard provides this code for you.
All MFC OLE applications require the following call to AfxOleInit, which initializes the OLE DLLs so they can call OLE interfaces:
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
All MFC Automation server applications, as well as ActiveX object servers, require a Class ID. The call to the ConnectTemplate member function of class COleTemplateServer registers the Class ID in the registry.
static const CLSID BASED_CODE clsid =
{ 0x2106e720, 0xaef8, 0x101a, { 0x90, 0x5, 0x0, 0xdd, 0x1, 0x8, 0xd6, 0x51 } };
...
// Connect the COleTemplateServer to the document template.
// The COleTemplateServer creates new documents on behalf
// of requesting OLE containers by using information
// specified in the document template.
m_server.ConnectTemplate(clsid, pDocTemplate, FALSE);
Note The numbers shown in the clsid line are generated at random, so the numbers in your code will be different from the ones shown here.
A framework application that is an Automation server can use COleTemplateServer::UpdateRegistry to register itself as an Automation server (OLE Application Type: OAT_DISPATCH_OBJECT). This AppWizard-provided code is optional.
m_server.UpdateRegistry(OAT_DISPATCH_OBJECT);
COleObjectFactory::UpdateRegistryAll();
Alternatively, you can register your application by using one of the two other methods: