FIX: ASSERT in OLECLI1.CPP When Copying Embedding to Clipboard (152072)
The information in this article applies to:
- Microsoft Visual C++ 2.0
- Microsoft Visual C++ 2.1
- Microsoft Visual C++ 2.2
- Microsoft Visual C++ 4.0
- Microsoft Visual C++ 4.1
- Microsoft Foundation Classes (MFC)
- Microsoft Visual C++ 1.5
- Microsoft Visual C++ 1.51
- Microsoft Visual C++ 1.52
This article was previously published under Q152072 SYMPTOMS
When you attempt to copy an embedding in an in-place active object to the
clipboard, the result is an ASSERT in OLECLI1.CPP. Specifically, the ASSERT
occurs in the COleClientItem::XOleClientSite::GetMoniker() function on the
following line of code:
VERIFY(pThis->m_lpObject->SetMoniker(OLEWHICHMK_OBJREL,
*ppMoniker)==S_OK);
CAUSE
When you copy an embedding to the clipboard, a number of data formats are
placed on the clipboard, including link source information. The link source
information contains a moniker used to locate the document in which the
embedding resides.
When the container assigns a moniker to an embedded object, it will call
the object's IOleObject::SetMoniker() function. The object will then call
the container's IOleClientSite::GetMoniker() function to construct a
composite moniker based on the container's moniker. This is done because
the container may have changed its moniker while the object was not
running.
When the embedded object calls IOleClientSite::GetMoniker() to get the
container's moniker, COleClientItem::XOleClientSite::GetMoniker() ASSERTs
on the aforementioned line of code because pThis->m_bMoniker had not been
set to TRUE when the moniker was assigned during a previous call to
COleClientItem::XOleClientSite::GetMoniker().
The problem is located in the following section of the
COleClientItem::XOleClientSite::GetMoniker() function located in
OLECLI1.CPP:
// notify the object of the assignment
if (dwAssign != OLEGETMONIKER_TEMPFORUSER &&
*ppMoniker != NULL && !pThis->m_bMoniker)
{
VERIFY(pThis->m_lpObject->SetMoniker(
OLEWHICHMK_OBJREL, *ppMoniker) == S_OK);
pThis->m_bMoniker = TRUE;
ASSERT_VALID(pThis->;m_pDocument);
pThis->m_pDocument->SetModifiedFlag();
}
The pThis->m_lpObject->SetMoniker() call results in the object calling
COleClientItem::XOleClientSite::GetMoniker() again. Because pThis-
>m_bMoniker is being set after the pThis->m_lpObject->SetMoniker() call,
the subsequent call to pThis->m_lpObject->SetMoniker() returns with an
error code of E_FAIL, triggering the ASSERT.
RESOLUTION
To work around this problem, you must override the default IOleClientSite
interface implementation in COleClientItem. This can be done by adding an
interface map to the class in your project that is derived from
COleClientItem and setting pThis->m_bMoniker to TRUE before calling pThis-
>m_lpObject->SetMoniker() from your custom GetMoniker() function.
The code below illustrates how to override the COleClientItem-derived
object using the OCLIENT MFC sample application.
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 Edtion version 4.2.
Modification Type: | Major | Last Reviewed: | 12/1/2003 |
---|
Keywords: | kbBug kbClipboard kbfix kbVC500fix KB152072 |
---|
|