Microsoft KB Archive/243806

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

Article ID: 243806

Article Last Modified on 8/9/2004

-

APPLIES TO


 * Microsoft Word 2000 Standard Edition
 * Microsoft Foundation Class Library 4.2
 * Microsoft Visual C++ 6.0 Professional Edition

-



This article was previously published under Q243806



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.



RESOLUTION
The problem has been corrected in SR1 for Office 2000. You can download the service pack from the following Web address:

http://office.microsoft.com



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are 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:

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

Steps to Reproduce Behavior
 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. Use the MFC ClassWizard to create class wrappers for Msword9.olb (the Word 2000 type library).  In CntrItem.h, add the following to the public section of CSDITestCntrItem class: inline LPUNKNOWN GetEmbeddedObject{return m_lpObject;};  Add #include "msword9.h" to the top of SDITestView.h.  In the TODO section of CSDITestView::InsertObject (SDITestView.cpp), add the following code: // 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"); }                     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.</li> 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.</li></ol>

Keywords: kbdownload kbbug kbfix kbactivedocs KB243806

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.