I work on a C++/ MFC app on Visual Studio 2013, Win7 32bit. I have a Main application with a dialog where I put a DateTimePicker MFC object. For the initilization I used the DDX_DateTimeCtrl
and a m_odtFilterData
member variable.
void CClassDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_DateTimeCtrl(pDX, IDC_DATE, m_odtFilterData);
}
BOOL CClassDlg::OnInitDialog()
{
COleDateTime odtCurrDate = COleDateTime::GetCurrentTime();
m_odtFilterData.SetDate(odtCurrDate.GetYear(), 1, 1);
CDialog::OnInitDialog();
//etc etc
UpdateData(FALSE);
return TRUE;
}
After I added a Date Time Change event
BEGIN_MESSAGE_MAP(CClassDlg, CDialog)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATE, &CClassDlg::OnDtnDatetimechange)
END_MESSAGE_MAP()
and
void CClassDlg::OnDtnDatetimechange(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
if(m_odtExampleODTVarThatIHave > m_odtFilterData)
{
//do stuff
}
*pResult = 0;
}
The problem is that when in the dialog I choose the date with the datetimepicker, sometimes, the app crash with this error:
Windows has triggered a breakpoint in AppName.exe.
This may be due to a corruption of the heap, which indicates a bug in AppName.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while AppName.exe has focus.
The output window may have more diagnostic information.
The output only says:
HEAP[AppName.exe]: HEAP: Free Heap block 279850 modified at 279e1c after it was freed
And the breakpoint is stucked at mfc\appmodul.cpp:
extern "C" int WINAPI
_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine, int nCmdShow)
#pragma warning(suppress: 4985)
{
// call shared/exported WinMain
/*->*/return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}
It's very strange and happens only few click on the button of the datetimepicker that shows the months widget. If, instead of the widget, I use the Spin Control all works perfectly... Do you have any idea? The button that open the month widget
Another thing, if I remove the
if(m_odtExampleODTVarThatIHave > m_odtFilterData)
all works. It seems that for some reason, the m_odtFilterData variabile gets corrupted by month widget. I don't understand where is my error.