Microsoft KB Archive/125795

From BetaArchive Wiki

BUG: VBX Events Aren't Routed Correctly

Q125795



The information in this article applies to:


  • The Microsoft Foundation Classes (MFC), included with:
    • Microsoft Visual C++, 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.
  • Reduce your application's stack size. To be precise, you need to reduce the stack size by at MOST 768 bytes.
  • 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:

    Q49935 PRB: L2028 Error Caused by HEAPSIZE, STACKSIZE and DGROUP Size

  • 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.
  • 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.
  • 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 query words: 1.00 1.50 1.51 1.52 2.00 2.50 2.51 2.52 no32bit noupdate

Keywords : kb16bitonly
Issue type :
Technology : kbAudDeveloper kbMFC


Last Reviewed: May 8, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.