CMFCToolBarImages may cause ActiveX host shutdown failure - by Greg Prosch

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 643999 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 2/14/2011 2:28:51 PM
Access Restriction Public


In the class CMFCToolBarImages there are two static HDC variables named hDCGlyphs and hDCMono.  Failure to clear these static variable can cause an ActiveX control's host to fail to shut down.

I discovered this issue in an ActiveX control that used CMFCVisualManagerOffice2007.  Use of this VisualManager will make it impossible to cleanly shut down the host of an ActiveX control that employs it because invocation of the GdiplusStartupOutput::NotificationUnhook function will cause GDI+ to launch a thread.  GdiplusShutdown will then not fully shut GDI+ down and the host process will remain resident.

Note: I was able to work around this problem by calling	CMFCToolBarImages::CleanUp() prior to calling GdiplusStartupOutput::NotificationUnhook.
Sign in to post a comment.
Posted by Microsoft on 3/7/2011 at 10:31 AM
Hi Greg,

Thanks for the responses. I am glad to hear that the fix in SP1 has resolved the problem for you. Do you happen to have a small repro case that we can use to verify for ourselves? This would also help us to make sure that we don't cause regressions in this area. Thanks!

Pat Brenner
Visual C++ Libraries Development
Posted by Greg Prosch on 2/21/2011 at 10:43 AM
I see now that my further problem resulted from not calling CWinApp::ExitInstance before calling the GDI+ shutdown logic. All is well now that I am using SP1 beta and making that call first.
Posted by Greg Prosch on 2/17/2011 at 3:03 PM
It appears that your assertion is correct in that the CMFCToolBarImages::CleanUp function is being called during CWinApp destruction in SP1. Unfortunately, my implementation is inside an ActiveX control where I am managing GDI+ resources. This necessitates that I call the NotificationHook/Unhook methods. If I don't invoke CMFCToolBarImages::CleanUp prior to calling NotificationUnhook then a GDI+ thread will be spawned which will cause my app to hang on shutdown.

I have successfully worked around this issue though by making calls in the following order from my ExitInstance:

        // Explicitly free static DC's

    // Ensure that the VisualManager resources are properly released.

    if (NULL != m_gdiplusToken)
        if (NULL != m_gdiplusHookToken)

        // Release GDI+ resources.
Posted by Microsoft on 2/17/2011 at 2:26 PM

Thanks for the report. I believe this issue has been fixed in VS2010 SP1. The call to ControlBarCleanup (which in turn calls CMFCToolBar::CleanUpImages, which in turn calls CMFCToolBarImages::CleanUp) has been moved from CWinAppEx::ExitInstance to CWinApp::ExitInstance, so all CWinApp-derived classes will clean up the images on exit.

This should fix the issue that you are reporting, since it causes the same code path to be executed as your workaround does. We are attempting to verify here, but if you have an example with which we can reproduce the problem we can make sure.

Pat Brenner
Visual C++ Libraries Development
Posted by Microsoft on 2/14/2011 at 6:53 PM
Thank you for reporting this issue.
Could you please attach a project to help us reproduce this issue?
Posted by Microsoft on 2/14/2011 at 3:00 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(