FIX: Assertion with an Insertable OLE Control
ID: Q177641
|
The information in this article applies to:
-
Microsoft Visual C++, 32-bit Editions, version 4.0
SYMPTOMS
If you try to handle a WM_LBUTTONDOWN message to get access to the
IOleContainer interface for an insertable OLE Control, the following
Assertion Error occurs:
Debug Assertion Failed!
Program: ...
File: wincore.cpp
Line: 871
CAUSE
This problem is cause by COleClientItem::XOleClientSite::GetContainer not
pushing the container's module state. As a result, the container attempts
to assert that the container's view window is present in the control
module's HWND map.
RESOLUTION
To correct this problem, include the following in the call to
COleClientItem::XOleClientSite::GetContainer function:
STDMETHODIMP COleClientItem::XOleClientSite::GetContainer
(LPOLECONTAINER **ppContainer)
{
#ifdef _DEBUG
METHOD_PROLOGUE_EX(COleClientItem, OleClientSite)
#else
METHOD_PROLOGUE_EX_(COleClientItem, OleClientSite)
#endif
}
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. This bug was corrected in Visual C++, 32-
bit Edition version 4.1.
MORE INFORMATION
The assertion error is caused by the following sequence:
- GetContainer calls GetDocument on the client item.
- The client item asserts that it is valid.
- The client item's AssertValid asserts that its document is valid.
- The document's AssertValid asserts that its view is valid.
- The view's AssertValid asserts that the window is valid.
- The window asserts that its HWND is in the current module's HWND map.
Steps To Reproduce the Problem
- Create a Control using the ControlWizard in Visual C++ 4.0. Make sure
you set the "Available in InsertObject Dialog" option.
- To this control, add a WM_LBUTTONDOWN handler as follows:
void CYourCtrl::OnLButtonDown(UINT nFlags, Cpoint point)
{
LPOLECONTAINER pContainer;
if(SUCCEEDED(GetClientSite()->GetContainer(&pContainer)))
{
AfxMessageBox("We have access to IOleContainer interface");
}
if(pContainer)pContainer->Release();
COleControl::OnLButtonDown(nFlags,point);
}
- Build the control.
- Create a default MFC OLE Container application.
- Build and run the container.
- Click InsertObject on the Edit menu to insert your OLE Control.
- Click on the control. The assertion error occurs.
Additional query words:
4.10
Keywords : kbole kbMFC kbVC
Version : WINNT:4.0
Platform : winnt
Issue type : kbbug