Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - CXTPTaskDialog dynamic allocation and deletion
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTPTaskDialog dynamic allocation and deletion

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


Joined: 10 November 2007
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote solo Quote  Post ReplyReply Direct Link To This Post Topic: CXTPTaskDialog dynamic allocation and deletion
    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
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1210
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1210
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1210
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
solo View Drop Down
Groupie
Groupie


Joined: 10 November 2007
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote solo Quote  Post ReplyReply Direct Link To This Post 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).
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.047 seconds.