PRB: Menus Either Do Not Work or They Cause a Crash in the MFC MDI ActiveX Document Container

ID: Q243315


The information in this article applies to:
  • Microsoft Visual C++, 32-bit Professional Edition, version 6.0
  • The Microsoft Foundation Classes (MFC)
  • Microsoft Excel 2000


SYMPTOMS

After switching between MDI documents in an MFC MDI ActiveX Document Container, the ActiveX Document Server's merged menus fail to work properly, or cause a crash with a message such as:

The instruction at "0x303820bc" referenced memory at "0x00000000". The memory could not be "read."


CAUSE

Some servers, such as Microsoft Excel 2000, need to be de-activated and re-activated every time they are activated in an MDI ActiveX Document Container.


RESOLUTION

To resolve the problem, each time an MDI view that contains a server is activated, you must de-activate and re-activate the server. See the sample below for complete steps.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Using Visual C++ 6.0, create a new MFC AppWizard (exe0 project named MdiAdxPrb.


  2. Select Multiple documents in step 1, and click Next twice.


  3. Select Container, check Active document container, then click Finish.


  4. Compile and run the project.


  5. From the Insert menu drop down box, choose Object, and insert a Microsoft Excel Worksheet.


  6. From the File menu, select New.


  7. From the Insert menu drop down box, choose Object again and insert another Microsoft Excel Worksheet.


  8. Note that if you choose a menu option from the newly-merged Microsoft Excel menus, such as Format|Cells, it responds appropriately.


  9. Now, click from this MDI child window back to the first one, and try selecting the same menu item.


  10. The result is that either the menu does not work, or it causes a crash.

Steps to Work Around Behavior

  1. Using the first three steps from the section above, build an MDI ActiveX Document container.


  2. Open MdiAdxPrbView.h and add the following member variable and function declaration to the top of the CMdiAdxPrbView class:


  3. 
       int m_viewID; // view id...
       LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam); 
  4. Open MdiAdxPrbView.cpp, and add the following global variables just before the CMdiAdxPrbView constructor:


  5. 
       int g_nextViewID = 1;
       int g_activeViewID = 0; 
  6. In the CMdiAdxPrbView constructor, add the following lines of code:


  7. 
       m_viewID = g_nextViewID;
       g_nextViewID++; 
  8. In MdiAdxPrbView.cpp, add the following line to your CMdiAdxPrbView message map:


  9. 
       ON_MESSAGE(WM_APP+1, OnMyMessage) 
  10. Hit the CTRL+W keys to bring up the ClassWizard, and add a handler for OnActivateView in your CMdiAdxPrbView class.


  11. Add the following lines of code to the end of the implementation in OnActivateView():


  12. 
       if (bActivate && m_pSelection) {
          if (m_viewID != g_activeViewID) {
             g_activeViewID = m_viewID;
             PostMessage(WM_APP+1);
          }
       } 
  13. Add the following function to the end of your MdiAdxPrbView.cpp file:


  14. 
    LRESULT CMdiAdxPrbView::OnMyMessage(WPARAM wParam, LPARAM lParam) {
       if (m_pSelection) {
          m_pSelection->Deactivate();
          m_pSelection->Activate(OLEIVERB_UIACTIVATE, this);
       }
       return 0;
    } 
  15. Compile and Run.


The code basically overrides OnActivateView() to be notified whenever a view is activated, and de-activates and re-activates any active server in that view if it has not already been activated. You have to post a message from OnActivateView() because the calls De-activate and Activate you want to make are not allowed in a synchronous context.

Additional query words:

Keywords : kbActiveDocs kbActiveX kbExcel kbMFC kbVC600 kbGrpDSO kbDSupport
Version : WINDOWS:2000; winnt:6.0
Platform : WINDOWS winnt
Issue type : kbprb


Last Reviewed: October 26, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.