Click here to Skip to main content
11,704,107 members (49,954 online)
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 Maciej Los 530
1 OriginalGriff 510
2 Sergey Alexandrovich Kryukov 421
3 Andy Lanng 294
4 F-ES Sitecore 220
0 OriginalGriff 8,744
1 Sergey Alexandrovich Kryukov 7,747
2 CPallini 5,107
3 Maciej Los 4,716
4 Mika Wendelius 3,606


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 11 Jul 2011
Copyright © CodeProject, 1999-2015
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