KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q182434: PRB: ActiveX Control’s Stock Error Event Uses SCODE Value

Article: Q182434
Product(s): Microsoft C Compiler
Version(s): winnt:4.2,5.0,6.0
Operating System(s): 
Keyword(s): kbole kbActiveX kbCOMt kbCtrl kbInprocSvr kbMFC kbVC420 kbVC500 kbVC600 kbClassWizard k
Last Modified: 17-JUL-2001

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

- The Microsoft Foundation Classes (MFC), used with:
   - Microsoft Visual C++, 32-bit Enterprise Edition, version 4.2 
   - Microsoft Visual C++, 32-bit Professional Edition, version 4.2 
   - Microsoft Visual C++, 32-bit Enterprise Edition, version 5.0 
   - Microsoft Visual C++, 32-bit Professional Edition, version 5.0 
   - Microsoft Visual C++, 32-bit Enterprise Edition, version 6.0 
   - Microsoft Visual C++, 32-bit Professional Edition, version 6.0 
   - Microsoft Visual C++, 32-bit Learning Edition, version 6.0 
-------------------------------------------------------------------------------

SYMPTOMS
========

The event handler generated by ClassWizard does not get called.

CAUSE
=====

The following is a quotation from the online documentation of
COleControl::FireError() function:

  The implementation of an OLE control's Stock Error event uses an SCODE
  value. If your control uses this event, and is intended to be used in
  Visual Basic 4.0, you will receive errors because the SCODE value is not
  supported in Visual Basic.

When you go into the .odl file of the ActiveX control and change the stock error
event from SCODE to LONG as required by Visual Basic, the change works correctly
in Visual Basic.

However, ClassWizard generates an event handler according to the information it
obtains from the .odl file. As a result, the event handler in the test container
written in Visual C++ will have a LONG instead of SCODE value.

RESOLUTION
==========

The following are two possible solutions:

- Keep two .odl files. One for Visual C++ (has an SCODE parameter type) and the
  other for Visual Basic (has a LONG parameter type).

- Manually modify the event handler generated by ClassWizard from SCODE to
  LONG, and change VTS_I4 to VTS_SCODE in the ON_EVENT macro of the event sink
  map. Refer to the sample code below for these changes.

MORE INFORMATION
================

Sample Code
-----------

     // In the .cpp file of the test container:
     // CMyTestDlg is a test container (a dialog-based application)
     // written in Visual C++.
     BEGIN_EVENTSINK_MAP(CMyTestDlg, CDialog)
     //{{AFX_EVENTSINK_MAP(CMyTestDlg)
     ON_EVENT(CMyTestDlg,
         IDC_OLECTRL1CTRL1,
         -608 /* Error */,
         OnErrorOlectrl1ctrl1,
         VTS_I2
         VTS_PBSTR
         VTS_I4       // Change VTS_I4 to VTS_SCODE!!!
         VTS_BSTR
         VTS_BSTR
         VTS_I4
         VTS_PBOOL)
     //}}AFX_EVENTSINK_MAP
     END_EVENTSINK_MAP()
     // OnErrorOleCtrl1 is the event handler for the Stock Error event of the
     // ActiveX control.
     void CMyTestDlg::OnErrorOleCtrl1(
     short       Number,
     BSTR FAR*    Description,
     long       Scode,          // Change LONG to SCODE!!!
     LPCTSTR    Source,
     LPCTSTR    HelpFile,
     long       HelpContext,
     BOOL FAR*    CancelDisplay)
     {
        // TODO: Add your control notification handler code here.
        ...
     }

Copyright, Microsoft Corporation 1998, All Rights Reserved. Contributions by
Yeong-Kah Tam, Microsoft Corporation

Additional query words:

======================================================================
Keywords          : kbole kbActiveX kbCOMt kbCtrl kbInprocSvr kbMFC kbVC420 kbVC500 kbVC600 kbClassWizard kbGrpDSMFCATL 
Technology        : kbAudDeveloper kbMFC
Version           : winnt:4.2,5.0,6.0
Issue type        : kbprb

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

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.