Q152391: PRB: Adding OnClose Handler to COleControl Class Causes C2660

Article: Q152391
Product(s): Microsoft C Compiler
Version(s): 2.0,2.1,2.2,4.0,4.1,5.0
Operating System(s): 
Keyword(s): kberrmsg kbole kbActiveX kbCOMt kbCtrlCreate kbMFC kbVC200 kbVC400 kbVC500 kbGrpDSMFCAT
Last Modified: 09-MAY-2001

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Visual C++, versions 2.0, 2.1, 2.2, 4.0, 4.1 
- Microsoft Visual C++, 32-bit Enterprise Edition, version 5.0 
- Microsoft Visual C++, 32-bit Professional Edition, version 5.0 
-------------------------------------------------------------------------------

SYMPTOMS
========

When building an ActiveX control (OLE Control) using Visual C++ prior to version
5.0, you may receive the following error message:

  error C2660: 'OnClose' : function does not take 0 parameters

With Visual C++ 5.00, no compiler error is generated when building the control.
However, both the CAUSE and RESOLUTION sections below still apply.

CAUSE
=====

This error occurs when using the Developer Studio or Class Wizard to add a
WM_CLOSE message handler to your ColeControl-derived class. The handler created
will have the following format:

     void CEdt_on_ctrlCtrl::OnClose() {
        // TODO: Add your message handler code here and/or call default
        COleControl::OnClose(); // statement generated by VC++ prior to 5.0
        // CWnd::OnClose(); - statement generated by VC++ 5.0
     }

However, an ActiveX Control is a COM object and, as such, uses a different
mechanism than processing a WM_CLOSE message to close down its window. For this
reason, COleControl has overridden OnClose with its own version using the
following prototype:

     void OnClose(DWORD dwSaveOption);

COleControl::OnClose has one parameter that is the reason for the error message.

RESOLUTION
==========

Because the ActiveX Control doesn't handle the WM_CLOSE message, if you want to
do some processing when the OLE control is terminating, you can override the
COleControl::OnClose function as follows:

Add the following function prototype to the class definition in the header file
for your COleControl derived class (in this example, CEdt_on_ctrlCtr):

     void OnClose(DWORD dwSaveOption);

To replace CEdt_on_ctrlCtrl with the name of your OLE control class, add the
following implementation in the .cpp file:

     void CEdt_on_ctrlCtrl::OnClose(DWORD dwSaveOption) {
        // TODO: Add your message handler code here and/or call default
        COleControl::OnClose(dwSaveOption);
     }

STATUS
======

This behavior is by design.

Additional query words:

======================================================================
Keywords          : kberrmsg kbole kbActiveX kbCOMt kbCtrlCreate kbMFC kbVC200 kbVC400 kbVC500 kbGrpDSMFCATL 
Technology        : kbVCsearch kbVC400 kbAudDeveloper kbVC220 kbVC410 kbVC500 kbVC200 kbVC210 kbVC32bitSearch kbVC500Search
Version           : :2.0,2.1,2.2,4.0,4.1,5.0
Issue type        : kbprb

=============================================================================