void CNetscapeCntrItem::OnActivate() { char * pSource = NULL; const char* ptr; LPDISPATCH pdisp; HRESULT hr; int _convert; if (m_lpObject->QueryInterface(IID_IDispatch, (void**)&pdisp) == S_OK){ #ifdef XP_WIN32 LPCOLESTR lpOleStr = T2COLE("SaveAs"); hr = pdisp->GetIDsOfNames(IID_NULL, (unsigned short **)&lpOleStr, 1, LOCALE_USER_DEFAULT, &m_idSavedAs); pdisp->Release(); if (hr == S_OK) m_bCanSavedByOLE = TRUE; else m_idSavedAs = DISPID_UNKNOWN; #else m_idSavedAs = DISPID_UNKNOWN; #endif } const char* ptr1 = m_csAddress; if (NET_IsLocalFileURL((char*)ptr1)) { XP_ConvertUrlToLocalFile(m_csAddress, &pSource); m_csDosName = *pSource; // pick up the drive name. m_csDosName += ":"; m_csDosName += strchr(pSource, '\\'); // pick up the real file name. ptr = m_csDosName; FE_ConvertSpace((char*)ptr); XP_FREE(pSource); } // the object does not support ole automation, try to find out if this is a storagefile, so // we can use OLESave(). if (!m_bCanSavedByOLE) { #ifdef XP_WIN32 // we will only want to handle saving when the object had storage file. int _convert; LPCOLESTR lpsz = A2CW(m_csDosName); if (StgIsStorageFile(lpsz) == S_OK) m_bCanSavedByOLE = TRUE; #else HRESULT sc1 = StgIsStorageFile(m_csDosName); if (GetScode(sc1) == S_OK) m_bCanSavedByOLE = TRUE; #endif } CGenericView* pView = GetActiveView(); CFrameGlue *pFrameGlue = pView->GetFrame(); if(pFrameGlue != NULL) { m_bLocationBarShowing = pFrameGlue->GetChrome()->GetToolbarVisible(ID_LOCATION_TOOLBAR); } COleClientItem::OnActivate(); }
int PolylineTest::readCompundFile() { assert(StgIsStorageFile(kFileName) == S_OK); ComPtr<IStorage> pStorage; ComPtr<IStream> pStream; auto hr = StgOpenStorageEx(kFileName, STGM_READ | STGM_SHARE_EXCLUSIVE | STGM_DIRECT, STGFMT_STORAGE, 0, NULL, 0, IID_IStorage, (void**)&pStorage); if (FAILED(hr)) return hr; hr = pStorage->OpenStream(kStreamName, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream); if (FAILED(hr)) return hr; ULARGE_INTEGER ui; ui.QuadPart = 10; pStream->SetSize(ui); int keke[6]; ULONG cb; hr = pStream->Read(keke, sizeof(int) * _countof(keke), &cb); if (FAILED(hr)) return hr; for (int i = 0; i < _countof(kData); i++) { assert(keke[i] == kData[i]); } return 0; }
HRESULT CDShowCtrl::LoadGraphFile(IGraphBuilder *pGraph, const WCHAR* wszName) { IStorage *pStorage = 0; if (S_OK != StgIsStorageFile(wszName)) { return E_FAIL; } HRESULT hr = StgOpenStorage(wszName, 0, STGM_TRANSACTED | STGM_READ | STGM_SHARE_DENY_WRITE, 0, 0, &pStorage); if (FAILED(hr)) { return hr; } IPersistStream *pPersistStream = 0; hr = pGraph->QueryInterface(IID_IPersistStream, reinterpret_cast<void**>(&pPersistStream)); if (SUCCEEDED(hr)) { IStream *pStream = 0; hr = pStorage->OpenStream(L"ActiveMovieGraph", 0, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream); if(SUCCEEDED(hr)) { hr = pPersistStream->Load(pStream); pStream->Release(); } pPersistStream->Release(); } pStorage->Release(); return hr; }
/****************************************************************************** * FileMoniker_BindToStorage */ static HRESULT WINAPI FileMonikerImpl_BindToStorage(IMoniker* iface, IBindCtx* pbc, IMoniker* pmkToLeft, REFIID riid, VOID** ppvObject) { LPOLESTR filePath=0; IStorage *pstg=0; HRESULT res; TRACE("(%p,%p,%p,%s,%p)\n",iface,pbc,pmkToLeft,debugstr_guid(riid),ppvObject); if (pmkToLeft==NULL){ if (IsEqualIID(&IID_IStorage, riid)){ /* get the file name */ IMoniker_GetDisplayName(iface,pbc,pmkToLeft,&filePath); /* verify if the file contains a storage object */ res=StgIsStorageFile(filePath); if(res==S_OK){ res=StgOpenStorage(filePath,NULL,STGM_READWRITE|STGM_SHARE_DENY_WRITE,NULL,0,&pstg); if (SUCCEEDED(res)){ *ppvObject=pstg; IStorage_AddRef(pstg); return res; } } CoTaskMemFree(filePath); } else if ( (IsEqualIID(&IID_IStream, riid)) || (IsEqualIID(&IID_ILockBytes, riid)) ) return E_FAIL; else return E_NOINTERFACE; } else { FIXME("(%p,%p,%p,%s,%p)\n",iface,pbc,pmkToLeft,debugstr_guid(riid),ppvObject); return E_NOTIMPL; } return res; }
// @pymethod int|pythoncom|StgIsStorageFile|Indicates whether a particular disk file contains a storage object. PyObject *pythoncom_StgIsStorageFile(PyObject *self, PyObject *args) { PyObject *obName; if (!PyArg_ParseTuple(args, "O:StgIsStorageFile", &obName)) // @pyparm string|name||The path to the file to check. return NULL; PyWin_AutoFreeBstr bstrName; if ( !PyWinObject_AsAutoFreeBstr(obName, &bstrName) ) return NULL; PY_INTERFACE_PRECALL; HRESULT hr = StgIsStorageFile(bstrName); PY_INTERFACE_POSTCALL; if (FAILED(hr)) return PyCom_BuildPyException(hr); // @rdesc The return value is 1 if a storage file, else 0. This // method will also raise com_error if the StgIsStorageFile function // returns a failure HRESULT. return PyInt_FromLong(hr==0); }
int E_Routines::ccom_is_compound_file (WCHAR * pwcsName) // Indicates whether a particular disk file contains a storage object. // - pwcsName points to the name of the disk file to be examined, // passed uninterpreted to the underlying file system. { HRESULT hr; int result; hr = StgIsStorageFile (pwcsName); if (hr == S_OK) result = 1; else if (hr == S_FALSE) result = 0; else { //Formatter f; result = 0; com_eraise (f.c_format_message (hr), EN_COM); } return result; };
BOOL COleDocument::OnOpenDocument(LPCTSTR lpszPathName) { ASSERT(lpszPathName == NULL || AfxIsValidString(lpszPathName)); // just use default implementation if 'docfile' not enabled if (!m_bCompoundFile && m_lpRootStg == NULL) { ASSERT(lpszPathName != NULL); return CDocument::OnOpenDocument(lpszPathName); } if (IsModified()) TRACE(traceOle, 0, "Warning: OnOpenDocument replaces an unsaved document.\n"); // abort changes to current docfile if (lpszPathName != NULL) { DeleteContents(); RELEASE(m_lpRootStg); } SetModifiedFlag(); // dirty during de-serialize BOOL bResult = FALSE; TRY { if (m_lpRootStg == NULL) { const CStringW strPathName(lpszPathName); LPCOLESTR lpsz = lpszPathName ? strPathName.GetString() : NULL; // use STGM_CONVERT if necessary SCODE sc; LPSTORAGE lpStorage = NULL; if (StgIsStorageFile(lpsz) == S_FALSE) { // convert existing storage file sc = StgCreateDocfile(lpsz, STGM_READWRITE| STGM_TRANSACTED|STGM_SHARE_DENY_WRITE|STGM_CONVERT, 0, &lpStorage); } else { // open new storage file sc = StgOpenStorage(lpsz, NULL, STGM_READWRITE|STGM_TRANSACTED|STGM_SHARE_DENY_WRITE, 0, 0, &lpStorage); if (FAILED(sc) || lpStorage == NULL) sc = StgOpenStorage(lpsz, NULL, STGM_READ|STGM_TRANSACTED, 0, 0, &lpStorage); } if (FAILED(sc)) AfxThrowOleException(sc); ASSERT(lpStorage != NULL); m_lpRootStg = lpStorage; } // use helper to read document from storage LoadFromStorage(); SetModifiedFlag(FALSE); // start off with unmodified bResult = TRUE; } CATCH_ALL(e) { DeleteContents(); // removed failed contents RELEASE(m_lpRootStg); // if not file-based load, return exceptions to the caller if (lpszPathName == NULL) { THROW_LAST(); } TRY { ReportSaveLoadException(lpszPathName, e, FALSE, AFX_IDP_FAILED_TO_OPEN_DOC); } END_TRY DELETE_EXCEPTION(e); } END_CATCH_ALL return bResult; }
HRESULT CLibObject::openAr( const TCHAR* pszArchive, bool bWrite, BSTR* psErrorDescr ) { USES_CONVERSION; FC_ARSTAT ret; HRESULT hr; TCHAR szVerFound[FC_AR_MAX_VER]; assert(!m_pRoot); *psErrorDescr = NULL; hr = S_OK; ret = m_ar.open(pszArchive, bWrite, szVerFound); //special error handling on open: if(ret == FC_AR_BADMAGIC) { FC_CString jot(MAX_PATH); HMODULE hmod = _Module.GetResourceInstance(); if(*szVerFound) { FC_CString szFound; const TCHAR* pszExpect; pszExpect = szFound.appendUpTo(szVerFound, _T(",")); jot.fmtMsg2(CL_E_VERSION_BINARY, hmod, pszExpect, szFound); } else if(StgIsStorageFile(T2OLE(pszArchive))==S_OK) { jot.fmtMsg(CL_E_VERSION_V1X, hmod); } else { jot.fmtMsg(CL_E_READ_MAGIC, hmod); } *psErrorDescr = jot.toBSTR(); hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); } else if(ret != FC_AR_OK) { //all other errors (should be only IO errors): hr = onArError(ret, psErrorDescr); } else if(*szVerFound && _tcscmp(CL_4CL_VERSION, szVerFound)) { FC_CString jot(MAX_PATH); HMODULE hmod = _Module.GetResourceInstance(); //4CL internal version, independet of archive binary format: jot.fmtMsg2(CL_E_VERSION_4CL, hmod, CL_4CL_VERSION, szVerFound); *psErrorDescr = jot.toBSTR(); hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); //close it: m_ar.close(false, NULL); } //else: version ok. if(hr == S_OK) { assert(*szVerFound || bWrite);//<-must be new archive m_pRoot = m_ar.getRoot(); assert(m_pRoot); } return hr; }