:监听线程时出现如上异常

求救:监听线程时出现如下错误
Unhandled exception at 0x004edda7 in imsi_tool.exe: 0xC0000005: Access violation reading location 0x000004dc.
C/C++ code

DWORD ThreadFunction(LPVOID pParam)//线程函数
{
   DWORD dwEvtMask ,dwResult;
   tOverLaped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);//创建一个事件
   
   while(IsFun)
   {
      //等待窗口事件
      WaitCommEvent(((Cimsi_toolDlg*)AfxGetMainWnd())->h_Com,&dwEvtMask, &tOverLaped);
      //如果事件没有信号,延时0.1秒
      dwResult = WaitForSingleObject(tOverLaped.hEvent, 100);

      if(dwResult == WAIT_OBJECT_0) //事件对象有信号
      {
         if(dwEvtMask == EV_RXCHAR) //接收到数据
         {
            if(IsStop)//发送停止
            {
               IsStop = FALSE;
               //发送消息,由消息处理函数接收数据
               ::PostMessage(AfxGetMainWnd()->m_hWnd, CM_RECEIVE, 0,(LPARAM)EV_RXCHAR);
            } 
         } 
      }
   }
   
   return 0;
}


经调试时死在WaitCommEvent(((Cimsi_toolDlg*)AfxGetMainWnd())->h_Com,&dwEvtMask, &tOverLaped);
这行

------解决方案--------------------
WaitCommEvent(((Cimsi_toolDlg*)AfxGetMainWnd())->h_Com,&dwEvtMask, &tOverLaped);
这句有问题

在线程中一般不这样用AfxGetMainWnd()
通过 pParam传个Cimsi_toolDlg* 指针

------解决方案--------------------
DWORD param;
Cimsi_toolDlg* pDlg = XXXX;
param = (LPVOID) pDlg;
hThread = CreateThread((LPSECURITY_ATTRIBUTES)NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunction,&param,0, &dwThreadID);

线程中解开
DWORD ThreadFunction(LPVOID pParam)//线程函数
{
Cimsi_toolDlg* pDlg = (Cimsi_toolDlg*)pParam;
}