![]() |
CXTPTaskDialog dynamic allocation and deletion |
Post Reply
|
| Author | |
solo
Groupie
Joined: 10 November 2007 Status: Offline Points: 17 |
Post Options
Thanks(0)
Quote Reply
Topic: CXTPTaskDialog dynamic allocation and deletionPosted: 10 April 2008 at 2:20pm |
|
Hi,
What is wrong with this class.
{ public: CWaitDialog(CWnd* pWndParent, CString csTitle, CString csInstruction, LPCWSTR pszIconResource = TD_INFORMATION_ICON): CXTPTaskDialog(pWndParent){ SetWindowTitle(csTitle); SetMainInstruction(csInstruction); SetMainIcon(pszIconResource); SetCommonButtons(TDCBF_CANCEL_BUTTON); ShowProgressBar(TRUE, TRUE);} virtual void OnDialogConstructed(){ if (m_config.dwFlags & TDF_SHOW_PROGRESS_BAR) SetProgressBarPos(60); if (m_config.dwFlags & TDF_SHOW_MARQUEE_PROGRESS_BAR) StartProgressBarMarquee(1, 50); EnableButton(IDCANCEL, FALSE);} virtual void PostNcDestroy(){ // TODO: Add your specialized code here and/or call the base class CXTPTaskDialog::PostNcDestroy(); // Release resources from heap delete this;} } ;When I call m_pWaitDlg ->ClickButton(IDCANCEL);where m_pWaitDlg is the pointer to the object created in heap, every thing seems fine. But when I close my main application, the debugger open free.c and shows me this line. retval = HeapFree(_crtheap, 0, pBlock); [Line 109]What is the problem. Why is there a corruption in heap.
Thanks
|
|
![]() |
|
mgampi
Senior Member
Joined: 14 July 2003 Status: Offline Points: 1210 |
Post Options
Thanks(0)
Quote Reply
Posted: 10 April 2008 at 3:07pm |
|
Hi;
Can you show the call stack when the app core dumps; where and how is m_pWaitDlg constructed?
|
|
|
Martin Product: Xtreme Toolkit v 22.1.0, new Projects v 24.0.0 Platform: Windows 10 v 22H2 (64bit) Language: VC++ 2022 |
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 11 April 2008 at 1:02am |
|
Hi,
Problem can be with virtual void PostNcDestroy()
In Vista we use System TaskDialog - and PostNcDestroy will be never called.
|
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
mgampi
Senior Member
Joined: 14 July 2003 Status: Offline Points: 1210 |
Post Options
Thanks(0)
Quote Reply
Posted: 11 April 2008 at 1:51am |
|
Hi Oleg;
but wouldn't this result in a memory leak instead of a heap corruption?
|
|
|
Martin Product: Xtreme Toolkit v 22.1.0, new Projects v 24.0.0 Platform: Windows 10 v 22H2 (64bit) Language: VC++ 2022 |
|
![]() |
|
mgampi
Senior Member
Joined: 14 July 2003 Status: Offline Points: 1210 |
Post Options
Thanks(0)
Quote Reply
Posted: 11 April 2008 at 2:20am |
|
Hi Solo;
Another suggestion:
What about using a std::auto_ptr<CWaitDialog> member in the parent class of your dialog?
|
|
|
Martin Product: Xtreme Toolkit v 22.1.0, new Projects v 24.0.0 Platform: Windows 10 v 22H2 (64bit) Language: VC++ 2022 |
|
![]() |
|
solo
Groupie
Joined: 10 November 2007 Status: Offline Points: 17 |
Post Options
Thanks(0)
Quote Reply
Posted: 12 April 2008 at 1:55am |
|
Hi,
Well, I am not sure about the exact problem but I agree that the problem shouldn't be with the heap if PostNcDestroy is not called rather it should a simple memory leak. Seems like I am messing up the threads in my application. I will try to resolve the issue and complete this thread by mentioning my mistake.
Thanks a lot for help (everybody).
|
|
![]() |
|
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 |