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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Chrash at UpdateData(FALSE)

Chrash at UpdateData(FALSE)

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++data-structuressecurityannouncement
14 Posts 5 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.
  • M merh

    Hi, Im a MFC bigginer and neeed help to understand the crash which is caused by my program. I have created a Dialog i MFC and in the method OnInitDialog, I create a class which it creates a function in a thread and there is a loop in the method which sends the values to dialog via a interface. When I try to update the dialog by UpdateData(FALSE)the application crashes. Please help me out of this problem Thanks in advance. M.H BOOL CThreadDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here Thread1 *pThread = new Thread1(this); return TRUE; // return TRUE unless you set the focus to a control } void CThreadDlg::setValueAlt1(int inValue1, int invalue2) { m_Value1.Format("%.3d", inValue1); UpdateData(FALSE); } DWORD WINAPI ThreadFunc( LPVOID lpParam ) { ISetValue * pISetValue = (ISetValue *)lpParam; int a=44; int b = 45; for (int i=40; i<100; i++) { pISetValue->setValueAlt1(i, b ); Sleep(10); } return 0; } Thread1::Thread1(ISetValue *pISetValue) { DWORD dwThreadId; HANDLE hThread; LPVOID param = pISetValue; m_pISetValue = pISetValue; //pISetValue->setValueAlt1(44, 99); //return; hThread = CreateThread( NULL, // no security attributes 0, // use default stack size ThreadFunc, // thread function param, // argument to thread function 0, // use default creation flags &dwThreadId); // returns the thread identifier }

    B Offline
    B Offline
    bert_r
    wrote on last edited by
    #4

    Try this: the thread function:

    DWORD WINAPI ThreadFunc( LPVOID lpParam )
    {
    CWnd * pDlg = (pDlg*)lpParam;
    int a = 44;
    int b = 45;
    for (int i=40; i<100; i++)
    {
    pDlg->PostMessage(WMU_SETVALUE1, (WPARAM)i,(LPARAM)b);
    Sleep(10);
    }
    return 0;

    }

    in the dialog.h file

    #define WMU_SETVALUE1 (WM_USER+1)

    in the message map add following line:

    ON\_MESSAGE(WMU\_SETVALUE1,OnSetValue1)
    

    And add following function:

    LRESULT CSurveyUpdateDlg::OnSetValue1(WPARAM wParam, LPARAM lParam)
    {
    setValueAlt1((int)wParam, (int)lParam);
    }

    M 1 Reply Last reply
    0
    • M merh

      Please, can somebody show me how I can do that? Thanks M.H

      J Offline
      J Offline
      jhwurmbach
      wrote on last edited by
      #5

      merh wrote:

      Please, can somebody show me how I can do that?

      Sure. Joseph M. Newcomer can: Threads and Processes Article Series[^]

      Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
      Douglas Adams, "Dirk Gently's Holistic Detective Agency"

      1 Reply Last reply
      0
      • B bert_r

        Try this: the thread function:

        DWORD WINAPI ThreadFunc( LPVOID lpParam )
        {
        CWnd * pDlg = (pDlg*)lpParam;
        int a = 44;
        int b = 45;
        for (int i=40; i<100; i++)
        {
        pDlg->PostMessage(WMU_SETVALUE1, (WPARAM)i,(LPARAM)b);
        Sleep(10);
        }
        return 0;

        }

        in the dialog.h file

        #define WMU_SETVALUE1 (WM_USER+1)

        in the message map add following line:

        ON\_MESSAGE(WMU\_SETVALUE1,OnSetValue1)
        

        And add following function:

        LRESULT CSurveyUpdateDlg::OnSetValue1(WPARAM wParam, LPARAM lParam)
        {
        setValueAlt1((int)wParam, (int)lParam);
        }

        M Offline
        M Offline
        merh
        wrote on last edited by
        #6

        First of all thanks a lot. It dosent work. I have the following interface you mentioned that I could use pDlg->PostMessage(WMU_SETVALUE1, (WPARAM)i,(LPARAM)b); where is comming pDlg? I have got error at CWnd * pDlg = (pDlg*)lpParam; and pDlg->PostMessage(WMU_SETVALUE1, (WPARAM)i,(LPARAM)b); I have copied all files maybe you can see my problem better Thanks M.h // ThreadDlg.cpp : implementation file // #include "stdafx.h" #include "Thread.h" #include "ThreadDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #ifndef GLOGAL #define GLOBAL int Globalvariable; #endif class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CThreadDlg dialog CThreadDlg::CThreadDlg(CWnd* pParent /*=NULL*/) : CDialog(CThreadDlg::IDD, pParent) { //{{AFX_DATA_INIT(CThreadDlg) m_Value1 = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CThreadDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CThreadDlg) DDX_Text(pDX, IDC_VALUE1, m_Value1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CThreadDlg, CDialog) //{{AFX_MSG_MAP(CThreadDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_MESSAGE(WMU_SETVALUE1,OnSetValue1) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CThreadDlg message handlers BOOL CThreadDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system comman

        B 1 Reply Last reply
        0
        • M merh

          First of all thanks a lot. It dosent work. I have the following interface you mentioned that I could use pDlg->PostMessage(WMU_SETVALUE1, (WPARAM)i,(LPARAM)b); where is comming pDlg? I have got error at CWnd * pDlg = (pDlg*)lpParam; and pDlg->PostMessage(WMU_SETVALUE1, (WPARAM)i,(LPARAM)b); I have copied all files maybe you can see my problem better Thanks M.h // ThreadDlg.cpp : implementation file // #include "stdafx.h" #include "Thread.h" #include "ThreadDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #ifndef GLOGAL #define GLOBAL int Globalvariable; #endif class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CThreadDlg dialog CThreadDlg::CThreadDlg(CWnd* pParent /*=NULL*/) : CDialog(CThreadDlg::IDD, pParent) { //{{AFX_DATA_INIT(CThreadDlg) m_Value1 = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CThreadDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CThreadDlg) DDX_Text(pDX, IDC_VALUE1, m_Value1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CThreadDlg, CDialog) //{{AFX_MSG_MAP(CThreadDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_MESSAGE(WMU_SETVALUE1,OnSetValue1) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CThreadDlg message handlers BOOL CThreadDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system comman

          B Offline
          B Offline
          bert_r
          wrote on last edited by
          #7

          You can see I didn't test this ... :sigh: That should have been:

          CWnd * pDlg = (CWnd*)lpParam;

          If that doesn't work, I'll test it myself! :)

          M 1 Reply Last reply
          0
          • B bert_r

            You can see I didn't test this ... :sigh: That should have been:

            CWnd * pDlg = (CWnd*)lpParam;

            If that doesn't work, I'll test it myself! :)

            M Offline
            M Offline
            merh
            wrote on last edited by
            #8

            Hi Thanks, It still dosent work. I get the following error 'CSurveyUpdateDlg' : is not a class or namespace name 'WMU_SETVALUE1' : undeclared identifier If you have a email adress I can send you my workspace which you can test it easier. For your information I have VC++ 6.0 Thanks M.H

            B D 2 Replies Last reply
            0
            • M merh

              Hi Thanks, It still dosent work. I get the following error 'CSurveyUpdateDlg' : is not a class or namespace name 'WMU_SETVALUE1' : undeclared identifier If you have a email adress I can send you my workspace which you can test it easier. For your information I have VC++ 6.0 Thanks M.H

              B Offline
              B Offline
              bert_r
              wrote on last edited by
              #9

              I copy-pasted the OnSetValue1 function of a project of mine, and forgot to edit the class name, so CSurveyUpdateDlg::OnSetValue1 should be CThreadDlg::OnSetValue1 And don't forget to add the function prototype in the ThreadDlg.h header file too:

              afx_msg LRESULT OnSetValue1(WPARAM wParam, LPARAM lParam);

              The WMU_SETVALUE1 error is caused by a missing

              #include "Thread.h"

              in the file where you're calling PostMessage(WMU_SETVALUE1, ...) That should do it.

              M 1 Reply Last reply
              0
              • B bert_r

                I copy-pasted the OnSetValue1 function of a project of mine, and forgot to edit the class name, so CSurveyUpdateDlg::OnSetValue1 should be CThreadDlg::OnSetValue1 And don't forget to add the function prototype in the ThreadDlg.h header file too:

                afx_msg LRESULT OnSetValue1(WPARAM wParam, LPARAM lParam);

                The WMU_SETVALUE1 error is caused by a missing

                #include "Thread.h"

                in the file where you're calling PostMessage(WMU_SETVALUE1, ...) That should do it.

                M Offline
                M Offline
                merh
                wrote on last edited by
                #10

                Hi, have got the crash at BOOL AFXAPI AfxAssertFailedLine(LPCSTR lpszFileName, int nLine) { #ifndef _AFX_NO_DEBUG_CRT // we remove WM_QUIT because if it is in the queue then the message box // won't display MSG msg; BOOL bQuit = PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE); BOOL bResult = _CrtDbgReport(_CRT_ASSERT, lpszFileName, nLine, NULL, NULL); if (bQuit) Thanks Mehran

                1 Reply Last reply
                0
                • M merh

                  Hi Thanks, It still dosent work. I get the following error 'CSurveyUpdateDlg' : is not a class or namespace name 'WMU_SETVALUE1' : undeclared identifier If you have a email adress I can send you my workspace which you can test it easier. For your information I have VC++ 6.0 Thanks M.H

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #11

                  merh wrote:

                  'CSurveyUpdateDlg' : is not a class or namespace name 'WMU_SETVALUE1' : undeclared identifier

                  If these basic errors are troubling you, perhaps multithreaded applications should be postponed for a while. They're not a trivial concept.

                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  M 1 Reply Last reply
                  0
                  • D David Crow

                    merh wrote:

                    'CSurveyUpdateDlg' : is not a class or namespace name 'WMU_SETVALUE1' : undeclared identifier

                    If these basic errors are troubling you, perhaps multithreaded applications should be postponed for a while. They're not a trivial concept.

                    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    M Offline
                    M Offline
                    merh
                    wrote on last edited by
                    #12

                    Hi, I need how I can use PostMessage for sending the message with some parameters to main thread(window) and then how I can read the data from It. Best regards Mehran

                    M D 2 Replies Last reply
                    0
                    • M merh

                      Hi, I need how I can use PostMessage for sending the message with some parameters to main thread(window) and then how I can read the data from It. Best regards Mehran

                      M Offline
                      M Offline
                      merh
                      wrote on last edited by
                      #13

                      Thanks a lot it works. Have a nice weekend M.H

                      1 Reply Last reply
                      0
                      • M merh

                        Hi, I need how I can use PostMessage for sending the message with some parameters to main thread(window) and then how I can read the data from It. Best regards Mehran

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #14

                        See here.

                        "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                        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