Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CDialog::EndDialog crashes application

CDialog::EndDialog crashes application

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leatrop
    wrote on last edited by
    #1

    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

    K R 2 Replies Last reply
    0
    • L leatrop

      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

      K Offline
      K Offline
      khan
      wrote on last edited by
      #2

      I do not know if this will work. Anyway, try this: ((ProgressDialog *)lparam)->PostMessage(WM_COMMAND,IDOK); this is this.

      L 1 Reply Last reply
      0
      • L leatrop

        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

        R Offline
        R Offline
        Rahim Rattani
        wrote on last edited by
        #3

        No problem with the code. Please paste the stack trace and ProgressDialog class. Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan

        L 1 Reply Last reply
        0
        • K khan

          I do not know if this will work. Anyway, try this: ((ProgressDialog *)lparam)->PostMessage(WM_COMMAND,IDOK); this is this.

          L Offline
          L Offline
          leatrop
          wrote on last edited by
          #4

          Thank you khan++ - PostMessage has fixed the problem. I still wondered what was wrong with EndDialog??!!

          1 Reply Last reply
          0
          • R Rahim Rattani

            No problem with the code. Please paste the stack trace and ProgressDialog class. Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan

            L Offline
            L Offline
            leatrop
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups