// @pymethod |pythoncom|WriteClassStm|Writes a CLSID to a stream. PyObject *pythoncom_WriteClassStm(PyObject *self, PyObject *args) { PyObject *obStm; PyObject *obCLSID; if (!PyArg_ParseTuple(args, "OO:WriteClassStm", &obStm, // @pyparm <o PyIStream>|Stm||An IStream interface &obCLSID)) // @pyparm <o PyIID>|clsid||The IID to write return NULL; CLSID clsid; if (!PyWinObject_AsIID(obCLSID, &clsid)) return NULL; IStream *pStm; if (!PyCom_InterfaceFromPyObject(obStm, IID_IStream, (void **)&pStm, FALSE)) return NULL; PY_INTERFACE_PRECALL; HRESULT hr = WriteClassStm(pStm, clsid); pStm->Release(); PY_INTERFACE_POSTCALL; if (FAILED(hr)) return PyCom_BuildPyException(hr); Py_INCREF(Py_None); return Py_None; }
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; }