我生成一个Dialog,在里面有一个按牛,点了一下和一个服务器建立连接,发送连接信息,服务器返回信息后,要动态的更新界面。
在协议解吸里面收到服务器的确认后,我调用
ReturnLoginInfo(int pReturn)
{
        if(pReturn==0)
 {
       m_SystemStatic="身份验证失败,用户名不存在.........";
 **               this->RedrawWindow();
return;
 } 
}在OnPaint()里面是这样的
void CPLoginDialog::OnPaint() 
{
CPaintDC dc(this); // device context for painting

dc.BitBlt(0,0,489,246,&memdc,0,0,SRCCOPY);
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(RGB(0,0,255));
dc.TextOut(108,76,m_SystemStatic);
}
可以一到那个*号的地方就出现异常呢?什么原因,百思不解呀

解决方案 »

  1.   

    First-chance exception in ConferClient.exe (KERNEL32.DLL): 0xC0000005: Access Violation.
    First-chance exception in ConferClient.exe (HOOKDLL.DLL): 0xC0000005: Access Violation.
    这是什么意思啊?哪位大哥帮忙看看,到底什么问题啊?
      

  2.   

    m_SystemStatic="身份验证失败,用户名不存在.........";m_SystemStatic是什么类型的变量?char*的话就挂了,CString就没问题
      

  3.   

    是CString 类型的啊,是在dc里面把他写出来的
      

  4.   

    异常说Access violation????
    可能找不到当前窗口的句并?对不对?
      

  5.   

    异常出现直接跳到这个里面了,
    CPaintDC::CPaintDC(CWnd* pWnd)
    {
    ASSERT_VALID(pWnd);
    ** ASSERT(::IsWindow(pWnd->m_hWnd)); if (!Attach(::BeginPaint(m_hWnd = pWnd->m_hWnd, &m_ps)))
    AfxThrowResourceException();
    }
    ????
      

  6.   

    The exception comes because you call ReturnLoginInfo before your dialog window 
    has been created!Just add a logic :
    ReturnLoginInfo(int pReturn)
    {
            if(pReturn==0)
     {
           m_SystemStatic="身份验证失败,用户名不存在.........";
                      if(this->m_hWnd)
     **                      this->RedrawWindow();
           return;
     } 
    }If this function is only called once prior to your dialog window creation,then 
    it has no effect ,then you should post a message or use EVENT object to do that 
    job!
      

  7.   

    我觉得应该是绘的时候找不到当前窗口的问题,我用this->SendMessage()也不行,会出现问题。
    但是用AfxGetApp()->GetMainWnd()->SendMessage()就可以????
      

  8.   

    你是在另一个线程里调用的吧.MFC的CWnd是线程不安全的.如果要跨线程来操作CWnd,最好通过句柄来发送消息.