BUG: VBX Events Aren't Routed Correctly

Last reviewed: July 22, 1997
Article ID: Q125795
1.00 1.50 1.51 1.52 WINDOWS kbprg kbbuglist

The information in this article applies to:

  • The Microsoft Foundation Classes, included with: Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51, 1.52

SYMPTOMS

VBX Event handlers are not called even though the events have been properly registered using AfxRegisterVBEvent. You can solve the problem by reducing the size of the application's DGROUP by, for example, reducing stack size.

CAUSE

There is a bug in the routing mechanism for VBX events. The bug becomes apparent when an event's registered value is greater than 0xFF00; at which point, the program will not call the handler for the event because the routing in CCmdTarget::OnCmdMsg will not route the VBX event as a registered notification code but as a regular Windows message.

RESOLUTION

VBX events are registered using AfxRegisterVBEvent. The value assigned to the VBX event is directly related to the amount of space available in the default data segment. If an application's default data segment is nearing maximum capacity (0xFFFF), then these values could end up being greater than 0xFF00. Here are several possible workarounds for this problem:

  • Put the module where you have the AfxRegisterVBEvent calls first in the link order. This ensures that the events are registered before other heap allocations occur during initialization of other modules. As a result, the event values tend to be smaller. If you are building the application from the Visual WorkBench, you can accomplish this by removing the modules from your project and adding the module with the AfxRegisterVBEvent calls before the other modules in your project except a pre-compiled header module, such as STDAFX.CPP.

    -or-

  • Reduce your application's stack size. To be precise, you need to reduce the stack size by at MOST 768 bytes.

    -or-

  • Use other techniques to reduce the size of DGROUP. For more information on how to do this, please see the following article in the Microsoft Knowledge Base:

          ARTICLE-ID: Q49935
    
          TITLE     : PRB: L2028 Error Caused by HEAPSIZE, STACKSIZE and
                      DGROUP Size
    
       -or-
    
    
  • Reduce heap allocations done during global initialization. If your application is built in small/medium memory model, these allocations will come out of your default data segment. This will not help, however if you are using the Compact/Large memory model.

    -or-

  • If your use of VBX controls is limited to one parent window (for example, all your VBX controls exist on only one window) and you are handling a limited number of events, you can handle the WM_VBXEVENT message in the parent window class. Then you can take care of decoding and handling the particular event and right in the OnVBXEvent function. Please see MFC TechNote #24 for details.

    -or-

  • Modify the OnCmdMsg function to route the events correctly. This would require that you rebuild the MFC libraries, so this solution should be used as a last resort. For details on rebuilding the MFC Libraries, please see the section titled "How To Build Other Library Versions" in the "Class Library User's Guide." Or read the README.TXT file that can be found in the MFC source directory (the default directory is \MSVC\MFC\SRC). The modification would be to change the following lines in CMDTARG.CPP:

    From:

          // Constant code...
          if ((UINT)nCode < 0xC000 || (UINT)nCode > 0xFF00)
    

    To:

          if ((UINT)nCode < 0xC000 || (UINT)nCode == 0xFFFF)
    

    And change the following lines:

    From:

          #endif //_DEBUG
          if ((UINT)nCode < 0xC000 || (UINT)nCode > 0xFF00)
    

    To:

          #endif //_DEBUG
          if ((UINT) nCode < 0xC000 || (UINT)nCode == 0xFFFF)
    

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


Additional reference words: 1.00 1.50 1.51 1.52 2.00 2.50 2.51 2.52 no32bit
noupdate
KBCategory: kbprg kbbuglist
KBSubCategory: MfcVBX
Keywords : kb16bitonly kbbuglist kbprg
Technology : kbMfc
Version : 1.00 1.50 1.51 1.52
Platform : WINDOWS


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: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.