Lescha
asked on
Worker thread and AfxGetMainWnd
I have the following piece of code:
CWnd *CMyApp::GetView()
{
CMainFrame *pFrm = (CMainFrame *)AfxGetMainWnd();
return pFrm->GetActiveView();
}
It works fine from the main thread of the application. For some reason, I cannot call this function from a worker thread.
I have heard there is a problem when AfxGetMainWnd is called from a worker thread. Is this correct, and if so, why and what kind of problems?
CWnd *CMyApp::GetView()
{
CMainFrame *pFrm = (CMainFrame *)AfxGetMainWnd();
return pFrm->GetActiveView();
}
It works fine from the main thread of the application. For some reason, I cannot call this function from a worker thread.
I have heard there is a problem when AfxGetMainWnd is called from a worker thread. Is this correct, and if so, why and what kind of problems?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The problem was that I forgot to create the thread as suspended, set its Main Window pointer, and then resume.
Still, it would be unfair to deny the answer points to Alex.
James - just for the record, SendMessage in the way you suggested crashes the application in Release mode. Dunno why.
Still, it would be unfair to deny the answer points to Alex.
James - just for the record, SendMessage in the way you suggested crashes the application in Release mode. Dunno why.
Something like:
theApp.m_pMainWnd->SendMes