我写了一个简单的client程序,但发现client程序运行在debug模式的时候点Button1会出错,出错提示请看附件图片,而release模式运行正常,现将client的工程附上,请各位指点一下我看了下出错的时候在执行hwnd->UpdateData(true);开发环境是vs2008+sp1
工程:client.rar错误提示:error.png

解决方案 »

  1.   

    这是因为UpdateData中有ASSERT检查,debug下起作用,所以就提示你有问题,release下,ASSERT什么也不干,所以不会提示错误。
    从你的代码看,应该有问题
    hwnd->UpdateData(true);
    你这个hwnd是模式对话框还是非模式对话框呢?应该是模式对话框吧,把这行代码所在的函数贴出来看看吧,然后说明一下hwnd的定义。
      

  2.   

    如果Debug模式下出错,那就是代码有问题,建议你检查一下hwnd上的控件,是不是有下拉框什么的,我之前也碰到过这个问题,好像是下拉框是Disable属性时有问题吧,你可以用GetWindowText, GetCurSel,GetCheck等函数试试看出不出错
      

  3.   

    这是调试断言指令ASSERT,它只在debug时有警告
      

  4.   

    程序是一个基于Dialog的MFC程序,用向导建的,拖了一个BTN控件,BTN控件响应函数起动一个新线程。而
    hwnd->UpdateData(true);
    语句正是处于这个线程函数这中部分代码如下:void Cmfc_testDlg::OnBnClickedButton1()//btn控件响应函数
    {
    DWORD dwTh1;
    CreateThread(NULL,0,&start_send1,this,DEBUG_PROCESS,&dwTh1);//传递this指针

    DWORD WINAPI start_send1(
      LPVOID lpParameter   // thread data
    )
    {
    Cmfc_testDlg *hwnd = (Cmfc_testDlg *)lpParameter;//接收this指针并转换
            //.......其他代码
            hwnd->UpdateData(true);//这里出错
      

  5.   

    看一下你机器上WINCORE.CPP文件的第900行是什么语句
      

  6.   

    想必线程函数一定是静态函数,在静态函数中调用UI的成员函数不妥,何不发送消息给UI,于消息处理函数中UpdateData?
      

  7.   

    照理说应该是没问题的呀,因为release运行没问题呀
    我想弄明白为什么这样不行以下是调试运行时出错部份的代码,位于wincore.cpp当中:void CWnd::AssertValid() const
    {
    if (m_hWnd == NULL)
    return;     // null (unattached) windows are valid // check for special wnd??? values
    ASSERT(HWND_TOP == NULL);       // same as desktop
    if (m_hWnd == HWND_BOTTOM)
    ASSERT(this == &CWnd::wndBottom);
    else if (m_hWnd == HWND_TOPMOST)
    ASSERT(this == &CWnd::wndTopMost);
    else if (m_hWnd == HWND_NOTOPMOST)
    ASSERT(this == &CWnd::wndNoTopMost);
    else
    {
    // should be a normal window
    ASSERT(::IsWindow(m_hWnd)); // should also be in the permanent or temporary handle map
    CHandleMap* pMap = afxMapHWND();
    ASSERT(pMap != NULL);  //这里是第900行 CObject* p=NULL;
    if(pMap)
    {
    ASSERT( (p = pMap->LookupPermanent(m_hWnd)) != NULL ||
    (p = pMap->LookupTemporary(m_hWnd)) != NULL);
    }
    ASSERT((CWnd*)p == this);   // must be us // Note: if either of the above asserts fire and you are
    // writing a multithreaded application, it is likely that
    // you have passed a C++ object from one thread to another
    // and have used that object in a way that was not intended.
    // (only simple inline wrapper functions should be used)
    //
    // In general, CWnd objects should be passed by HWND from
    // one thread to another.  The receiving thread can wrap
    // the HWND with a CWnd object by using CWnd::FromHandle.
    //
    // It is dangerous to pass C++ objects from one thread to
    // another, unless the objects are designed to be used in
    // such a manner.
    }
    }
      

  8.   


    ASSERT(pMap != NULL);  //这里是第900行
      

  9.   

    不可以在你创建的线程中对主线程(也就是你的对话框)资源进行操作。UpdateData(TRUE)是从界面上的取数据。在release上没有问题,并不是就没有问题,只是你的测试实例不够,如果测试足够严格的话,会出现异常的,建议在自己的线程中::PostMessage(hwnd->GetsafeHwnd(),...)。防止主线程与自己的线程同时操作对话框资源所引起的混乱。