SOS,有没有遇到类似的情况
在VS2010上开发一款MFC单文档应用程序(VS默认最完整的界面方式),频繁刷新和激活应用程序,一段时间后,就出现异常中断(DEBUG模式),概率性的事件,实在搞不清楚是什么情况,难不成是MFC的本身的BUG,不然我找不出我的代码的异常?!!
下面是异常的调用堆栈:  msvcr100d.dll!_CrtDbgBreak()  行 85 C
  msvcr100d.dll!_VCrtDbgReportA(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, char * arglist)  行 287 C
  msvcr100d.dll!_CrtDbgReportV(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, char * arglist)  行 241 + 0x1d 字节 C
  msvcr100d.dll!_CrtDbgReport(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, ...)  行 258 + 0x1d 字节 C
  mfc100d.dll!AfxAssertFailedLine(const char * lpszFileName, int nLine)  行 25 + 0x14 字节 C++
  mfc100d.dll!CDC::SelectObject(CBitmap * pBitmap)  行 368 + 0x21 字节 C++
  mfc100d.dll!CMFCVisualManagerOffice2007::DrawNcCaption(CDC * pDC, CRect rectCaption, unsigned long dwStyle, unsigned long dwStyleEx, const ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > > & strTitle, const ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > > & strDocument, HICON__ * hIcon, int bPrefix, int bActive, int bTextCenter, const CObList & lstSysButtons)  行 2071 + 0xc 字节 C++
  mfc100d.dll!CMFCVisualManagerOffice2007::OnNcPaint(CWnd * pWnd, const CObList & lstSysButtons, CRect rectRedraw)  行 2342 C++
  mfc100d.dll!CFrameImpl::OnNcPaint()  行 1554 C++
  mfc100d.dll!CFrameWndEx::OnNcPaint()  行 1033 + 0xe 字节 C++
  mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult)  行 2354 C++
  mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam)  行 2067 + 0x20 字节 C++
  mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  行 248 + 0x1c 字节 C++
  mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  行 411 C++
  mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  行 420 + 0x15 字节 C++
  user32.dll!77d18734() 
  [下面的框架可能不正确和/或缺失,没有为 user32.dll 加载符号]
  user32.dll!77d2bdf1() 
  user32.dll!77d3ada0() 
  user32.dll!77d18734() 
  user32.dll!77d2413c() 
  user32.dll!77d23b30() 
  user32.dll!77d3e577() 
  mfc100d.dll!CThreadSlotData::GetThreadValue(int nSlot)  行 266 C++
  00000110()
  user32.dll!77d18734() 
  user32.dll!77d3e577() 
  user32.dll!77d3e577() 
  user32.dll!77d3a2bc() 
  ntdll.dll!7c930415() 
  ntdll.dll!7c930365() 
  ntdll.dll!7c937de9() 
  user32.dll!77d50877() 
  user32.dll!77d5082f() 
  msvcr100d.dll!__crtMessageBoxA(const char * lpText, const char * lpCaption, unsigned int uType)  行 158 + 0x13 字节 C
  msvcr100d.dll!__crtMessageWindowA(int nRptType, const char * szFile, const char * szLine, const char * szModule, const char * szUserMessage)  行 363 + 0x16 字节 C
  msvcr100d.dll!_VCrtDbgReportA(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, char * arglist)  行 417 + 0x28 字节 C
  msvcr100d.dll!_CrtDbgReportV(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, char * arglist)  行 241 + 0x1d 字节 C
  msvcr100d.dll!_CrtDbgReport(int nRptType, const char * szFile, int nLine, const char * szModule, const char * szFormat, ...)  行 258 + 0x1d 字节 C
  mfc100d.dll!AfxAssertFailedLine(const char * lpszFileName, int nLine)  行 25 + 0x14 字节 C++
> mfc100d.dll!CDC::SelectObject(CBitmap * pBitmap)  行 368 + 0x21 字节 C++
  mfc100d.dll!CMFCVisualManagerOffice2007::DrawNcCaption(CDC * pDC, CRect rectCaption, unsigned long dwStyle, unsigned long dwStyleEx, const ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > > & strTitle, const ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > > & strDocument, HICON__ * hIcon, int bPrefix, int bActive, int bTextCenter, const CObList & lstSysButtons)  行 2071 + 0xc 字节 C++
  mfc100d.dll!CMFCVisualManagerOffice2007::OnNcPaint(CWnd * pWnd, const CObList & lstSysButtons, CRect rectRedraw)  行 2342 C++
  mfc100d.dll!CFrameImpl::OnNcPaint()  行 1554 C++
  mfc100d.dll!CFrameWndEx::OnNcPaint()  行 1033 + 0xe 字节 C++
  mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult)  行 2354 C++
  mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam)  行 2067 + 0x20 字节 C++
  mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  行 248 + 0x1c 字节 C++
  mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  行 411 C++
  mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  行 420 + 0x15 字节 C++
  user32.dll!77d18734() 
  user32.dll!77d2bdf1() 
  user32.dll!77d2f40b() 
  mfc100d.dll!CWnd::SendMessageA(unsigned int message, unsigned int wParam, long lParam)  行 42 + 0x44 字节 C++
  mfc100d.dll!CMFCVisualManagerOffice2007::OnNcActivate(CWnd * pWnd, int bActive)  行 1860 C++
  mfc100d.dll!CFrameImpl::OnNcActivate(int bActive)  行 1727 + 0x26 字节 C++
  mfc100d.dll!CFrameWndEx::OnNcActivate(int bActive)  行 1049 + 0x12 字节 C++
  mfc100d.dll!CWnd::OnWndMsg(unsigned int message, unsigned int wParam, long lParam, long * pResult)  行 2216 + 0xd 字节 C++
  mfc100d.dll!CWnd::WindowProc(unsigned int message, unsigned int wParam, long lParam)  行 2067 + 0x20 字节 C++
  mfc100d.dll!AfxCallWndProc(CWnd * pWnd, HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  行 248 + 0x1c 字节 C++
  mfc100d.dll!AfxWndProc(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  行 411 C++
  mfc100d.dll!AfxWndProcBase(HWND__ * hWnd, unsigned int nMsg, unsigned int wParam, long lParam)  行 420 + 0x15 字节 C++
  user32.dll!77d18734() 
  user32.dll!77d18816() 
  user32.dll!77d28ea0() 
  user32.dll!77d28eec() 
  ntdll.dll!7c92e453() 
  user32.dll!77d191be() 
  user32.dll!77d2776b() 
  mfc100d.dll!AfxInternalPumpMessage()  行 153 + 0x13 字节 C++
  mfc100d.dll!CWinThread::PumpMessage()  行 900 C++
  mfc100d.dll!CWinThread::Run()  行 629 + 0xd 字节 C++
  mfc100d.dll!CWinApp::Run()  行 822 C++
  mfc100d.dll!AfxWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow)  行 47 + 0xd 字节 C++
  MainApp.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow)  行 26 C++
  MainApp.exe!__tmainCRTStartup()  行 547 + 0x2c 字节 C
  MainApp.exe!WinMainCRTStartup()  行 371 C
  kernel32.dll!7c817067() 

解决方案 »

  1.   

    VS的调试输出窗口:
    MainApp.exe 中的 0x7c812aeb 处最可能的异常: Microsoft C++ 异常: 内存位置 0x0013f6fc 处的 CResourceException。
    Warning: Uncaught exception in WindowProc (returning 0).
    Second Chance Assertion Failed: File f:\dd\vctools\vc7libs\ship\atlmfc\include\afxwin1.inl, Line 368
    MainApp.exe 已触发了一个断点
      

  2.   

    资源异常  可能是资源缺失报的错误应该是 CDC::SelectObject(CBitmap * pBitmap) 选中的位图无效看你程序中有没有用到这样的代码另外在资源ID中把没有使用到的ID都删除掉,重新编译下,修改直至编译成功
      

  3.   

    看到了两点:
    >    mfc100d.dll!CDC::SelectObject(CBitmap * pBitmap)  行 368 + 0x21 字节    C++
    这个是位图获得错误,看afxwin1代码文件能看到是断言错误。
    另一个是:
    CMFCVisualManagerOffice2007
    这个类中引用的CDC失败,可能与第一点相关。
      

  4.   

    mfc100d.dll!CMFCVisualManagerOffice2007::DrawNcCaption函数实现的是绘制Office2007风格的标题栏,属于MFC框架重绘的功能。在程序被激活时,MFC内部自动调用函数绘制应用标题栏。
    如此错误我又能奈何?
    有没有遇到相同问题的朋友?
      

  5.   

    mfc100d.dll!CDC::SelectObject(CBitmap * pBitmap)  行 368 + 0x21 字节    C++
    ---------------------
    这里错了?是不是你的代码中有GDI资源泄露?
      

  6.   

    运行一段时间,用任务管理器看下GDI资源是否是有增无减?
      

  7.   

    找到“凶手”了:
    原:HBRUSH XXXXX::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
    if (nCtlColor == CTLCOLOR)
    {
           hbr = (HBRUSH)::GetStockObject(NEW_BRUSH);
    }
    return hbr;
    }
    修改成:HBRUSH XXXXX::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
    if (nCtlColor == CTLCOLOR)
    {
                   if (hbr != NULL)
       ::DeleteObject(hbr);

           hbr = (HBRUSH)::GetStockObject(NEW_BRUSH);
    }
    return hbr;
    }
    究其原因还是自已的错~!!!!!
      

  8.   

    HBRUSH XXXXX::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
        HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);        
        if (nCtlColor == CTLCOLOR)
        {    
               if (hbr != NULL)
                 ::DeleteObject(hbr);

               hbr = (HBRUSH)::GetStockObject(NEW_BRUSH);
        }
        return hbr;
    }