Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Docking Pane
  New Posts New Posts RSS Feed - Heap Corruption After Attaching View to DockingPan
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Heap Corruption After Attaching View to DockingPan

 Post Reply Post Reply
Author
Message
tommyvee View Drop Down
Groupie
Groupie


Joined: 21 August 2007
Location: United States
Status: Offline
Points: 11
Post Options Post Options   Thanks (0) Thanks(0)   Quote tommyvee Quote  Post ReplyReply Direct Link To This Post Topic: Heap Corruption After Attaching View to DockingPan
    Posted: 05 October 2010 at 8:00pm
I have been tracing down a problem where an application using code jock reports heap corruption on exit. By moving the exit location around in the code until I can determine where the heap corruption occurs I have found that the heap is corrupted after I attach a CTReeView derived class to a Docking Pane. If I attach the m_dlgPane from the ActivePaneView sample to the pane, then no heap corruption occurs.

So here is the definition of the CTreeView class I attach

CTreeViewReports m_wnd_cTreeViewReports;

and here is the code to attach it

if (!::IsWindow(m_wnd_cTreeViewReports.m_hWnd))
{
       if (!m_wnd_cTreeViewReports.CreateEx(WS_EX_CLIENTEDGE, NULL,NULL,
WS_CHILD|ES_AUTOVSCROLL|ES_MULTILINE, CRect(0, 0,200, 120), this, IDR_TREEVIEW_REPORTS))
{
TRACE0( "Error creating m_wnd_cTreeViewReports tab in Results Docking Pane.\n" );
}
else{
pPane->Attach(&m_wnd_cTreeViewReports);
}
               
and the declaration of the CTReeViewReports class is based on CTreeView as below

class CTreeViewReports : public CTreeView
{
protected:
//CTreeViewReports();           // protected constructor used by dynamic creation
DECLARE_DYNCREATE(CTreeViewReports)

// Attributes
public:
CTreeCtrl* m_TreeCtrl;
CImageList m_ImageList;

// Operations
public:

CTreeViewReports(); // TWV 8/9/10 Made public for m_wnd_cTreeViewReports member construction
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTreeViewReports)
protected:
virtual void OnDraw(CDC* pDC);      // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CTreeViewReports(); // TWV 8/9/10 Made public for m_wnd_cTreeViewReports member construction
protected:
//virtual ~CTreeViewReports();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

// Generated message map functions
protected:
//{{AFX_MSG(CTreeViewReports)
afx_msg void OnItemExpanding(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnSelChanged(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnFileSaveAs();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_TREEVIEWREPORTS_H__C8FFA603_70C6_11D2_B67F_00104B6C110D__INCLUDED_)

}

I notice in the CodeJock samples that CView derived objects are usually attached with RUNTIME_CLASS like in the code cut-and-pasted from  the ActivePaneViewbelow, but is that required???

if (!m_pViewOne)
{
m_pViewOne = DYNAMIC_DOWNCAST(CViewOne,
pPane->AttachView(this, RUNTIME_CLASS(CViewOne)));
}
else
{
pPane->Attach(m_pViewOne->GetParent());
}

Thanks,
Tom
Back to Top
tommyvee View Drop Down
Groupie
Groupie


Joined: 21 August 2007
Location: United States
Status: Offline
Points: 11
Post Options Post Options   Thanks (0) Thanks(0)   Quote tommyvee Quote  Post ReplyReply Direct Link To This Post Posted: 05 October 2010 at 11:58pm
Just wanted to mention that changing from pPane->Attach() to pPane->AttachView() for CView based objects fixed my heap corruption problem.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.125 seconds.