Kovarnii AfxMessageBox
![]() |
Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
|
| ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
| [216.73.216.167] |
|
|
Правила раздела Visual C++ / MFC / WTL (далее Раздела)
FAQ Раздела
Обновления для FAQ Раздела
Поиск по Разделу
MSDN Library Online
Kovarnii AfxMessageBox
|
|
|
|
|
I have multithreaded application. I get exeption when AfxMessageBox is called. The crash happens in func. CWinApp::DoMessageBox (it is called from AfxMessageBox)
// restore prompt context if possible if (pdwContext != NULL) *pdwContext = dwOldPromptContext; -> crash is here When I use MessageBox - it works ok. But I don't think that the problem is in AfxMessageBox, but in threads' syncronization. Maybe you got some ideas? |
|
Сообщ.
#2
,
|
|
|
|
It happens in debug (in release I have not checked yet). But I have something like:
AfxMessageBox("test"); |
|
Сообщ.
#3
,
|
|
|
|
No, there is no GetParent. The code goes like that:
HRESULT CMyClass::WaitForEnd() { MSG msg; while (TRUE) { while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage (&msg); DispatchMessage (&msg); } //checks the flag signaled when the event is finished if (((CMyApp *)AfxGetApp())->GetEndFlagState()) break; } return S_OK; } void CMyView::OnCancel() { if (AfxMessageBox ("Hello", MB_YESNO) == IDNO) return; if (!m_pDoc->m_ThreadEnd) { // the thread did not finish its work, so we can not yet // return to the container // tell the thread to finish its work m_bIsCancel = TRUE; m_pDoc->m_abortEvent->SetEvent(); } else { m_bIsCancel = TRUE; // notify CMyThread to exit. SetEvent(m_pDoc->m_pWorkerThread->m_evnExit); // signal flag for returning to container ((CMyApp *)AfxGetApp())->SetEndFlagState(); } } void CMyDoc::ActivateMyThread() { //create thread ... // send to the worker thread its document parent m_pWorkerThread->SetParentDoc(this); m_pWorkerThread->DoWork(); while (TRUE) { while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage (&msg); DispatchMessage (&msg); } // checks the flag signaled when the work is finished dwEventRet = WaitForSingleObject(m_pWorkerThread->m_evnNextFilter, 0); if (dwEventRet == WAIT_OBJECT_0) { break; } if (((CMyApp *)AfxGetApp())->GetEndFlagState()) { pdwFilterColorArr->RemoveAll(); pdwFilterColorArr=NULL; return; } } m_pWorkerThread->m_evnNextFilter.ResetEvent(); m_pWorkerThread->m_evnExit.SetEvent(); } Notice - if I change AfxMessageBox by MessageBox - no crash occurrs. This may be the solution - but it is interesting - why this problem happens. |