Microsoft KB Archive/272256

= BUG: MFC ActiveX Document Container Hangs During Shutdown on Windows 2000 =

Article ID: 272256

Article Last Modified on 1/29/2007

-

APPLIES TO


 * Microsoft Foundation Class Library 4.2, when used with:
 * Microsoft Windows 2000 Standard Edition
 * Microsoft Excel 2002 Standard Edition

-



This article was previously published under Q272256



SYMPTOMS
A standard MFC ActiveX Document container that embeds a Microsoft Excel 2000 or 2002 spreadsheet or chart hangs during application shutdown, leaving both the MFC application and Excel running in the task list. This occurs only when the application is run on a Microsoft Windows 2000 system. The same application running on a Microsoft Windows NT 4.0, Microsoft Windows 95, or a Microsoft Windows 98 works correctly.



CAUSE
The bug is the result of a change in behavior for OLE embedded objects due to the addition of Component Object Model extension (COM+) to the version of OLE32.DLL that ships with Windows 2000. The bug occurs only under special circumstances, leaving both Excel and MFC with artificially incremented reference counts, which in turn can leave them running because both parties believe that the other is still trying to keep its connection alive.

So far, the problem has only been reproduced with MFC ActiveX Document containers and Excel. This does not mean that other containers, or other ActiveX Document servers, could not be effected.



RESOLUTION
To avoid the problem, OLE containers can forcibly disconnect their proxy/stub during shutdown, thereby allowing their reference count to fall to zero and exit normally. This also frees the running instance of the OLE server once ORPC confirms that the connection is dead (which is after three non-responsive pings spaced about two minutes apart; about six minutes total).



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior

 * 1) On a Windows 2000 computer, start Visual C++ 6.0, and then create a new MFC AppWizard (exe) project. Name the project MFCAxTest.
 * 2) In the MFC wizard, set the project type to Multi Document Interface (MDI).
 * 3) In step 3, select Container, and then click to select the Active document container check box. Leave the rest of the options in their default state, and click Finish to add the new project.
 * 4) Press the F7 key to build the project.
 * 5) Press F5 to run the project.
 * 6) On the Edit menu, select Insert Object while the project is running. Choose Microsoft Excel Chart as a new object, and then click OK. This should activate Excel as an ActiveX Document server.
 * 7) On the File menu, select Exit. Do not save changes when prompted.

Note that the MFC app hides but does not exit. The debugger stays running and Excel is still in the task list. Press SHIFT+F5 in Visual C++ to stop the debugger. Excel exits some time later after ORPC detects that the container has died.

Steps to Correct the Behavior
 In the MFC project, open the CntrItem.cpp file and find the CMFCAxTestCntrItem::OnChange function.  Just after the call to the UpdateAllViews method, add the following lines of code: // Explicitly release inproc handler connected to our doc site if (nCode == OLE_CLOSED) {     IUnknown* punk = GetInterface(&IID_IUnknown); if (punk) ::CoDisconnectObject(punk, 0); }                    Re-compile the MFC application and repeat steps 5-7 from &quot;Steps to Reproduce Behavior.&quot; Note that the MFC application now exits on shutdown and the disconnected Excel eventually is freed.

Additional query words: docobj Office CntrItem

Keywords: kbactivedocs kbbug kbcontainer kbpending KB272256

-

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

© Microsoft Corporation. All rights reserved.