LPMONIKER COleServerItem::GetMoniker(OLEGETMONIKER nAssign) { // get IOleObject interface for this item LPOLEOBJECT lpOleObject = GetOleObject(); ASSERT(lpOleObject != NULL); // get moniker from OLE object LPMONIKER lpMoniker = NULL; lpOleObject->GetMoniker(nAssign, OLEWHICHMK_OBJFULL, &lpMoniker); return lpMoniker; }
BOOL COleServerItem::GetLinkSourceData(LPSTGMEDIUM lpStgMedium) { ASSERT_VALID(this); ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM))); LPOLEOBJECT lpOleObject = GetOleObject(); ASSERT(lpOleObject != NULL); // get moniker from ole object LPMONIKER lpMoniker; SCODE sc = lpOleObject->GetMoniker(OLEGETMONIKER_TEMPFORUSER, OLEWHICHMK_OBJFULL, &lpMoniker); if (sc != S_OK) { TRACE0("Warning: unable to get moniker for object.\n"); return FALSE; } ASSERT(lpMoniker != NULL); // create a memory based stream to write the moniker to LPSTREAM lpStream; if (::CreateStreamOnHGlobal(NULL, TRUE, &lpStream) != S_OK) { lpMoniker->Release(); AfxThrowMemoryException(); } ASSERT(lpStream != NULL); // write the moniker to the stream, and add it to the clipboard sc = ::OleSaveToStream(lpMoniker, lpStream); lpMoniker->Release(); if (sc != S_OK) { lpStream->Release(); AfxThrowOleException(sc); } // write the class ID of the document to the stream as well COleLinkingDoc* pDoc = GetDocument(); ASSERT(pDoc->m_pFactory != NULL); sc = WriteClassStm(lpStream, pDoc->m_pFactory->GetClassID()); if (sc != S_OK) { lpStream->Release(); AfxThrowOleException(sc); } // setup the STGMEDIUM lpStgMedium->tymed = TYMED_ISTREAM; lpStgMedium->pstm = lpStream; lpStgMedium->pUnkForRelease = NULL; return TRUE; }
HGLOBAL AFXAPI _AfxOleGetObjectDescriptorData( LPOLEOBJECT lpOleObj, LPCOLESTR lpszSrcOfCopy, DWORD dwDrawAspect, POINTL pointl, LPSIZEL lpSizelHim) { USES_CONVERSION; CLSID clsid; LPOLESTR lpszFullUserTypeName = NULL; LPMONIKER lpSrcMonikerOfCopy = NULL; HGLOBAL hObjDesc = NULL; IBindCtx *pbc = NULL; SCODE sc; SIZEL sizelHim; BOOL bFreeSrcOfCopy = FALSE; LPVIEWOBJECT2 lpViewObj2; LPOLELINK lpOleLink; BOOL fIsLink; TCHAR szLinkedTypeFmt[80]; LPCOLESTR lpszLinkedTypeFmt; LPOLESTR lpszBuf = NULL; DWORD dwStatus = 0; // query for IOleLink lpOleLink = QUERYINTERFACE(lpOleObj, IOleLink); fIsLink = lpOleLink != NULL; // query for IViewObject2 lpViewObj2 = QUERYINTERFACE(lpOleObj, IViewObject2); // Get CLSID sc = lpOleObj->GetUserClassID(&clsid); if (sc != S_OK) clsid = CLSID_NULL; // Get FullUserTypeName sc = lpOleObj->GetUserType(USERCLASSTYPE_FULL, &lpszFullUserTypeName); // if object is a link, then expand usertypename to be "Linked %s" if (fIsLink && lpszFullUserTypeName != NULL) { // Note: If this LoadString call fails, it is likely that // _AFX_NO_OLE_RESOURCES is defined in your .RC file. // To correct the situation remove the following line from your // resource script: // #define _AFX_NO_OLE_RESOURCES // This should be done using the Resource.Set Includes... command. VERIFY(AfxLoadString(AFX_IDS_PASTELINKEDTYPE, szLinkedTypeFmt)); lpszLinkedTypeFmt = T2COLE(szLinkedTypeFmt); lpszBuf = (LPOLESTR)CoTaskMemAlloc((ocslen(lpszFullUserTypeName) + ocslen(lpszLinkedTypeFmt) + 1) * sizeof(OLECHAR)); if (lpszBuf != NULL) { #ifdef OLE2ANSI sprintf(lpszBuf, lpszLinkedTypeFmt, lpszFullUserTypeName); #else swprintf(lpszBuf, lpszLinkedTypeFmt, lpszFullUserTypeName); #endif CoTaskMemFree(lpszFullUserTypeName); lpszFullUserTypeName = lpszBuf; } } // get source of copy if (fIsLink) { sc = lpOleLink->GetSourceDisplayName((LPOLESTR*)&lpszSrcOfCopy); bFreeSrcOfCopy = TRUE; } else if (lpszSrcOfCopy == NULL) { sc = lpOleObj->GetMoniker( OLEGETMONIKER_TEMPFORUSER, OLEWHICHMK_OBJFULL, &lpSrcMonikerOfCopy); if (sc == S_OK) { CreateBindCtx(0, &pbc); lpSrcMonikerOfCopy->GetDisplayName(pbc, NULL, (LPOLESTR*)&lpszSrcOfCopy); RELEASE(pbc); bFreeSrcOfCopy = TRUE; } } if (lpSizelHim) { // Use extents passed by the caller sizelHim = *lpSizelHim; } else if (lpViewObj2) { // Get the current extents from the object sc = lpViewObj2->GetExtent(dwDrawAspect, -1, NULL, (LPSIZEL)&sizelHim); if (sc != S_OK) sizelHim.cx = sizelHim.cy = 0; } else { sizelHim.cx = sizelHim.cy = 0; } // Get dwStatus sc = lpOleObj->GetMiscStatus(dwDrawAspect, &dwStatus); if (sc != S_OK) dwStatus = 0; // Get OBJECTDESCRIPTOR hObjDesc = _AfxOleGetObjectDescriptorData(clsid, dwDrawAspect, sizelHim, pointl, dwStatus, lpszFullUserTypeName, lpszSrcOfCopy); // Clean up CoTaskMemFree(lpszFullUserTypeName); if (bFreeSrcOfCopy) CoTaskMemFree((LPOLESTR)lpszSrcOfCopy); RELEASE(lpSrcMonikerOfCopy); RELEASE(lpOleLink); RELEASE(lpViewObj2); return hObjDesc; }