Hello,
I have taken a MFC dialog application. I derived a class called CMyDialog from CAxDialogImpl. I created an object of CMyDialog and called DoModal(); The application runs but i found a memory leak.
I learnt that the memory allocated by HeapAlloc is not freed. Where do i free this? Please help me.
Sumee
Software/Hardware used:
Windows
ASKED:
July 11, 2011 2:15 PM
UPDATED:
March 31, 2012 9:52 PM
Can you post your code ?
Also, how did you determine that the memory is not being freed ?
Thank you for the reply. I run Visual leak detector to check the memory leaks. The trace pointed me to the DoModal of the dialog box. My sample has no code added to the generated one.
Here is the sample code:
class Cdedede :
public CAxDialogImpl<Cdedede>
{
public:
Cdedede()
{
}
~Cdedede()
{
}
enum { IDD = IDD_DEDEDE };
BEGIN_MSG_MAP(Cdedede)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_HANDLER(IDOK, BN_CLICKED, OnClickedOK)
COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnClickedCancel)
CHAIN_MSG_MAP(CAxDialogImpl<Cdedede>)
END_MSG_MAP()
// Handler prototypes:
// LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
// LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
// LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
CAxDialogImpl<Cdedede>::OnInitDialog(uMsg, wParam, lParam, bHandled);
bHandled = TRUE;
return 1; // Let the system set the focus
}
LRESULT OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
EndDialog(wID);
return 0;
}
LRESULT OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
EndDialog(wID);
return 0;
}
};