CControlBar::m_bAutoDelete=TRUE causes shutdown crash porting from VC6 to VC7 
Author Message
 CControlBar::m_bAutoDelete=TRUE causes shutdown crash porting from VC6 to VC7

CControlBar::m_bAutoDelete = TRUE causes shutdown crash when porting working
code from VC6 to VC7.  This occurs because MFC's
CFrameWnd::DestroyDockBars() in VC6 just destroyed the CDockBars, but in
VC7, the same MFC method now destroys all the CControlBars after it has
destroyed the CDockBars.   Too bad that when destroyed, the CDockBars
destroy the CControlBar windows, which also delete this if m_bAutoDelete is
TRUE.

I guess the workarounds are:

a) don't set m_bAuoDelete = TRUE like the documentation suggests yoo do if
you allocate on the heap  (of course, then you have to make sure you delete
these objects AFTER the associated windows are destroyed)

b) call the undocumented CFrameWnd::RemoveControlBar() and remove all your
heap-allocated CControlBars prior to calling CFrameWnd::OnClose().

Perhaps Microsoft will fix this bug in an upcoming service pack????? Nudge
nudge, hint, hint;)



Tue, 19 Apr 2005 06:15:12 GMT  
 CControlBar::m_bAutoDelete=TRUE causes shutdown crash porting from VC6 to VC7
Can you provide us with a simple project in VC6 that reproduces the problem?

Quote:

> CControlBar::m_bAutoDelete = TRUE causes shutdown crash when porting
> working code from VC6 to VC7.  This occurs because MFC's
> CFrameWnd::DestroyDockBars() in VC6 just destroyed the CDockBars, but
> in VC7, the same MFC method now destroys all the CControlBars after
> it has destroyed the CDockBars.   Too bad that when destroyed, the
> CDockBars destroy the CControlBar windows, which also delete this if
> m_bAutoDelete is TRUE.

> I guess the workarounds are:

> a) don't set m_bAuoDelete = TRUE like the documentation suggests yoo
> do if you allocate on the heap  (of course, then you have to make
> sure you delete these objects AFTER the associated windows are
> destroyed)

> b) call the undocumented CFrameWnd::RemoveControlBar() and remove all
> your heap-allocated CControlBars prior to calling
> CFrameWnd::OnClose().

> Perhaps Microsoft will fix this bug in an upcoming service pack?????
> Nudge nudge, hint, hint;)

--
Chuck Mitchell and Steven Toscano
Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers no
rights.


Sat, 23 Apr 2005 03:47:52 GMT  
 CControlBar::m_bAutoDelete=TRUE causes shutdown crash porting from VC6 to VC7
1) in VC6, use appwizzzzard to make an MFC app and include toolbar support

2) Modify the mainframe definition to add the following member ptr:

 CToolBar    *m_pwndToolBar2;

3) Modify the mainframe implementation as follows:

CMainFrame::CMainFrame()
{
     m_pwndToolBar2 = NULL;

Quote:
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
 if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  return -1;

 if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE |
CBRS_TOP
  | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
 {
  TRACE0("Failed to create toolbar\n");
  return -1;      // fail to create
 }

 m_pwndToolBar2 = new CToolBar;
 if (!m_pwndToolBar2->CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE |
CBRS_TOP
  | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  !m_pwndToolBar2->LoadToolBar(IDR_MAINFRAME))
 {
  TRACE0("Failed to create toolbar\n");
  return -1;      // fail to create
 }
 m_pwndToolBar2->m_bAutoDelete = TRUE; //will delete when mainframe does

 if (!m_wndStatusBar.Create(this) ||
  !m_wndStatusBar.SetIndicators(indicators,
    sizeof(indicators)/sizeof(UINT)))
 {
  TRACE0("Failed to create status bar\n");
  return -1;      // fail to create
 }

 // TODO: Delete these three lines if you don't want the toolbar to
 //  be dockable
 m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
 m_pwndToolBar2->EnableDocking(CBRS_ALIGN_ANY);
 EnableDocking(CBRS_ALIGN_ANY);
 DockControlBar(&m_wndToolBar);
 DockControlBar(m_pwndToolBar2);

 return 0;

Quote:
}

that's it, build the app in VC6, and it will run and shutdown fine.  Build
it in VC.Net, run it, and it will crash when you close the app.



Quote:
> Can you provide us with a simple project in VC6 that reproduces the
problem?


> > CControlBar::m_bAutoDelete = TRUE causes shutdown crash when porting
> > working code from VC6 to VC7.  This occurs because MFC's
> > CFrameWnd::DestroyDockBars() in VC6 just destroyed the CDockBars, but
> > in VC7, the same MFC method now destroys all the CControlBars after
> > it has destroyed the CDockBars.   Too bad that when destroyed, the
> > CDockBars destroy the CControlBar windows, which also delete this if
> > m_bAutoDelete is TRUE.

> > I guess the workarounds are:

> > a) don't set m_bAuoDelete = TRUE like the documentation suggests yoo
> > do if you allocate on the heap  (of course, then you have to make
> > sure you delete these objects AFTER the associated windows are
> > destroyed)

> > b) call the undocumented CFrameWnd::RemoveControlBar() and remove all
> > your heap-allocated CControlBars prior to calling
> > CFrameWnd::OnClose().

> > Perhaps Microsoft will fix this bug in an upcoming service pack?????
> > Nudge nudge, hint, hint;)

> --
> Chuck Mitchell and Steven Toscano
> Visual C++ Team
> This posting is provided "AS IS" with no warranties, and confers no
> rights.



Sat, 23 Apr 2005 05:43:03 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. CControlBar::m_bAutoDelete=TRUE causes shutdown crash porting from VC6 to VC7

2. IEnumUnknown->Next method causes a crash in MFC 7.1 (VS .net 2003)

3. System::Runtime::InteropServices::Out with Arrays

4. BUG: IDBPropertiesImpl::SetProperties will not compile with /Zc:forScope

5. error analysis/handling/detecting/reporting/preventing/recovery/reproduce/debug

6. AssertValid failing in CControlBar in VC6

7. CControlBar causes Access Violation 0xC0000005

8. bufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbuf

9. How to debug Shutdown crash?!

10. Firewall Shutdown Ports, Thread count

11. CreateMeasurementGraphics().GetHdc() causes exception in debug only

12. Slow application shutdowns under VS Beta2

 

 
Powered by phpBB® Forum Software