Creating an ActiveX Control with the MFC Library

This tutorial has four steps:

The basic ActiveX control you will have created by the end of the second step will be enriched to integrate more functionality as you progress in this tutorial.

Note

The following comments in the files generated by the wizard indicate lines of code that have been modified or added specifically for Views:

// Added for Views
// End Added for Views

Warning

Before starting with this tutorial, you should be aware that you might encounter problems when building the ActiveX control. For some reason, symbols such as _DllMain, new, and delete are defined several times at link time. None of these symbols is defined in the code provided in this tutorial nor in the Views libraries. It seems that the problem arises from a conflict between the following files: nafxcw.lib (used by the MFC), libcmt.lib (used by the C runtime library), and libcpmt.lib (used by the C++ runtime library).

However there is a workaround to that problem:

  1. Place comment characters before all the lines referring to the DemoCtrl class in the files DemoMFC.cpp and DemoMFCCtrl.cpp.

  2. Set the files ctrl.cpp and DemoCtrl.cpp in the project as inactive.

  3. Build the ActiveX control.

  4. Remove comment characters entered at step 1.

  5. Reset the files ctrl.cpp and DemoCtrl.cpp as active.

  6. Rebuild the ActiveX control.

Following this procedure eliminates the problem. To make things easier for you, the lines to be commented are enclosed in the following if/endif macro in the source files:

#if define(USE_VIEWS)

#endif

This macro is defined in the file ctrl.h. Simply place comment characters before the lines of code that this macro defines and remove them as needed.

We will report this problem to Microsoft as soon as we have identified precisely where it originates from.