BOOL CSummInfo::ReadFromStorage(LPSTORAGE lpRootStg) { if (lpRootStg != NULL) { LPSTREAM lpStream = NULL; if (FAILED(lpRootStg->OpenStream(szSummInfo, NULL, STGM_SHARE_EXCLUSIVE|STGM_READ, 0, &lpStream))) { TRACE(_T("OpenStream failed\n")); return FALSE; } else { if (!m_propSet.ReadFromStream(lpStream)) { TRACE(_T("ReadFromStream failed\n")); return FALSE; } m_pSection = m_propSet.GetSection(FMTID_SummaryInformation); lpStream->Release(); return TRUE; } } return FALSE; }
void ReadStorage(LPSTORAGE pStg) // reads one storage -- recursive calls for substorages { USES_CONVERSION; LPSTORAGE pSubStg = NULL; LPSTREAM pStream = NULL; LPENUMSTATSTG pEnum = NULL; LPMALLOC pMalloc = NULL; // for freeing statstg STATSTG statstg; ULONG nLength; BYTE buffer[101]; g_nIndent++; ::CoGetMalloc(MEMCTX_TASK, &pMalloc); // assumes AfxOleInit // was called VERIFY(pStg->EnumElements(0, NULL, 0, &pEnum) == S_OK); while (pEnum->Next(1, &statstg, NULL) == S_OK) { if (statstg.type == STGTY_STORAGE) { VERIFY(pStg->OpenStorage(statstg.pwcsName, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, NULL, 0, &pSubStg) == S_OK); ASSERT(pSubStg != NULL); TRACE("%0.*sStorage = %s\n", (g_nIndent - 1) * 4, g_szBlanks, OLE2CT(statstg.pwcsName)); ReadStorage(pSubStg); pSubStg->Release(); } else if (statstg.type == STGTY_STREAM) { VERIFY(pStg->OpenStream(statstg.pwcsName, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream) == S_OK); ASSERT(pStream != NULL); TRACE("%0.*sStream = %s\n", (g_nIndent - 1) * 4, g_szBlanks, OLE2CT(statstg.pwcsName)); pStream->Read(buffer, 100, &nLength); buffer[nLength] = '\0'; TRACE("%s\n", buffer); pStream->Release(); } else { ASSERT(FALSE); // LockBytes? } pMalloc->Free(statstg.pwcsName); // avoids memory leaks } pMalloc->Release(); pEnum->Release(); g_nIndent--; }
STDMETHODIMP VLCPersistStorage::Load(LPSTORAGE pStg) { if( NULL == pStg ) return E_INVALIDARG; LPSTREAM pStm = NULL; HRESULT result = pStg->OpenStream(L"VideoLAN ActiveX Plugin Data", NULL, STGM_READ|STGM_SHARE_EXCLUSIVE, 0, &pStm); if( FAILED(result) ) return result; LPPERSISTSTREAMINIT pPersistStreamInit; if( SUCCEEDED(QueryInterface(IID_IPersistStreamInit, (void **)&pPersistStreamInit)) ) { result = pPersistStreamInit->Load(pStm); pPersistStreamInit->Release(); } pStm->Release(); return result; };
BOOL COleControl::SetPropsetData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium, REFCLSID fmtid) { UNUSED(lpFormatEtc); // unused in release builds ASSERT_VALID(this); ASSERT(AfxIsValidAddress(lpFormatEtc, sizeof(FORMATETC), FALSE)); ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM))); // Get the stream that contains the property set. LPSTORAGE lpStorage = NULL; LPSTREAM lpStream = NULL; switch (lpStgMedium->tymed) { case TYMED_ISTORAGE: { lpStorage = lpStgMedium->pstg; ASSERT_POINTER(lpStorage, IStorage); if (FAILED(lpStorage->OpenStream(OLESTR("Contents"), 0, STGM_SHARE_EXCLUSIVE|STGM_READ, 0, &lpStream))) { TRACE0("Failed to open content stream.\n"); return FALSE; } } break; case TYMED_ISTREAM: lpStorage = NULL; lpStream = lpStgMedium->pstm; break; default: TRACE0("Propset only supported for stream or storage.\n"); return FALSE; } ASSERT_POINTER(lpStream, IStream); // Read the property set from the stream. CPropertySet pset; if (!pset.ReadFromStream(lpStream)) { TRACE0("CPropertySet::ReadFromStream failed.\n"); return FALSE; } CPropertySection* ppsec = pset.GetSection(fmtid); if (ppsec == NULL) { TRACE0("CLSID_PersistPropset section not found in property set.\n"); return FALSE; } // Detect whether we're converting a VBX m_bConvertVBX = (BYTE)IsEqualGUID(fmtid, CLSID_ConvertVBX); // Parse the property set. CPropsetPropExchange propx(*ppsec, lpStorage, TRUE); BOOL bPropExchange = FALSE; TRY { DoPropExchange(&propx); bPropExchange = TRUE; } END_TRY // Properties have probably changed BoundPropertyChanged(DISPID_UNKNOWN); InvalidateControl(); m_bConvertVBX = FALSE; // Clear the modified flag. m_bModified = FALSE; // Unless IOleObject::SetClientSite is called after this, we can // count on ambient properties being available while loading. m_bCountOnAmbients = TRUE; // Properties have been initialized m_bInitialized = TRUE; // Cleanup. if (lpStorage != NULL) // If we called OpenStream(), release now. lpStream->Release(); BoundPropertyChanged(DISPID_UNKNOWN); return bPropExchange; }
FARINTERNAL Ut10NativeStmToContentsStm (LPSTORAGE pstg, REFCLSID rclsid, BOOL fDeleteSrcStm) { CLIPFORMAT cfOld; CLIPFORMAT cfNew; LPOLESTR lpszUserType = NULL; HRESULT error; LPSTREAM pstmSrc = NULL; LPSTREAM pstmDst = NULL; if (error = ReadFmtUserTypeStg(pstg, &cfOld, &lpszUserType)) return error; if (rclsid == CLSID_StaticDib) cfNew = CF_DIB; else if (rclsid == CLSID_StaticMetafile) cfNew = CF_METAFILEPICT; else { AssertSz(FALSE, "Internal Error: this routine shouldn't have been called for this class"); return ResultFromScode(E_FAIL); } if (cfOld == g_cfPBrush) { if (cfNew != CF_DIB) { error = ResultFromScode(DV_E_CLIPFORMAT); goto errRtn; } } else if (cfOld == g_cfMSDraw) { if (cfNew != CF_METAFILEPICT) { error = ResultFromScode(DV_E_CLIPFORMAT); goto errRtn; } } else { // Converted to static object from some class other than PBrush or // MSDraw. The data must be in a proper format in the CONTENTS // stream. return NOERROR; } if (error = pstg->OpenStream(OLE10_NATIVE_STREAM, NULL, (STGM_READ|STGM_SHARE_EXCLUSIVE), 0, &pstmSrc)) goto errRtn; if (error = OpenOrCreateStream(pstg, OLE_CONTENTS_STREAM, &pstmDst)) goto errRtn; DWORD dwSize; if (error = pstmSrc->Read(&dwSize, sizeof(DWORD), NULL)) goto errRtn; if (cfOld == g_cfMSDraw) { WORD mfp[3]; // mm, xExt, yExt if (error = pstmSrc->Read(mfp, sizeof(mfp), NULL)) goto errRtn; dwSize -= sizeof(mfp); error = UtMFStmToPlaceableMFStm(pstmSrc, dwSize, (LONG) mfp[1], (LONG) mfp[2], pstmDst); } else { // The PBrush native data format is DIB File format. So all we got to // do is CopyTo. ULARGE_INTEGER ularge_int; ULISet32(ularge_int, dwSize); if ((error = pstmSrc->CopyTo(pstmDst, ularge_int, NULL, NULL)) == NOERROR) StSetSize(pstmDst, 0, TRUE); } errRtn: if (pstmDst) pstmDst->Release(); if (pstmSrc) pstmSrc->Release(); if (error == NOERROR) { error = WriteFmtUserTypeStg(pstg, cfNew, lpszUserType); if (fDeleteSrcStm) pstg->DestroyElement(OLE10_NATIVE_STREAM); } else { pstg->DestroyElement(OLE_CONTENTS_STREAM); } if (lpszUserType) PubMemFree(lpszUserType); return error; }
FARINTERNAL UtContentsStmTo10NativeStm (LPSTORAGE pstg, REFCLSID rclsid, BOOL fDeleteSrcStm, UINT FAR* puiStatus) { CLIPFORMAT cf; LPOLESTR lpszUserType = NULL; HRESULT error; LPSTREAM pstmSrc = NULL; LPSTREAM pstmDst = NULL; *puiStatus = NULL; if (error = ReadFmtUserTypeStg(pstg, &cf, &lpszUserType)) return error; if (! ((cf == CF_DIB && rclsid == CLSID_PBrush) || (cf == CF_METAFILEPICT && rclsid == CLSID_MSDraw))) { error = ResultFromScode(DV_E_CLIPFORMAT); goto errRtn; } if (error = pstg->OpenStream(OLE_CONTENTS_STREAM, NULL, (STGM_READ|STGM_SHARE_EXCLUSIVE), 0, &pstmSrc)) { *puiStatus |= CONVERT_NOSOURCE; // check whether OLE10_NATIVE_STREAM exists if (pstg->OpenStream(OLE10_NATIVE_STREAM, NULL, (STGM_READ|STGM_SHARE_EXCLUSIVE), 0, &pstmDst)) *puiStatus |= CONVERT_NODESTINATION; else { pstmDst->Release(); pstmDst = NULL; } goto errRtn; } if (error = OpenOrCreateStream(pstg, OLE10_NATIVE_STREAM, &pstmDst)) { *puiStatus |= CONVERT_NODESTINATION; goto errRtn; } if (cf == CF_METAFILEPICT) error = UtPlaceableMFStmToMSDrawNativeStm(pstmSrc, pstmDst); else error = UtDIBFileStmToPBrushNativeStm(pstmSrc, pstmDst); errRtn: if (pstmDst) pstmDst->Release(); if (pstmSrc) pstmSrc->Release(); if (error == NOERROR) { LPOLESTR lpszProgId = NULL; ProgIDFromCLSID(rclsid, &lpszProgId); error = WriteFmtUserTypeStg(pstg, RegisterClipboardFormat(lpszProgId), lpszUserType); if (lpszProgId) delete lpszProgId; } if (error == NOERROR) { if (fDeleteSrcStm) pstg->DestroyElement(OLE_CONTENTS_STREAM); } else { pstg->DestroyElement(OLE10_NATIVE_STREAM); } if (lpszUserType) delete lpszUserType; return error; }