Create dialog in second user-interface thread

I created second user-intertface thread. To this thread I post pThread->PostThreadMessage(ID_DISPECER_TRAINS,0,0). On this mesage I create modal dialog. But when I close dialog, in PreTranslateMessage method exception occures (Access Violation).
This problem is just in release version. In debug it works fine.

Here's my thread class:

CDlgThread* CDlgThread::m_pThis = NULL;

IMPLEMENT_DYNCREATE(CDlgThread, CWinThread)

CDlgThread::CDlgThread(CWnd* pWnd)
{
      m_pThis = this;
      m_pMainWnd = pWnd;
}

CDlgThread::~CDlgThread()
{
      m_pThis = NULL;
}

BOOL CDlgThread::InitInstance()
{
      AfxEnableControlContainer();
      return TRUE;
}

int CDlgThread::ExitInstance()
{
      CoUninitialize();
      return CWinThread::ExitInstance();
}

void CDlgThread::OnDispecerTrains()
{
      CStationTrainsDlg dlg(m_pMainWnd, m_pContents, m_pStation);
      dlg.DoModal();
}

BEGIN_MESSAGE_MAP(CDlgThread, CWinThread)
      //{{AFX_MSG_MAP(CDlgThread)
      ON_THREAD_MESSAGE(ID_DISPECER_TRAINS, OnDispecerTrains)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()
knillAsked:
Who is Participating?
 
mikeblasConnect With a Mentor Commented:

Your thread message handler is incorrectly prototyped.  Even though you don't use them, there's wParam and lParam parameters and you need to declare them.  Your prototype is:

   void CDlgThread::OnDispecerTrains()
   {
   }

but should be

   void CDlgThread::OnDispecerTrains(WPARAM wParam, LPARAM lParam)
   {
   }

If you're trying to build at warning level four, you can avoid the "unreferenced parameter" warnings by providing an informal prototype:

   void CDlgThread::OnDispecerTrains(WPARAM, LPARAM)
   {
   }

..B ekiM
0
 
knillAuthor Commented:
Thak you for your answer.
0
All Courses

From novice to tech pro — start learning today.