Re: Updating Controls from a Thread Causes Access Violation

From: Jim Howard (jnhtx_at_spamcop.net)
Date: 11/10/04


Date: Wed, 10 Nov 2004 13:38:49 -0600

Pass into your thread a pointer to the GUI's window object (either a window
handle or a CWnd*) . Use this pointer to send a message from the thread to
the dialog window to tell it to update. Direct messing about with the GUI
from a worker thread is "Considered Harmful".

Jim H

"Brad McMillan" <mcmillan@viselect.com> wrote in message
news:4191d942.176097375@dslnews.netwiz.net...
> Hi:
>
> I have a VC++ 6.0 Dialog based application where I'm trying to update
> a static control from a thread.
>
> My main dialog is:
>
> CMyDlg* myDlg;
>
> I create the thread with the following code:
>
> myDlg = this;
> void myThread(void *ch);
> _beginthread( myThread, 1000, (void*)(ch));
>
> Then, I am updating my static control from within the thread with:
>
> myDlg->myVar = "Test";
> myDlg->OnUpdateControls();
>
> where myVar is a CString variable associated with my static control.
>
> The method OnUpdateControls is:
>
> void CMyDlg::OnUpdateControls()
> {
> UpdateData(FALSE);
> }
>
> The problem is that when I run this under Debug I get an access
> violation when UpdateData(FALSE) is executed.
>
> Can anyone tell me why I'm getting an access violation here? Or, is
> there a better way of updating my static control from within the
> thread?
>
> TIA,
> Brad McMillan
>
>
>



Relevant Pages

  • Re: Updating Controls from a Thread Causes Access Violation
    ... > Pass into your thread a pointer to the GUI's window object (either a ... Use this pointer to send a message from the thread ... >> where myVar is a CString variable associated with my static control. ... >> Can anyone tell me why I'm getting an access violation here? ...
    (microsoft.public.vc.mfc)
  • TWM for the common man (or Maam)
    ... twm - Tab Window Manager for the X Window System ... Twm is a window manager for the X Window System. ... It provides titlebars, shaped windows,several forms of icon management, user-defined macro functions, click-to-type and pointer-driven keyboard focus, and user-specified key and pointer button bindings. ...
    (comp.sys.ibm.ps2.hardware)
  • Re: GetOpenFileName filters not working
    ... store a pointer with each window and store all of the unique data you want. ... HWND hWnd; ...
    (microsoft.public.win32.programmer.ui)
  • Re: MDI as SDI
    ... > I decided to "fake" SDI by handling New, Open, Close, etc. such that only ... > // there are cases where destroying the documents may destroy the ... > // main window of the application. ... because the pointer is not NULL ...
    (microsoft.public.vc.mfc)
  • Re: Designing a Modern Window System
    ... I have started writing a document today about my thoughts on window ... create a great window system design. ... by trapping the pointer in the first box, ... I have experienced that annoying problem with popup ...
    (comp.windows.x)

Loading