Print Page | Close Window

Heap Corruption After Attaching View to DockingPan

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Docking Pane
Forum Description: Topics Related to Codejock Docking Pane
URL: http://forum.codejock.com/forum_posts.asp?TID=17383
Printed Date: 26 April 2024 at 1:31pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Heap Corruption After Attaching View to DockingPan
Posted By: tommyvee
Subject: Heap Corruption After Attaching View to DockingPan
Date 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



Replies:
Posted By: tommyvee
Date 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.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net