PRB: ActiveX Control's Stock Error Event Uses SCODE Value

Last reviewed: March 13, 1998
Article ID: Q182434
The information in this article applies to:
  • The Microsoft Foundation Classes (MFC) included with:

        - Microsoft Visual C++, 32-bit Editions, versions 4.2, 5.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.

STATUS

Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

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
Keywords          : MfcOLE
Version           : WINNT:4.2,5.0
Platform          : winnt
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.

Last reviewed: March 13, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.