| BUG: Wincore.cpp Line 879 Assert When Using MFC ClassesID: Q192853 
 | 
When you use MFC, the following assert can occur:
Program: e:\test\app.exe File: wincore.cpp Line: 879The following example calls CDatabase::OpenEx() from inside an MFC regular DLL and shows the resulting assert. The problem is not limited to the MFC Database classes.
   STDMETHODIMP CTest::TestMethod()
   {
      AFX_MANAGE_STATE(afxGetStaticModuleState())
      CDatabase db;
      db.OpenEx("DSN=LocalServer;Database=pubs;UID=sa;PWD=;");
      db.Close();
      return S_OK;
   } Code has been added to the GetSafeOwner_() call that calls GetRoutingFrame_(). In the GetRoutingFrame_() function, you can see the following code:
   if (pFrame != NULL)
      ASSERT_VALID(pFrame); To get rid of the failed asserts, you can add the following code to debug builds:
   class CTempRoutingFrame
   {
      CFrameWnd* m_pFrame ;
      public:
        CTempRoutingFrame(CFrameWnd * pWnd= NULL)
        {
          // Save current value.
          m_pFrame = AfxGetThreadState()->m_pRoutingFrame;
          // Set to value passed in. NULL by default.
          AfxGetThreadState()->m_pRoutingFrame = pWnd;
        }
        ~CTempRoutingFrame()
        {
          // Restore m_pRoutingFrame to original value.
          AfxGetThreadState()->m_pRoutingFrame = m_pFrame;
        }
   };
   STDMETHODIMP CsrvTest2::Test()
   {
      AFX_MANAGE_STATE(AfxGetStaticModuleState())
      #ifdef _DEBUG
        CTempRoutingFrame tmp;
      #endif
      CDatabase db;
      db.OpenEx("DSN=LocalServer;Database=pubs;UID=sa;PWD=;");
      db.Close();
      return S_OK;
   } 
   #ifdef _DEBUG
      #define ASSERT_FIX() CTempRoutingFrame tmp;
   #else
      #define ASSERT_FIX()
   #endif 
   STDMETHODIMP CsrvTest2::Test()
   {
      AFX_MANAGE_STATE(AfxGetStaticModuleState())
      ASSERT_FIX()
      ...
   } Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
Keywords          : kbDatabase kbMFC kbVC600bug 
Version           : WINNT:
Platform          : winnt 
Issue type        : kbbug Last Reviewed: July 15, 1999