CDialog::EndDialog crashes application
-
I have pretty simple code void ReadDeviceThread( void *lparam ) { Sleep(2000); ((ProgressDialog *)lparam)->EndDialog(IDOK); } void CMainWindow::OnReadDevice() { static ProgressDialog pd; _beginthread(ReadDeviceThread, 0, &pd); pd.DoModal("Initialising read from device"); } The app crashes at user32.dll (win XP, VC++ 6.0, SP6.0) after call of EndDialog. Specifically it crashes after calling ::EndDialog at the end of the EndDialog routine. void CDialog::EndDialog(int nResult) { ASSERT(::IsWindow(m_hWnd)); if (m_nFlags & (WF_MODALLOOP|WF_CONTINUEMODAL)) EndModalLoop(nResult); ::EndDialog(m_hWnd, nResult); // after this line app crashes at USER32! 77d562cf() } Could anybody please help me with this problem. What's wrong with my code. Thank you
-
I have pretty simple code void ReadDeviceThread( void *lparam ) { Sleep(2000); ((ProgressDialog *)lparam)->EndDialog(IDOK); } void CMainWindow::OnReadDevice() { static ProgressDialog pd; _beginthread(ReadDeviceThread, 0, &pd); pd.DoModal("Initialising read from device"); } The app crashes at user32.dll (win XP, VC++ 6.0, SP6.0) after call of EndDialog. Specifically it crashes after calling ::EndDialog at the end of the EndDialog routine. void CDialog::EndDialog(int nResult) { ASSERT(::IsWindow(m_hWnd)); if (m_nFlags & (WF_MODALLOOP|WF_CONTINUEMODAL)) EndModalLoop(nResult); ::EndDialog(m_hWnd, nResult); // after this line app crashes at USER32! 77d562cf() } Could anybody please help me with this problem. What's wrong with my code. Thank you
-
I have pretty simple code void ReadDeviceThread( void *lparam ) { Sleep(2000); ((ProgressDialog *)lparam)->EndDialog(IDOK); } void CMainWindow::OnReadDevice() { static ProgressDialog pd; _beginthread(ReadDeviceThread, 0, &pd); pd.DoModal("Initialising read from device"); } The app crashes at user32.dll (win XP, VC++ 6.0, SP6.0) after call of EndDialog. Specifically it crashes after calling ::EndDialog at the end of the EndDialog routine. void CDialog::EndDialog(int nResult) { ASSERT(::IsWindow(m_hWnd)); if (m_nFlags & (WF_MODALLOOP|WF_CONTINUEMODAL)) EndModalLoop(nResult); ::EndDialog(m_hWnd, nResult); // after this line app crashes at USER32! 77d562cf() } Could anybody please help me with this problem. What's wrong with my code. Thank you
No problem with the code. Please paste the stack trace and ProgressDialog class. Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan
-
I do not know if this will work. Anyway, try this: ((ProgressDialog *)lparam)->PostMessage(WM_COMMAND,IDOK); this is this.
-
No problem with the code. Please paste the stack trace and ProgressDialog class. Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan
Hmm.., ((ProgressDialog *)lparam)->PostMessage(WM_COMMAND,IDOK) fixes the problem, but what was wrong with EndDialog?! Stack trace: USER32! 77d562cf() CDialog::EndDialog(int) ReadDeviceThread(void *) _threadstart(void *) KERNEL32!7c80b50b() ---------------------------- ProgressDialog.cpp ---------------------------- // ProgressDialog.cpp : implementation file // #include "stdafx.h" #include "monitor.h" #include "ProgressDialog.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // ProgressDialog dialog ProgressDialog::ProgressDialog(CWnd* pParent /*=NULL*/) : CDialog(ProgressDialog::IDD, pParent) { //{{AFX_DATA_INIT(ProgressDialog) m_text = _T(""); //}}AFX_DATA_INIT } void ProgressDialog::OnFinalRelease() { // When the last reference for an automation object is released // OnFinalRelease is called. The base class will automatically // deletes the object. Add additional cleanup required for your // object before calling the base class. CDialog::OnFinalRelease(); } void ProgressDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(ProgressDialog) DDX_Control(pDX, IDC_MPROGRESS, m_bar); DDX_Text(pDX, IDC_MPROGTEXT, m_text); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(ProgressDialog, CDialog) //{{AFX_MSG_MAP(ProgressDialog) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // ProgressDialog message handlers int ProgressDialog::DoModal(char *txt) { m_text = txt; //m_bar.SetRange(0,100); //m_bar.SetPos(0); return CDialog::DoModal(); } void ProgressDialog::SetText(char *txt) { m_text = txt; UpdateData(FALSE); } void ProgressDialog::SetPos(int pos) { m_bar.SetPos(pos); } void ProgressDialog::OnCancel() { // TODO: Add extra cleanup here StopAcc = 0; CancelProgressModal = 1; Sleep(4); // a little delay to stop a collision CDialog::OnCancel(); } void ProgressDialog::SetRange(int min, int max) { m_bar.SetRange(min, max); } ---------------------------- ProgressDialog.h ---------------------------- #if !defined(AFX_PROGRESSDIALOG_H__13AB40A1_4F1A_11D2_932F_F4950FC10000__INCLUDED_) #define AFX_PROGRESSDIALOG_H__13AB40A1_4F1A_11D2_932F_F4950FC10000__INCLUDED_ #include "stdafx.h" #include "resource.h" #if _MSC_VER >= 1000 #pragma once #endi