Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC
Dear All,
 
I am getting assertion error, on implementing the updates for "Close All Others" in MFC Application,, wherein, Tab Document Interface(TDI) has numerous tabs, similar to VS 2008 IDE, and when user right clicks the context menu <<Close All Other>> , which has the following handler ,
 
The following code will close all except the active tab in the "first" MDI client tab group..
//Mainframe.cpp

Begin_message_map
 
..............
 
ON_COMMAND(ID_TAB_CLOSEOTHER, &CMainFrame::OnTabCloseOther)
 
............
 
CMainFrame::OnCloseOtherTab()
 
{
 
Line 1. const CObList* tabList = &m_wndClientArea.GetMDITabGroups(); 
Line 2: CMFCTabCtrl* pTabWnd = (CMFCTabCtrl*)tabList->GetHead(); 
Line 3. if (pTabWnd != NULL) 
Line 4: { 
Line 5: int iActiveTab = pTabWnd->GetActiveTab();
Line 6: ASSERT_VALID(pTabWnd);
Line 7: for (int i = pTabWnd->GetTabsNum() - 1; i >= 0; i--)
Line 8: {
Line 9: CMDIChildWndEx* pNextWnd = DYNAMIC_DOWNCAST CMDIChildWndEx........................ }
//MainFrame.h 

CMDIChientAreaWnd m_wndClientArea; 
 

The assertion is displayed on execution of Line 2. The following line gets displayed on assertion
return AfxWinMain(hInstance, hPrevInstance, lpCmdLine,nCmdShow);
<<<<Unhandled exception at 0x787d01ec (mfc90d.dll)
in CART.exe: 0xC0000005: Access violation reading location x00000008.>>>>
 
Please let me know how to correct the above solution.
 
With Regards,
Posted 11-Jul-11 4:10am
Edited 11-Jul-11 5:18am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The documentation for CObList::GetHead() says that the list cannot be empty and would fail.
 
You are not currently checking the size of the list before getting the head element. Try calling IsEmpty() first to determine whether accessing the head element would be an error.
 
It may be worth stepping through the code to check the the tabList pointer is valid from the call to GetMDITabGroups
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

AfxWinMain() is the entry point of an MFC application, are you sure you're not accidentally calling this method during startup? You may have a conflict with ID_TAB_CLOSEOTHER or something is calling that directly upon startup but before the members are initialized.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 358
1 Sergey Alexandrovich Kryukov 234
2 PhilLenoir 179
3 MT_ 175
4 Yogesh Kumar Tyagi 165
0 Sergey Alexandrovich Kryukov 6,205
1 OriginalGriff 5,333
2 CPallini 2,473
3 Richard MacCutchan 1,617
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 11 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100