Article ID: 152072
Article Last Modified on 12/1/2003
VERIFY(pThis->m_lpObject->SetMoniker(OLEWHICHMK_OBJREL,
*ppMoniker)==S_OK);
// 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.
// Code to be added to CRectItem class definition in RECTITEM.H
class CRectItem : public COleClientItem
{
// ...original declarations in CRectItem class go here...
// Interface Map
BEGIN_INTERFACE_PART(OleClientSite2, IOleClientSite)
STDMETHOD(SaveObject)();
STDMETHOD(GetMoniker)(DWORD, DWORD, LPMONIKER*);
STDMETHOD(GetContainer)(LPOLECONTAINER*);
STDMETHOD(ShowObject)();
STDMETHOD(OnShowWindow)(BOOL);
STDMETHOD(RequestNewObjectLayout)();
END_INTERFACE_PART(OleClientSite2)
DECLARE_INTERFACE_MAP()
};
// XOleClientSite2 functions to be added to RECTITEM.CPP
BEGIN_INTERFACE_MAP(CRectItem, COleClientItem)
INTERFACE_PART(CRectItem, IID_IOleClientSite, OleClientSite2)
END_INTERFACE_MAP()
STDMETHODIMP_(ULONG) CRectItem::XOleClientSite2::AddRef()
{
METHOD_PROLOGUE_EX_(CRectItem, OleClientSite2)
return pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG) CRectItem::XOleClientSite2::Release()
{
METHOD_PROLOGUE_EX_(CRectItem, OleClientSite2)
return pThis->ExternalRelease();
}
STDMETHODIMP CRectItem::XOleClientSite2::QueryInterface(
REFIID iid, LPVOID* ppvObj)
{
METHOD_PROLOGUE_EX_(CRectItem, OleClientSite2)
return pThis->ExternalQueryInterface(&iid, ppvObj);
}
STDMETHODIMP CRectItem::XOleClientSite2::SaveObject()
{
METHOD_PROLOGUE_EX(CRectItem, OleClientSite2)
ASSERT_VALID(pThis);
return pThis->m_xOleClientSite.SaveObject();
}
STDMETHODIMP CRectItem::XOleClientSite2::GetMoniker(
DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER* ppMoniker)
{
METHOD_PROLOGUE_EX(CRectItem, OleClientSite2)
ASSERT_VALID(pThis);
USES_CONVERSION; // note, must #include afxpriv.h
COleDocument* pDoc = pThis->GetDocument();
ASSERT_VALID(pDoc);
ASSERT(ppMoniker != NULL);
*ppMoniker = NULL;
switch (dwWhichMoniker)
{
case OLEWHICHMK_CONTAINER:
// return the current moniker for the document
*ppMoniker = pDoc->GetMoniker((OLEGETMONIKER)dwAssign);
break;
case OLEWHICHMK_OBJREL:
{
if (!pDoc->IsKindOf(RUNTIME_CLASS(COleLinkingDoc)))
break;
// don't return relative moniker if no document moniker
LPMONIKER lpMoniker = pDoc-
>GetMoniker((OLEGETMONIKER)dwAssign);
if (lpMoniker == NULL)
break;
lpMoniker->Release();
// relative monikers have to handle assignment correctly
switch (dwAssign)
{
case OLEGETMONIKER_ONLYIFTHERE:
if (!pThis->m_bMoniker)
break; // no moniker assigned, don't return one
// fall through...
case OLEGETMONIKER_TEMPFORUSER:
case OLEGETMONIKER_FORCEASSIGN:
{
// create item moniker from item name
TCHAR szItemName[OLE_MAXITEMNAME];
pThis->GetItemName(szItemName);
CreateItemMoniker(OLESTDDELIMOLE, T2COLE(szItemName),
ppMoniker);
// notify the object of the assignment
if (dwAssign != OLEGETMONIKER_TEMPFORUSER &&
*ppMoniker != NULL && !pThis->m_bMoniker)
{
pThis->m_bMoniker = TRUE;
VERIFY(pThis->m_lpObject->SetMoniker(
OLEWHICHMK_OBJREL, *ppMoniker) == S_OK);
ASSERT_VALID(pThis->m_pDocument);
pThis->m_pDocument->SetModifiedFlag();
}
}
break;
case OLEGETMONIKER_UNASSIGN:
pThis->m_bMoniker = FALSE;
break;
}
}
break;
case OLEWHICHMK_OBJFULL:
{
// get each sub-moniker: item & document
LPMONIKER lpMoniker1, lpMoniker2;
GetMoniker(dwAssign, OLEWHICHMK_CONTAINER, &lpMoniker1);
GetMoniker(dwAssign, OLEWHICHMK_OBJREL, &lpMoniker2);
// create composite moniker
if (lpMoniker1 != NULL && lpMoniker2 != NULL)
::CreateGenericComposite(lpMoniker1, lpMoniker2,
ppMoniker);
// release sub-monikers
RELEASE(lpMoniker1);
RELEASE(lpMoniker2);
}
break;
}
return *ppMoniker != NULL ? S_OK : E_FAIL;
}
STDMETHODIMP CRectItem::XOleClientSite2::GetContainer(LPOLECONTAINER*
ppContainer)
{
#ifdef _DEBUG
METHOD_PROLOGUE_EX(CRectItem, OleClientSite2)
#else
METHOD_PROLOGUE_EX_(CRectItem, OleClientSite2)
#endif
ASSERT_VALID(pThis);
return pThis->m_xOleClientSite.GetContainer(ppContainer);
}
STDMETHODIMP CRectItem::XOleClientSite2::ShowObject()
{
METHOD_PROLOGUE_EX(CRectItem, OleClientSite2)
ASSERT_VALID(pThis);
return pThis->m_xOleClientSite.ShowObject();
}
STDMETHODIMP CRectItem::XOleClientSite2::OnShowWindow(BOOL fShow)
{
METHOD_PROLOGUE_EX(CRectItem, OleClientSite2)
ASSERT_VALID(pThis);
return pThis->m_xOleClientSite.OnShowWindow(fShow);
}
STDMETHODIMP CRectItem::XOleClientSite2::RequestNewObjectLayout()
{
return E_NOTIMPL;
}
Additional query words: 1.50 1.51 1.52 2.00 2.10 2.20 4.00 4.10 4.20 vcfixlist420 MfcOLE
Keywords: kbbug kbfix kbvc500fix kbclipboard KB152072