Hi,
I am working on a DLL which will display a modeless dialog
box. The executing program first calls an initialisation
routine in the DLL (which calls .Create()), and then starts
polling another routine, which should update a certain
control in the Dialog. The polling routine does this by
calling a member function of dialog box, which updates
the associated member variable and then calls its inherited
UpdateData(true).
When debugging the application, I get an Assertion error at
when calling the UpdateData function. Further tracing the
problem I found the fail in WinCore.cpp (CWnd::AssertValid).
The call that causes the fail is afxMapHWND, which returns
a NULL value. The comment for this ASSERT check says:
A comment a little lower says :
What I basically have is the following:
If this is caused by the calling program being multithreaded
than how must I use this CWnd::FromHandle in the polling
routine ?
Or is there something else I am doing wrong ?
Regards,
Alex van L.
I am working on a DLL which will display a modeless dialog
box. The executing program first calls an initialisation
routine in the DLL (which calls .Create()), and then starts
polling another routine, which should update a certain
control in the Dialog. The polling routine does this by
calling a member function of dialog box, which updates
the associated member variable and then calls its inherited
UpdateData(true).
When debugging the application, I get an Assertion error at
when calling the UpdateData function. Further tracing the
problem I found the fail in WinCore.cpp (CWnd::AssertValid).
The call that causes the fail is afxMapHWND, which returns
a NULL value. The comment for this ASSERT check says:
Code:
//should also be in the permanent or temporary handle map
Code:
// Note: if either of the above asserts fire and you are
// writing a multithreaded application, it is likely that
// you have passed a C++ object from one thread to another
// and have used that object in a way that was not intended.
// (only simple inline wrapper functions should be used)
//
// In general, CWnd objects should be passed by HWND from
// one thread to another. The receiving thread can wrap
// the HWND with a CWnd object by using CWnd::FromHandle.
//
// It is dangerous to pass C++ objects from one thread to
// another, unless the objects are designed to be used in
// such a manner.
Code:
CMyDialog myDialog;
DLLEXPORT int MyInitRoutine ()
{
// MyInitRoutine actually get called twice.
if (myDialog.m_hWnd == NULL)
myDialog.Show(IDD_MYDLG, NULL);
myDialog.UpdateFunction (); // <- works
}
DLLEXPORT int MyPollingRoutine ()
{
myDialog.UpdateFunction(); // <- fails in UpdateData
}
CMyDialog::UpdateFunction ()
{
// Update some member variables
// Call UpdateData to allow DDX and DDV to apply the changes
UpdateData (true);
}
If this is caused by the calling program being multithreaded
than how must I use this CWnd::FromHandle in the polling
routine ?
Or is there something else I am doing wrong ?
Regards,
Alex van L.