MFCCALC Sample: Demonstrates an Automation Server Application (C++ Samples)
MFCCALC is an Automation server. It implements a simple calculator similar to the CALC application in Windows. It can be driven via Automation by running its CalcDriv project, or it can be run standalone by running its MfcCalc project.
This sample is similar to the MFC samples MFCCALC and CALCDRIV except that it uses the native compiler COM support and it combines the calculator and driver in a single sample.
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.
To get samples and instructions for installing them:
To access samples from Visual Studio
On the Help menu, click Samples.
By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.
For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.
To build and run this sample
Open the solution mfccalc.sln.
On the Build menu, click Build Solution.
Set MfcCalc as the startup project (right-click the project node and click Set as StartUp Project).
On the Debug menu, click Start Without Debugging. This will run the calculator standalone. Close the MfcCalc application before continuing.
Now run the calculator using Automation. Set CalcDriv as the startup project and click Start Without Debugging. Type an expression in the MFC Calc Driver dialog box and click the Go button to run the calculator.
The differences between this sample and the MFC samples:
The COleDispatchDriver class is no longer necessary. Instead, #import is used to import a type library.
_bstr_t and _variant_t wrapper classes are used to simplify operations of BSTR and VARIANT types.
__declspec(property) is used to simplify assignment operations for properties of COM objects.
COM error handling is now performed by using the _com_error class.
With the Visual C++ native compiler COM support, the resulting sample code is shorter and more efficient. The MFC-based MFCCALC sample uses dispinterfaces only. Compare this sample with the MFC version to see the differences in source code.