BUG: Assertion Failed When Opening a Second ActiveX Document (195033)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q195033 SYMPTOMS
When opening a second ActiveX document from an AppWizard-generated Active
Document Container, you get an assertion failed in Olecli2.cpp line 104
(Visual C++ 6.0) or line 112 (Visual C++ 5.0):
BOOL COleFrameHook::OnDocActivate(BOOL bActive)
{
...
COleFrameHook* pNotifyHook = m_pActiveItem->m_pInPlaceFrame;
...
// Unhook top-level frame if not needed.
if (pNotifyHook != this)
{
// Shouldn't be removing some other hook.
ASSERT(pNotifyHook->m_pFrameWnd->m_pNotifyHook == pNotifyHook);
pNotifyHook->m_pFrameWnd->m_pNotifyHook = NULL;
}
...
}
CAUSE
This problem occurs because AppWizard generates code to activate the Active
document object from OnInitialUpdate [through DoVerb(OLEIVERB_SHOW)]. For
many Active Document servers (or DocObject servers), this may be too early
when considering that WM_INITIALUPDATE is posted to the view of the second
document before WM_MDIACTIVATE is posted to the frame window of the first
document.
RESOLUTION
Move the code in OnInitialUpdate() to OnMDIActivate() to make the
appropriate modifications. The code should be called only once (during
activation) for each Active document and it should be called before calling
the base class OnMDIActivate():
// CMyView is a CView-derived class.
void CMyView::OnInitialUpdate()
{
CView::OnInitialUpdate();
m_pSelection = NULL; // Initialize selection.
}
// CChildFrame is a CMDIChildWnd-derived class.
CChildFrame::CChildFrame()
{
// TODO: add member initialization code here.
m_bFirstTime = TRUE; // Add data member m_bFirstTime of BOOL type.
}
// Use ClassWizard to add this WM_MDIACTIVATE message handler to
// the CMDIChildWnd-derived class.
void CChildFrame::OnMDIActivate(
BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
{
if (m_bFirstTime && bActivate)
{
CView* pView = GetActiveView();
ASSERT_VALID(pView);
//Active documents should always be activated.
COleDocument* pDoc = (COleDocument*) pView->GetDocument();;
if (pDoc != NULL)
{
// Activate the first one...
POSITION posItem = pDoc->GetStartPosition();
if (posItem != NULL)
{
CDocItem* pItem = pDoc->GetNextItem(posItem);
// only if it's an Active document.
COleDocObjectItem *pDocObjectItem =
DYNAMIC_DOWNCAST(COleDocObjectItem, pItem);
if (pDocObjectItem != NULL)
{
pDocObjectItem->DoVerb(OLEIVERB_SHOW, pView);
}
}
}
m_bFirstTime = FALSE;
}
CMDIChildWnd::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd);
}
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article.
Modification Type: | Major | Last Reviewed: | 12/2/2003 |
---|
Keywords: | kbActiveDocs kbBug kbContainer KB195033 |
---|
|