Click to open or copy the CALCDRIV project files.
CALCDRIV is a simple Automation (formerly OLE Automation) client application. CALCDRIV drives the MFCCALC sample application, which is an Automation server that provides basic calculator functions and is one of the OLE Software Development Kit samples. MFCCALC has a simple calculator interface that looks like the Calculator application that comes with Microsoft Windows®. MFCCALC can also demonstrate the use of ClassWizard's Automation Client option and a ClassWizard-created dispatch class.
Before you run CALCDRIV, first build the MFCCALC sample, then register it with Windows. If you run MFCCALC once, MFCCALC, like other MFC server applications, will automatically enter itself into the system registry. If you do not follow this procedure, you get an "Unable to create 'MFCCALC.Application' object" message.
When you run CALCDRIV, the Microsoft Foundation Class Library (MFC) Calc Driver dialog box appears and the MFCCALC application is launched. You can use MFCCALC's calculator user interface directly at this point, or you can drive MFCCALC from CALCDRIV as follows:
The CRemoteCalcDlg class of CALCDRIV represents the dispatch interface of MFCCALC. Class CRemoteCalcDlg is derived from CCmdTarget, which has a few automation-specific member functions, such as CreateDispatch.
It is easy to implement a dispatch class such as MFCCALC with ClassWizard if the automation server application has a type library (.tlb) file. To implement the header and implementation files, Calctype.h and Calctype.cpp:
You do not need to make any changes to the Calctype.h and Calctype.cpp files created by ClassWizard.
CALCDRIV uses the CRemoteCalcDlg class created by ClassWizard as follows:
m_calc
. The CRemoteCalcDlg object, like the CDriverDlg
object in which it is embedded, is alive for most of the duration of CALCDRIV. The CRemoteCalcDlg is constructed when the dialog object is constructed.Button
method of MFCCALC, which is an emulator for the various buttons in the calculator's dialog box.Refresh
function by calling the GetOpnd
and GetAccum
methods of MFCCALC.Quit
method exposed by MFCCALC to shut down MFCCALC when CALCDRIV closes. This sample demonstrates the following keywords:
AfxMessageBox; AfxOleInit; CDialog::DoModal; CDialog::EndDialog; CDialog::OnInitDialog; CEdit::GetSel; CEdit::SetSel; COleDispatchDriver::AttachDispatch; COleDispatchDriver::CreateDispatch; COleDispatchDriver::GetProperty; COleDispatchDriver::InvokeHelper; COleDispatchDriver::SetProperty; CString::GetLength; CWinApp::Enable3dControls; CWinApp::InitInstance; CWnd::DoDataExchange; CWnd::GetWindowText; CWnd::SetWindowText; GetWindowText; afxMemDF; min; wsprintf