BUG: MFC ActiveX Document Container Hangs After Deleting a Table in a Word 2000 Document

ID: Q243806


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


SYMPTOMS

You have a Microsoft Visual C++ 6.0 MFC ActiveX Document container application (MDI or SDI) that embeds a Word 2000 document. If your application automates Word and acquires an interface to a Row object in a table that is deleted before the document is closed, your application hangs during shutdown, and WinWord.exe is left running in memory.

NOTE: This problem does not occur with versions of Word earlier than 2000, nor does it occur using out-of-process automation if the container does not acquire an interface to a Row object in a table that is deleted before the document is closed.


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.


MORE INFORMATION

If you are unfamiliar with creating MFC wrapper classes for Automation, please see the following article in the Microsoft Knowledge Base:

Q178749 HOWTO: Create Automation Project Using MFC and a Type Library

Steps to Reproduce the Behavior

  1. Build a Microsoft Visual C++ 6.0 MFC SDI application and name it SDITest. Add support for ActiveX Document containment. Accept all other wizard defaults.


  2. Use the MFC ClassWizard to create class wrappers for Msword9.olb (the Word 2000 type library).


  3. In CntrItem.h, add the following to the public section of CSDITestCntrItem class:


  4. inline LPUNKNOWN GetEmbeddedObject(){return m_lpObject;}; 
  5. Add #include msword9.h to the top of SDITestView.h.


  6. In the TODO section of CSDITestView::InsertObject (DSITestView.cpp), add the following code:


  7. 
    // TODO: re-implement selection as appropriate for your application 
    try 
    { 
      _Application pWordApp; 
      _Document pDoc;
      COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
      Selection pSelection; Range pRng; 
      Tables pTbls; Table pTbl; 
      Rows pRows; Row pRow; 
    
      LPDISPATCH pdisp; 
      LPUNKNOWN punk = pItem->GetEmbeddedObject(); 
    
      punk->QueryInterface(IID_IDispatch, (void**)&pdisp); 
      pDoc.AttachDispatch(pdisp); 
    
      pWordApp.AttachDispatch(pDoc.GetApplication()); 
      pSelection.AttachDispatch(pWordApp.GetSelection()); 
      pRng.AttachDispatch(pSelection.GetRange()); 
      pTbls.AttachDispatch(pSelection.GetTables()); 
    
      pdisp = pTbls.Add(pRng, 3, 2, covOptional, covOptional); 
      pTbl.AttachDispatch(pdisp); 
    
      pRows.AttachDispatch(pTbl.GetRows()); 
      long rowcount = pRows.GetCount(); 
    
      for (long i = 0 ; i <= 1; i++) 
      { 
        pRow = pRows.Item(i+1); 
        Sleep(10); 
      } 
    
    } 
    catch(...) 
    { 
      AfxMessageBox("Code error"); 
    }  
  8. Compile the MFC application and run it. On the Edit menu, select Insert New Object and create a new Word Document. This builds a table in the new document. Exit the MFC app and note that it exits correctly. WinWord.exe shuts down correctly and MFC quits.


  9. Repeat step 6. However, before closing MFC, highlight the entire table in the Word document to select it, and then delete it (or, from the Table menu, choose Delete|Table). Close the MFC app but do not save changes.

    Note that the SDITest window is destroyed, SDITest disappears from the Task Bar, but MFC hangs. SDITest.exe and WinWord.exe are still running in memory. You can see them in the Windows 9x Task List by pressing the CTRL+ALT+DEL keys. They appear in the "Processes" page of Windows NT's Task Manager. The hang occurs when AfxOleTerm is called.


© Microsoft Corporation 2000, All Rights Reserved.
Contributions by Richard R. Taylor, Microsoft Corporation

Additional query words:

Keywords : kbActiveDocs kbMFC kbWord kbGrpDSO kbDSupport
Version : WINDOWS:2000; winnt:6.0
Platform : WINDOWS winnt
Issue type : kbbug


Last Reviewed: February 1, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.