На главную Наши проекты:
Журнал   ·   Discuz!ML   ·   Wiki   ·   DRKB   ·   Помощь проекту
ПРАВИЛА FAQ Помощь Участники Календарь Избранное RSS

Дорогие друзья! Поздравляем вас с Новым 2026 годом!

Всем удачи, успеха и благополучия!

msm.ru
! Правила раздела Visual C++ / MFC / WTL (далее Раздела)
1) На Раздел распространяются все Правила Форума.
2) Перед тем, как создать новый топик, убедитесь, что Вы читали Правила создания тем в Разделе.
3) Вопросы, не связанные с программированием (настройки MS Visual Studio, книги, библиотеки и т.д.),
обсуждаются в разделе C/C++: Прочее
4) Вопросы разработки .NET (Windows Form, C++/CLI и т.п.) приложений на Visual C++/C# обсуждаются в разделе .NET.
5) Нарушение Правил может повлечь наказание со стороны модераторов.

Полезные ссылки:
user posted image FAQ Раздела user posted image Обновления для FAQ Раздела user posted image Поиск по Разделу user posted image MSDN Library Online
Модераторы: ElcnU
  
> 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?
      It happens in debug (in release I have not checked yet). But I have something like:
      AfxMessageBox("test");
        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.
        0 пользователей читают эту тему (0 гостей и 0 скрытых пользователей)
        0 пользователей:


        Рейтинг@Mail.ru
        [ Script execution time: 0,0815 ]   [ 16 queries used ]   [ Generated: 10.01.26, 05:39 GMT ]