Click here to Skip to main content
13,089,610 members (80,354 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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..
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........................ }
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
Updated 11-Jul-11 5:18am
Rate this: bad
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
Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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