This sample illustrates how ATL COM objects can be used in an MFC server EXE.
The server allows the creation of two objects, ObjectOne (implemented in MFC and supporting a dispinterface) and ObjectTwo (implemented in ATL and supporting a dual interface).
Running the Sample
Build the Mfcatl.exe server and run it standalone to register it.
Load the Mfcatl.vbp Visual Basic 4.0 project, run it, and press the buttons in the form.
Note that if you are running the sample on NT 3.51, only the release build will work.
Remarks
Originally, MFCATL had both objects implemented in MFC. Both were derived from CCmdTarget. ObjectTwo was then reimplemented using ATL by following these steps:
Include the ATL header files (Atlbase.h and Atlcom.h) into Premfcat.h.
Include Atlimpl.cpp into Premfcat.cpp.
Add a CComModule derived class to Prefcat.h (similar to the BEEPER EXE sample). The derived class implements the Lock and Unlock methods to forward lock counts to MFC by calling AfxOleLockApp and AfxOleUnlockApp).
Add an object map macro pair (BEGIN_OBJECT_MAP/END_OBJECT_MAP) into the Mfcatl.cpp and add a static instance of the module class called _Module.
Call _Module.Init and Term from InitInstance and ExitInstance
Add the typelib as a resource
Call _Module.RegisterServer(TRUE) from InitInstance to match the MFC call to COleObjectFactory::UpdateRegistryAll
Call _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE) to match the REGCLS_MULTIPLEUSE of MFC's class factories, as implicitly done by the IMPLEMENT_OLECREATE macro
Reimplement ObjectTwo in ATL by following these steps:
Change the ODL file from dispinterface to dual interface
Have the ODL compilation generate a header file (Interf.h) needed by ATL
Rewrite .h and .cpp files (the quickest way is to run ATL Wizard and copy, paste, and rename the automatically generated code in place of the original MFC code)
Add an OBJECT_ENTRY(CLSID_ObjectTwo, CObjectTwo) to the ATL object map