Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q243315

↑ Back to the top


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."

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


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. 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:
       int m_viewID; // view id...
       LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam);
    					
  3. Open MdiAdxPrbView.cpp, and add the following global variables just before the CMdiAdxPrbView constructor:
       int g_nextViewID = 1;
       int g_activeViewID = 0;
    					
  4. In the CMdiAdxPrbView constructor, add the following lines of code:
       m_viewID = g_nextViewID;
       g_nextViewID++;
       g_activeViewID = m_viewID;
    					
  5. In MdiAdxPrbView.cpp, add the following line to your CMdiAdxPrbView message map:
       ON_MESSAGE(WM_APP+1, OnMyMessage)
    					
  6. Hit the CTRL+W keys to bring up the ClassWizard, and add a handler for OnActivateView in your CMdiAdxPrbView class.
  7. Add the following lines of code to the end of the implementation in OnActivateView():
       if (bActivate && m_pSelection) {
          if (m_viewID != g_activeViewID) {
             g_activeViewID = m_viewID;
             PostMessage(WM_APP+1);
          }
       }
    					
  8. Add the following function to the end of your MdiAdxPrbView.cpp file:
    LRESULT CMdiAdxPrbView::OnMyMessage(WPARAM wParam, LPARAM lParam) {
       if (m_pSelection) {
          m_pSelection->Deactivate();
          m_pSelection->Activate(OLEIVERB_UIACTIVATE, this);
       }
       return 0;
    }
    					
  9. 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.

↑ Back to the top


Keywords: KB243315, kbprb, kbactivedocs

↑ Back to the top

Article Info
Article ID : 243315
Revision : 6
Created on : 11/21/2006
Published on : 11/21/2006
Exists online : False
Views : 320