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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mikeblasCommented:

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
knillAuthor Commented:
Thak you for your answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.