Heap Corruption After Attaching View to DockingPan |
Post Reply |
Author | |
tommyvee
Groupie Joined: 21 August 2007 Location: United States Status: Offline Points: 11 |
Post Options
Thanks(0)
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
|
|
tommyvee
Groupie Joined: 21 August 2007 Location: United States Status: Offline Points: 11 |
Post Options
Thanks(0)
|
Just wanted to mention that changing from pPane->Attach() to pPane->AttachView() for CView based objects fixed my heap corruption problem.
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |