Search

CMFCToolBarImages may cause ActiveX host shutdown failure by Greg Prosch

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 643999
Opened: 2/14/2011 2:28:51 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
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.
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010 SP1 Beta

What category (if any) best represents this feedback?

Reliability

Steps to reproduce

See description above - to summarize: Create an ActiveX control that uses CMFCVisualManagerOffice2007. Implement GDI+ in the ActiveX control with the background thread suspended and using the GdiplusStartupOutput::NotificationUnhook approach (http://msdn.microsoft.com/en-us/library/ms534046(v=vs.85).aspx)

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

GDI+ spawns a thread when GdiplusStartupOutput::NotificationUnhook is called.

Expected results

GDI+ fully shuts down and releases all resources when GdiplusStartupOutput::NotificationUnhook is called.
File Attachments
0 attachments
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
    CMFCToolBarImages::CleanUp();    

    // Ensure that the VisualManager resources are properly released.
    CMFCVisualManager::DestroyInstance();

    if (NULL != m_gdiplusToken)
    {
        if (NULL != m_gdiplusHookToken)
        {
            m_gdiplusStartupOutput.NotificationUnhook(m_gdiplusHookToken);
        }

        // Release GDI+ resources.
        GdiplusShutdown(m_gdiplusToken);
    }
Posted by Microsoft on 2/17/2011 at 2:26 PM
Hello,

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(http://support.microsoft.com)
Sign in to post a workaround.