Article ID: 192853
Article Last Modified on 11/21/2006
Program: e:\test\app.exe File: wincore.cpp Line: 879
STDMETHODIMP CTest::TestMethod()
{
AFX_MANAGE_STATE(afxGetStaticModuleState())
CDatabase db;
db.OpenEx("DSN=LocalServer;Database=pubs;UID=<username>;PWD=<strong password>;");
db.Close();
return S_OK;
}
the assertion dialog appears.
if (pFrame != NULL)
ASSERT_VALID(pFrame);
This assertion is not correct. This assertion assumes that there is a
handle map and that the pFrame CWnd * is in either the temporary or permanent
CWnd handle map. Neither of these situations is true in the scenario described
in the Symptoms section.
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=<username>;PWD=<strong password>;");
db.Close();
return S_OK;
}
If you need to add this code in many places, you may want to write a
macro such as the following:
#ifdef _DEBUG
#define ASSERT_FIX() CTempRoutingFrame tmp;
#else
#define ASSERT_FIX()
#endif
So you can do the following:
STDMETHODIMP CsrvTest2::Test()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
ASSERT_FIX()
...
}
Keywords: kbqfe kbbug kbdatabase kbfix kbnoupdate KB192853