MFCCALC: Demonstrates an Automation Server Application

Click to open or copy the MFCCALC project files.

MFCCALC is an Automation (formerly OLE Automation) server. It implements a simple calculator similar to the CALC application in Windows. It can be driven via Automation with the CALCDRIV sample or run stand-alone. This sample uses the native compiler COM support. See the MFC MFCCALC sample for more information.

The differences between this sample and the MFC sample with the same name are:

  1. The COleDispatchDriver class is no longer necessary. Instead, #import is used to import a type library.

  2. _bstr_t and _variant_t wrapper classes are used to simplify operations of BSTR and VARIANT types.

  3. __declspec(property) is used to simplify assignment operations for properties of COM objects.

  4. 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.

This sample demonstrates the following keywords:

dispinterface; #import; _com_ptr_t; _variant_t; _bstr_t; _com_error.

See also Compiler COM Support, MFC MFCCALC sample.