Print Page | Close Window

CXTPTaskDialog dynamic allocation and deletion

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=10177
Printed Date: 14 November 2025 at 8:08pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTPTaskDialog dynamic allocation and deletion
Posted By: solo
Subject: CXTPTaskDialog dynamic allocation and deletion
Date Posted: 10 April 2008 at 2:20pm
Hi,
 
What is wrong with this class.
 

class CWaitDialog : public CXTPTaskDialog

{

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



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


Posted By: Oleg
Date 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


Posted By: mgampi
Date 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


Posted By: mgampi
Date 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


Posted By: solo
Date 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).



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