Error in wincore.cpp when i use "UpdateData(true)" - Programmer

This is a discussion on Error in wincore.cpp when i use "UpdateData(true)" - Programmer ; Hi, i started last week to use MFC in Visual C++ and i have a strange error using UpdateData(): I built an application with a dialog named "IDD_SIMULATOREPROTOCOLLO422_DIALOG", and in SimulatoreProtocollo422Dlg.cpp i write all the methods of the "CSimulatoreProtocollo422Dlg" class. ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Error in wincore.cpp when i use "UpdateData(true)"

  1. Error in wincore.cpp when i use "UpdateData(true)"

    Hi, i started last week to use MFC in Visual C++ and i have a strange
    error using UpdateData():

    I built an application with a dialog named
    "IDD_SIMULATOREPROTOCOLLO422_DIALOG", and in
    SimulatoreProtocollo422Dlg.cpp i write all the methods of the
    "CSimulatoreProtocollo422Dlg" class.

    In another files, "test.cpp", i can refer to my main window by using
    AfxGetApp()->m_pMainWnd, so i define "CSimulatoreProtocollo422Dlg* x =
    (CSimulatoreProtocollo422Dlg*) AfxGetApp()->m_pMainWnd;" and now i can
    access to text field "IDC_INPUTSTATUS" using the associated CString
    "dato" in main windows using "x->dato;" and all works fine.

    But now i need to update values in textfield "dato" and another fields
    while running the program, so i think to use in "test.cpp"

    x->UpdateData(true);

    so in every iteration the application would read the updated values, but
    Visual C++ crashes in wincore.cpp, line 890 in

    ASSERT (pMap != NULL);

    Can someone help me??? :-(


    --
    Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

  2. Re: Error in wincore.cpp when i use "UpdateData(true)"

    Dario Rossi wrote:
    > But now i need to update values in textfield "dato" and another fields
    > while running the program, so i think to use in "test.cpp"
    >
    > x->UpdateData(true);
    >
    > so in every iteration the application would read the updated values, but
    > Visual C++ crashes in wincore.cpp, line 890 in
    >
    > ASSERT (pMap != NULL);
    >
    > Can someone help me??? :-(


    This kind of error is usually caused by creating a secondary thread and
    then attempting to have it call functions of windows that were created
    in the main thread. MFC does not allow that. If that is your problem
    then explain more about the thread and what you need it to do.

    --
    Scott McPhillips [VC++ MVP]


  3. Re: Error in wincore.cpp when i use "UpdateData(true)"

    I create only ONE thread in this way (this 2 functions are in
    "test.cpp"), StartTest() call DoTheTest():

    void startTest(char *pTestName, char codiceConfig)
    {
    ...
    unsigned long TestThreadId;
    hTestThread = ::CreateThread(NULL, 0,
    (LPTHREAD_START_ROUTINE)DoTheTest, 0, 0, &TestThreadId);
    }

    void DoTheTest(void)
    {
    ...
    AfxGetApp()->m_pMainWnd->UpdateData(true);
    ...
    }

    When executed, this UpdateData() that refers to main window (data of
    main window are in "SimulatoreProtocollo422Dlg.cpp" that is the file
    associated to my Dialog "IDD_SIMULATOREPROTOCOLLO422_DIALOG") crash
    the application in "wincore.cpp" at line 890.

    I need simply to call UpdateData() to refresh data submitted in main
    windows to read updated values, because i need to change values during
    the execution, i have no need for a secondary thread! Or MFC creates
    automatically a secondary one?


    --
    Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

  4. Re: Error in wincore.cpp when i use "UpdateData(true)"

    Dario Rossi wrote:
    > I create only ONE thread in this way (this 2 functions are in
    > "test.cpp"), StartTest() call DoTheTest():
    >
    > void startTest(char *pTestName, char codiceConfig)
    > {
    > ...
    > unsigned long TestThreadId;
    > hTestThread = ::CreateThread(NULL, 0,
    > (LPTHREAD_START_ROUTINE)DoTheTest, 0, 0, &TestThreadId);
    > }
    >
    > void DoTheTest(void)
    > {
    > ...
    > AfxGetApp()->m_pMainWnd->UpdateData(true);
    > ...
    > }
    >
    > When executed, this UpdateData() that refers to main window (data of
    > main window are in "SimulatoreProtocollo422Dlg.cpp" that is the file
    > associated to my Dialog "IDD_SIMULATOREPROTOCOLLO422_DIALOG") crash
    > the application in "wincore.cpp" at line 890.
    >
    > I need simply to call UpdateData() to refresh data submitted in main
    > windows to read updated values, because i need to change values during
    > the execution, i have no need for a secondary thread! Or MFC creates
    > automatically a secondary one?
    >
    >


    Terminology: All programs have a main thread. You have created another
    thread, so it is a secondary thread.

    Big Problems: (1) You must use AfxBeginThread in an MFC program. (2)
    Your thread function must conform to the documented prototype. (3) You
    cannot call UpdateData from a secondary thread. MFC windows can only be
    updated from the thread that created them.

    Solutions: Read all the help pages about threading in MFC, starting with
    AfxBeginThread. To accomplish the UpdateData you can PostMessage from
    the thread to the mainframe. Then the mainframe message handler can
    call UpdateData. See this for an example of how to do that:
    http://www.mvps.org/vcfaq/mfc/index.htm

    --
    Scott McPhillips [VC++ MVP]


+ Reply to Thread