bool CMapiMessage::CopyBinAttachToFile(LPATTACH lpAttach, nsIFile **tmp_file) { nsCOMPtr<nsIFile> _tmp_file; nsresult rv = GetSpecialDirectoryWithFileName(NS_OS_TEMP_DIR, "mapiattach.tmp", getter_AddRefs(_tmp_file)); NS_ENSURE_SUCCESS(rv, false); rv = _tmp_file->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 00600); NS_ENSURE_SUCCESS(rv, false); nsCString tmpPath; _tmp_file->GetNativePath(tmpPath); LPSTREAM lpStreamFile; HRESULT hr = CMapiApi::OpenStreamOnFile(gpMapiAllocateBuffer, gpMapiFreeBuffer, STGM_READWRITE | STGM_CREATE, const_cast<char*>(tmpPath.get()), NULL, &lpStreamFile); if (HR_FAILED(hr)) { MAPI_TRACE1("~~ERROR~~ OpenStreamOnFile failed - temp path: %s\r\n", tmpPath.get()); return false; } bool bResult = true; LPSTREAM lpAttachStream; hr = lpAttach->OpenProperty(PR_ATTACH_DATA_BIN, &IID_IStream, 0, 0, (LPUNKNOWN *)&lpAttachStream); if (HR_FAILED(hr)) { MAPI_TRACE0("~~ERROR~~ OpenProperty failed for PR_ATTACH_DATA_BIN.\r\n"); lpAttachStream = NULL; bResult = false; } else { STATSTG st; hr = lpAttachStream->Stat(&st, STATFLAG_NONAME); if (HR_FAILED(hr)) { MAPI_TRACE0("~~ERROR~~ Stat failed for attachment stream\r\n"); bResult = false; } else { hr = lpAttachStream->CopyTo(lpStreamFile, st.cbSize, NULL, NULL); if (HR_FAILED(hr)) { MAPI_TRACE0("~~ERROR~~ Attach Stream CopyTo temp file failed.\r\n"); bResult = false; } } } if (lpAttachStream) lpAttachStream->Release(); lpStreamFile->Release(); if (!bResult) _tmp_file->Remove(false); else CallQueryInterface(_tmp_file, tmp_file); return bResult; }
/*static */ bool display_t::save_bitmap(const char *szFileName, HBITMAP bmp, HPALETTE pal /*= NULL*/) { START_FUNCTION_BOOL(); PICTDESC pdPictDesc; pdPictDesc.cbSizeofstruct = sizeof(PICTDESC); pdPictDesc.picType = PICTYPE_BITMAP; pdPictDesc.bmp.hbitmap = bmp; pdPictDesc.bmp.hpal = pal; LPPICTURE plPicture = NULL; HRESULT hResult = OleCreatePictureIndirect(&pdPictDesc, IID_IPicture, false, reinterpret_cast<void**>(&plPicture)); if (!SUCCEEDED(hResult)) { break; } LPSTREAM lpStream = NULL; hResult = CreateStreamOnHGlobal(0, true, &lpStream); if (!SUCCEEDED(hResult)) { plPicture->Release(); return false; } LONG lBytesStreamed = 0; hResult = plPicture->SaveAsFile(lpStream, true, &lBytesStreamed); HANDLE hFile = CreateFileA(szFileName, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (!SUCCEEDED(hResult) || !hFile) { lpStream->Release(); plPicture->Release(); break; } HGLOBAL hgMemory = 0; GetHGlobalFromStream(lpStream, &hgMemory); LPVOID lpData = GlobalLock(hgMemory); DWORD dwBytesWritten = 0; bool bResult = !!WriteFile(hFile, lpData, lBytesStreamed, &dwBytesWritten, 0); bResult &= (dwBytesWritten == static_cast<DWORD>(lBytesStreamed)); GlobalUnlock(hgMemory); CloseHandle(hFile); lpStream->Release(); plPicture->Release(); END_FUNCTION_BOOL(); }
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; }
static Gdiplus::Image* bkimg(int rcid) { HRSRC hrsc = ::FindResource(hInst, MAKEINTRESOURCE(rcid), TEXT("PNG")); DWORD size = ::SizeofResource(hInst, hrsc); LPVOID hg = ::LoadResource(hInst, hrsc); HGLOBAL mem = ::GlobalAlloc(GMEM_MOVEABLE, size); Gdiplus::Image* img = 0; if (mem) { LPVOID pmem = ::GlobalLock(mem); if (pmem) { ::CopyMemory(pmem, hg, size); LPSTREAM is; if (::CreateStreamOnHGlobal(pmem, FALSE, &is) == S_OK) { Gdiplus::Image* m = new Gdiplus::Image(is); is->Release(); if (m->GetLastStatus() != Gdiplus::Ok) { delete m; return img; } img = m; } ::GlobalUnlock(mem); } ::GlobalFree(mem); } return img; }
LPSTREAM AFXAPI _AfxLoadStreamFromPropset(CPropertySection& psec, LPCTSTR pszPropName, DWORD& vtType) { ASSERT(AfxIsValidString(pszPropName)); vtType = VT_EMPTY; DWORD dwPropID; CProperty* pprop = NULL; LPSTREAM pstm = NULL; if (psec.GetID(pszPropName, &dwPropID) && ((pprop = psec.GetProperty(dwPropID)) != NULL)) { vtType = pprop->GetType(); if ((vtType == VT_BLOB) || (vtType == VT_BLOB_PROPSET)) { pstm = _AfxCreateMemoryStream(); if (pstm != NULL) { if (!_AfxInitStreamDataFromBlobProp(pstm, pprop)) { pstm->Release(); pstm = NULL; } } } } return pstm; }
void CScratchPadDlg::LoadSrcImage() { HINSTANCE hResInstance = AfxGetResourceHandle( ); HRSRC res = FindResource(hResInstance, MAKEINTRESOURCE(IDB_BITMAP1),L"BINARY"); if (res) { HGLOBAL mem = LoadResource(hResInstance, res); void *data = LockResource(mem); size_t len = SizeofResource(hResInstance, res); HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, len); LPVOID pvData = GlobalLock( hGlobal ); memcpy(pvData,data,len); GlobalUnlock(hGlobal); LPSTREAM pStream = NULL; HRESULT hr = CreateStreamOnHGlobal( hGlobal, TRUE, &pStream ); using namespace Gdiplus; m_pSrcBitmap = new Bitmap(pStream,false); pStream->Release(); } }
STDMETHODIMP VLCPersistStorage::Save(LPSTORAGE pStg, BOOL fSameAsLoad) { if( NULL == pStg ) return E_INVALIDARG; if( fSameAsLoad && (S_FALSE == IsDirty()) ) return S_OK; LPSTREAM pStm = NULL; HRESULT result = pStg->CreateStream(L"VideoLAN ActiveX Plugin Data", STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, 0, &pStm); if( FAILED(result) ) return result; LPPERSISTSTREAMINIT pPersistStreamInit; if( SUCCEEDED(QueryInterface(IID_IPersistStreamInit, (void **)&pPersistStreamInit)) ) { result = pPersistStreamInit->Save(pStm, fSameAsLoad); pPersistStreamInit->Release(); } pStm->Release(); return result; };
BOOL CGifImage::LoadFromBuffer(const BYTE* lpBuf, DWORD dwSize) { if (NULL == lpBuf || dwSize <= 0) return FALSE; HGLOBAL hGlobal = ::GlobalAlloc(GHND, dwSize); if (NULL == hGlobal) return FALSE; LPVOID lpBuffer = ::GlobalLock(hGlobal); if (NULL == lpBuffer) { ::GlobalFree(hGlobal); return FALSE; } memcpy(lpBuffer, lpBuf, dwSize); ::GlobalUnlock(hGlobal); LPSTREAM lpStream = NULL; HRESULT hr = ::CreateStreamOnHGlobal(hGlobal, TRUE, &lpStream); if (hr != S_OK) { ::GlobalFree(hGlobal); return FALSE; } BOOL bRet = LoadFromIStream(lpStream); lpStream->Release(); return bRet; }
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; }
BOOL CSummInfo::WriteToStorage(LPSTORAGE lpRootStg) { if (lpRootStg != NULL) { LPSTREAM lpStream = NULL; if (FAILED(lpRootStg->CreateStream(szSummInfo, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, 0, &lpStream))) { TRACE(_T("CreateStream failed\n")); return FALSE; } else { if(!m_propSet.WriteToStream(lpStream)) { TRACE(_T("WriteToStream failed\n")); return FALSE; } lpRootStg->Commit(STGC_DEFAULT); lpStream->Release(); return TRUE; } } return FALSE; }
BOOL FileUpload(Zimbra::Rpc::ZimbraConnection *z_connection, LPWSTR *ppwszToken) { LOGFN_INTERNAL_NO; LPSTR pszTestFile = "E:\\temp\\aa.log"; LPSTREAM pStreamFile = NULL; HRESULT hr = OpenStreamOnFile(MAPIAllocateBuffer, MAPIFreeBuffer, STGM_READ, (LPWSTR)pszTestFile, NULL, &pStreamFile); if (FAILED(hr)) { LOG_ERROR(_T("failed to OpenStreamOnFile call: %x"), hr); return FALSE; } HANDLE hFile = CreateFile(L"E:\\temp\\aa.log", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); DWORD dwFileSize = GetFileSize(hFile, NULL); CloseHandle(hFile); _tprintf(_T(" File Upload size=%d bytes\n"), dwFileSize); BOOL bResult = z_connection->DoFileUpload(pStreamFile, dwFileSize, L"/service/upload?fmt=raw", ppwszToken, NULL); pStreamFile->Release(); return bResult; }
BOOL CImageEx::LoadFromResource(HINSTANCE hInstance, LPCTSTR pszResourceName, LPCTSTR pszResType) { HRSRC hRsrc = ::FindResource(hInstance, pszResourceName, pszResType); if (NULL == hRsrc) return FALSE; DWORD dwSize = ::SizeofResource(hInstance, hRsrc); if (0 == dwSize) return FALSE; HGLOBAL hGlobal = ::LoadResource(hInstance, hRsrc); if (NULL == hGlobal) return FALSE; LPVOID pBuffer = ::LockResource(hGlobal); if (NULL == pBuffer) { ::FreeResource(hGlobal); return FALSE; } HGLOBAL hGlobal2 = ::GlobalAlloc(GHND, dwSize); if (NULL == hGlobal2) { ::FreeResource(hGlobal); return FALSE; } LPVOID pBuffer2 = ::GlobalLock(hGlobal2); if (NULL == pBuffer2) { ::GlobalFree(hGlobal2); ::FreeResource(hGlobal); return FALSE; } memcpy(pBuffer2, pBuffer, dwSize); ::GlobalUnlock(hGlobal2); LPSTREAM pStream = NULL; HRESULT hr = ::CreateStreamOnHGlobal(hGlobal2, TRUE, &pStream); if (hr != S_OK) { ::GlobalFree(hGlobal2); ::FreeResource(hGlobal); return FALSE; } BOOL bRet = LoadFromIStream(pStream); if (pStream) pStream->Release(); ::FreeResource(hGlobal); return bRet; }
///////////////////////////////////////////////////////////////////////////////////////// // Utility to save a bitmap to file for later examination. Used for debugging only. // Based on an article by "gelbert" on www.experts-exchange.com at // http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20193761.html // // This version is a member function and instead of taking an HBITMAP as the 2nd // parameter, it take a reference to a CBitmap. Otherwise, it is identical. ///////////////////////////////////////////////////////////////////////////////////////// BOOL CSliderCtrlEx::SaveBitmap(LPCSTR lpFileName, CBitmap &hBitmap, HPALETTE hPal) { BOOL bResult = FALSE; PICTDESC stPictDesc; stPictDesc.cbSizeofstruct = sizeof(PICTDESC); stPictDesc.picType = PICTYPE_BITMAP; stPictDesc.bmp.hbitmap = hBitmap; stPictDesc.bmp.hpal = hPal; LPPICTURE pPicture; HRESULT hr = OleCreatePictureIndirect( &stPictDesc, IID_IPicture, FALSE, reinterpret_cast<void**>(&pPicture) ); if ( SUCCEEDED(hr) ) { LPSTREAM pStream; hr = CreateStreamOnHGlobal( NULL, TRUE, &pStream ); if ( SUCCEEDED(hr) ) { long lBytesStreamed = 0; hr = pPicture->SaveAsFile( pStream, TRUE, &lBytesStreamed ); if ( SUCCEEDED(hr) ) { HANDLE hFile = CreateFile(_T(lpFileName), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); if ( hFile ) { HGLOBAL hMem = NULL; GetHGlobalFromStream( pStream, &hMem ); LPVOID lpData = GlobalLock( hMem ); DWORD dwBytesWritten; bResult = WriteFile( hFile, lpData, lBytesStreamed, &dwBytesWritten, NULL ); bResult &= ( dwBytesWritten == (DWORD)lBytesStreamed ); // clean up GlobalUnlock(hMem); CloseHandle(hFile); } } // clean up pStream->Release(); } // clean up pPicture->Release(); } return bResult; }
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--; }
/// @brief ÉèÖÃGIF¶¯»Í¼Æ¬,´Ó×ÊÔ´ÖмÓÔØͼƬ. /// @param hEle ÔªËؾä±ú. /// @param id ×ÊÔ´ID. /// @param pType ×ÊÔ´ÀàÐÍ. void WINAPI XGif_SetImageRes(HELE hEle,int id,wchar_t *pType) { IsGifDebug(hEle,__FUNCTION__); gif_ *pObject=(gif_*)hEle; if(pObject->pGif) { delete pObject->pGif; pObject->pGif=NULL; } if(pType) { HMODULE hInst=GetModuleHandle(NULL); wchar_t * lpRes=MAKEINTRESOURCE(id); HRSRC hRsrc=::FindResource(hInst,lpRes,pType); if(NULL==hRsrc) return ; HGLOBAL hGlobal=LoadResource(hInst,hRsrc); DWORD dwSize =SizeofResource(hInst,hRsrc); LPVOID lpData =LockResource(hGlobal); HGLOBAL hJPG = ::GlobalAlloc(GMEM_MOVEABLE, dwSize); LPVOID lpJGP = ::GlobalLock(hJPG); memcpy(lpJGP, lpData, dwSize); ::GlobalUnlock(hJPG); LPSTREAM pstm =NULL; HRESULT hr =CreateStreamOnHGlobal(hJPG, TRUE, &pstm); assert(SUCCEEDED(hr) && pstm); pObject->pGif=new ImageEx(pstm); pstm->Release(); BOOL hrr=FreeResource(hGlobal); if(Gdiplus::Ok != (pObject->pGif->GetLastStatus())) { delete pObject->pGif; pObject->pGif=NULL; } if(pObject->pGif->InitAnimation(0,0)) SetTimer(XEle_GetHWnd(hEle),(int)hEle,100,Gif_TimerProc); } }
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 CMapiApi::GetLargeStringProperty( LPMAPIPROP pProp, ULONG tag, nsCString& val) { LPSTREAM lpStream; HRESULT hr = pProp->OpenProperty( tag, &IID_IStream, 0, 0, (LPUNKNOWN *)&lpStream); if (HR_FAILED( hr)) return( FALSE); STATSTG st; BOOL bResult = TRUE; hr = lpStream->Stat( &st, STATFLAG_NONAME); if (HR_FAILED( hr)) bResult = FALSE; else { if (!st.cbSize.QuadPart) st.cbSize.QuadPart = 1; char *pVal = new char[ (int) st.cbSize.QuadPart + 1]; // val.SetCapacity( (int) st.cbSize.QuadPart); if (pVal) { ULONG sz; hr = lpStream->Read( pVal, (ULONG) st.cbSize.QuadPart, &sz); if (HR_FAILED( hr)) { bResult = FALSE; *pVal = 0; sz = 0; } else pVal[(int) st.cbSize.QuadPart] = 0; val = pVal; delete [] pVal; } else bResult = FALSE; } lpStream->Release(); return( bResult); }
void ReadDirectory(const char* szPath, LPSTORAGE pStg) { // recursive function USES_CONVERSION; WIN32_FIND_DATA fData; HANDLE h; char szNewPath[MAX_PATH]; char szStorageName[100]; char szStreamName[100]; char szData[81]; char* pch = NULL; LPSTORAGE pSubStg = NULL; LPSTREAM pStream = NULL; g_nIndent++; strcpy(szNewPath, szPath); strcat(szNewPath, "*.*"); h = ::FindFirstFile(szNewPath, &fData); if (h == (HANDLE) 0xFFFFFFFF) return; // can't find directory do { if (!strcmp(fData.cFileName, "..") || !strcmp(fData.cFileName, ".") ) continue; while((pch = strchr(fData.cFileName, '!')) != NULL) { *pch = '|'; } if (fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // It's a directory, so make a storage strcpy(szNewPath, szPath); strcat(szNewPath,fData.cFileName); strcat(szNewPath, "\\"); strcpy(szStorageName, fData.cFileName); szStorageName[31] = '\0'; // limit imposed by OLE TRACE("%0.*sStorage = %s\n", (g_nIndent - 1) * 4, g_szBlanks, szStorageName); VERIFY(pStg->CreateStorage(T2COLE(szStorageName), STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pSubStg) == S_OK); ASSERT(pSubStg != NULL); ReadDirectory(szNewPath, pSubStg); pSubStg->Release(); } else { if ((pch = strrchr(fData.cFileName, '.')) != NULL) { if (!stricmp(pch, ".TXT")) { // It's a text file, so make a stream strcpy(szStreamName, fData.cFileName); strcpy(szNewPath, szPath); strcat(szNewPath, szStreamName); szStreamName[32] = '\0'; // OLE max length TRACE("%0.*sStream = %s\n", (g_nIndent - 1) * 4, g_szBlanks, szNewPath); CStdioFile file(szNewPath, CFile::modeRead); // Ignore zero-length files if(file.ReadString(szData, 80)) { TRACE("%s\n", szData); VERIFY(pStg->CreateStream(T2COLE(szStreamName), STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream) == S_OK); ASSERT(pStream != NULL); // Include the null terminator in the stream pStream->Write(szData, strlen(szData) + 1, NULL); pStream->Release(); } } } } } while (::FindNextFile(h, &fData)); g_nIndent--; }
BOOL AFXAPI _AfxSaveObjectInPropset(LPUNKNOWN pUnk, CPropertySection& psec, DWORD dwPropID) { if (pUnk == NULL) return FALSE; ASSERT_POINTER(pUnk, IUnknown); BOOL bSuccess = FALSE; LPDATAOBJECT pDataObj; if (SUCCEEDED(pUnk->QueryInterface(IID_IDataObject, (LPVOID*)&pDataObj))) { // Get the persistent propset format from object. FORMATETC formatEtc; STGMEDIUM stgMedium; formatEtc.cfFormat = _AfxGetClipboardFormatPersistPropset(); formatEtc.ptd = NULL; formatEtc.dwAspect = DVASPECT_CONTENT; formatEtc.lindex = -1; formatEtc.tymed = TYMED_ISTREAM; stgMedium.tymed = TYMED_NULL; stgMedium.pUnkForRelease = NULL; if (SUCCEEDED(pDataObj->GetData(&formatEtc, &stgMedium))) { if (stgMedium.tymed == TYMED_ISTREAM) { LPSTREAM pstm = stgMedium.pstm; // Seek to start of stream. if (SUCCEEDED(pstm->Seek(_afxLargeZero, STREAM_SEEK_SET, NULL))) { // Create a "blobbed" propset from the stream bSuccess = _AfxSaveStreamDataAsBlobProp(stgMedium.pstm, psec, dwPropID, VT_BLOB_PROPSET); } } // Cleanup ReleaseStgMedium(&stgMedium); } pDataObj->Release(); } LPPERSISTSTREAM pPersStm = NULL; if ((!bSuccess) && SUCCEEDED(pUnk->QueryInterface(IID_IPersistStream, (LPVOID*)&pPersStm))) { // Get the object to save itself into a stream, then store that // streamed data as a blob. ASSERT_POINTER(pPersStm, IPersistStream); LPSTREAM pstm = _AfxCreateMemoryStream(); if (pstm != NULL) { if (SUCCEEDED(::OleSaveToStream(pPersStm, pstm)) && SUCCEEDED(pstm->Seek(_afxLargeZero, STREAM_SEEK_SET, NULL))) { bSuccess = _AfxSaveStreamDataAsBlobProp(pstm, psec, dwPropID, VT_BLOB); } pstm->Release(); } pPersStm->Release(); } return bSuccess; }
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; }
/* This seems to be called if one clicks on Save in the context menu. And also sometimes before an Open click. */ STDMETHODIMP GpgolAttachedFileEvents::OnWritePattToSzFile (LPATTACH att, LPTSTR file, ULONG flags) { HRESULT hr; ULONG tag; char *iv; size_t ivlen; symenc_t symenc; LPSTREAM stream; char tmpbuf[16]; ULONG nread; int rc; log_debug ("%s:%s: att=%p file=`%s' flags=%lx\n", SRCNAME, __func__, att, file, flags); if (!att) return E_FAIL; if (get_gpgolprotectiv_tag ((LPMESSAGE)att, &tag) ) return E_ABORT; iv = mapi_get_binary_prop ((LPMESSAGE)att, tag, &ivlen); if (!iv) return S_FALSE; /* Not encrypted by us - Let OL continue as usual. */ symenc = symenc_open (get_128bit_session_key (), 16, iv, ivlen); xfree (iv); if (!symenc) { log_error ("%s:%s: can't open encryption context", SRCNAME, __func__); return E_ABORT; } hr = att->OpenProperty (PR_ATTACH_DATA_BIN, &IID_IStream, 0, 0, (LPUNKNOWN*) &stream); if (FAILED (hr)) { log_error ("%s:%s: can't open data stream of attachment: hr=%#lx", SRCNAME, __func__, hr); symenc_close (symenc); return E_ABORT; } hr = stream->Read (tmpbuf, 16, &nread); if (hr) { log_debug ("%s:%s: Read failed: hr=%#lx", SRCNAME, __func__, hr); stream->Release (); symenc_close (symenc); return E_ABORT; } symenc_cfb_decrypt (symenc, tmpbuf, tmpbuf, 16); if (memcmp (tmpbuf, "GpgOL attachment", 16)) { MessageBox (NULL, _("Sorry, we are not able to decrypt this attachment.\n\n" "Please use the decrypt/verify button to decrypt the\n" "entire message again. Then open this attachment."), "GpgOL", MB_ICONERROR|MB_OK); stream->Release (); symenc_close (symenc); return E_ABORT; } rc = decrypt_and_write_file (stream, file, symenc); stream->Release (); symenc_close (symenc); return rc; }
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; }
//$--HrMAPIGetPropToFile--------------------------------------------------------- // Get a property and put in a given file. // ----------------------------------------------------------------------------- HRESULT HrMAPIGetPropToFile( // RETURNS: return code IN LPMAPIPROP lpObj, // pointer to object IN ULONG ulPropTag, // property tag IN LPSTR lpszFilename, // pointer to destination file name OUT ULONG *lpcbProp) // pointer to count of bytes address // variable { HRESULT hr = NOERROR; HRESULT hrT = NOERROR; SCODE sc = 0; LPSTREAM lpStream = NULL; HANDLE hFile = NULL; ULONG ulBytesRead = 0; LPBYTE lpbBlock = NULL; DWORD dwBytesWritten = 0; DEBUGPUBLIC("HrMAPIGetPropToFile()\n"); hr = CHK_HrMAPIGetPropToFile( lpObj, ulPropTag, lpszFilename, lpcbProp); if(FAILED(hr)) RETURN(hr); // Open a stream on the property hrT = MAPICALL(lpObj)->OpenProperty( /*lpObj,*/ ulPropTag, (LPIID)&IID_IStream, STGM_READ, MAPI_DEFERRED_ERRORS, (LPUNKNOWN *)&lpStream); if(FAILED(hrT)) { // Streams are not supported by provider if((hrT == MAPI_E_NO_SUPPORT) || (hrT == MAPI_E_INTERFACE_NOT_SUPPORTED)) { ULONG PropType = 0; lpStream = NULL; MODULE_WARNING1("Streams are not supported by provider [%08lx]",hrT); PropType = PROP_TYPE(ulPropTag); // Read property into memory switch(PropType) { case PT_BINARY: hr = HrMAPIGetPropBinary( lpObj, ulPropTag, &ulBytesRead, (void **)&lpbBlock); break; default: hr = HrMAPIGetPropString( lpObj, ulPropTag, &ulBytesRead, (void **)&lpbBlock); } } else { hr = HR_LOG(E_FAIL); goto cleanup; } if(FAILED(hr)) { goto cleanup; } } hFile = CreateFile( lpszFilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); if(hFile == INVALID_HANDLE_VALUE) { hr = HR_LOG(E_FAIL); goto cleanup; } // Copy propery value to the file if(lpStream != NULL) { sc = MAPIAllocateBuffer(EDK_CBTRANSFER, (void **)&lpbBlock); // An error occured allocating the block buffer if(FAILED(sc)) { hr = HR_LOG(E_OUTOFMEMORY); goto cleanup; } for (;;) { // Read a block from the stream hrT = /*OLECALL*/(lpStream)->Read( /*lpStream,*/ lpbBlock, EDK_CBTRANSFER, &ulBytesRead); if(FAILED(hrT)) { hr = HR_LOG(E_FAIL); goto cleanup; } if(ulBytesRead == 0L) break; // Write the block to the file hr = _HrWriteFile(hFile, ulBytesRead, lpbBlock); if(FAILED(hr)) { goto cleanup; } } } else { // Write the block to the file hr = _HrWriteFile(hFile, ulBytesRead, lpbBlock); if(FAILED(hr)) { goto cleanup; } } cleanup: // Close the file if(hFile != NULL) { if(CloseHandle(hFile) == FALSE) { hr = HR_LOG(E_FAIL); } } // Release the stream //ULOLERELEASE(lpStream); if (lpStream != NULL) { lpStream->Release(); } lpStream = NULL; MAPIFREEBUFFER(lpbBlock); RETURN(hr); }
BOOL CPropsetPropExchange::ExchangeFontProp(LPCTSTR pszPropName, CFontHolder& font, const FONTDESC* pFontDesc, LPFONTDISP pFontDispAmbient) { ASSERT(AfxIsValidString(pszPropName)); ASSERT_POINTER(&font, CFontHolder); ASSERT_NULL_OR_POINTER(pFontDesc, FONTDESC); ASSERT_NULL_OR_POINTER(pFontDispAmbient, IFontDisp); BOOL bSuccess = FALSE; if (m_bLoading) { DWORD vtType; LPSTREAM pstm = _AfxLoadStreamFromPropset(m_psec, pszPropName, vtType); if (pstm != NULL) { LPFONT pFont; switch(vtType) { case VT_BLOB: pFont = _AfxCreateFontFromStream(pstm); break; case VT_BLOB_PROPSET: pFont = (LPFONT)_AfxCreateObjectFromStreamedPropset(pstm, IID_IFont); break; default: pFont = NULL; } if (pFont != NULL) { font.SetFont(pFont); bSuccess = TRUE; } pstm->Release(); } if (!bSuccess) { // Initialize font to its default state font.InitializeFont(pFontDesc, pFontDispAmbient); } } else { if ((font.m_pFont == NULL) || _AfxIsSameFont(font, pFontDesc, pFontDispAmbient)) { bSuccess = TRUE; } else { ++m_dwPropID; bSuccess = m_psec.SetName(m_dwPropID, pszPropName) && _AfxSaveObjectInPropset(font.m_pFont, m_psec, m_dwPropID); } } return bSuccess; }
LRESULT BlobMgmt::ShowImage() { #ifndef VC6 HDC hdc; RECT rectwin; wyInt32 renderwidth, renderheight; PAINTSTRUCT ps; LPSTREAM stream = NULL; HGLOBAL glbmem; void *glbbuffer; wyWChar tempfilename[MAX_PATH+1] = {0}, path[MAX_PATH + 1] = {0}; wyString tempstr; HANDLE hfile = INVALID_HANDLE_VALUE; DWORD byteswritten = 0; if(!m_piub->m_data || m_piub->m_datasize == 0) { VERIFY(hdc = BeginPaint(m_hwndimage, &ps)); VERIFY(EndPaint(m_hwndimage, &ps)); return 0; } /* allocate global memory and copy image data in it*/ VERIFY(glbmem = GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD, m_piub->m_datasize)); if(!glbmem) return 0; /* lock the global memory and get a pointer */ glbbuffer = GlobalLock(glbmem); /* copy the memory to buffer */ CopyMemory(glbbuffer, m_piub->m_data, m_piub->m_datasize); /* unlock it */ VERIFY(GlobalUnlock(glbmem)== NO_ERROR); /* create the stream */ VERIFY(CreateStreamOnHGlobal(glbmem, FALSE, &stream)== S_OK); /* prepare window for painting */ VERIFY(hdc = BeginPaint(m_hwndimage, &ps)); /* clear the window */ PrepareScreen(ps.hdc); if(pGlobals->m_configdirpath.GetLength() || SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, (LPWSTR)path))) { if(pGlobals->m_configdirpath.GetLength()) { //wcscpy(path, pGlobals->m_configdirpath.GetAsWideChar()); wcsncpy(path, pGlobals->m_configdirpath.GetAsWideChar(), MAX_PATH); path[MAX_PATH] = '\0'; } else { wcscat(path, L"\\"); wcscat(path, L"SQLyog"); } VERIFY(GetTempFileName(path, L"img", 0, tempfilename)); hfile = CreateFile(tempfilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, NULL, NULL); VERIFY(hfile != INVALID_HANDLE_VALUE); VERIFY(WriteFile(hfile, m_piub->m_data, m_piub->m_datasize, &byteswritten, NULL)); VERIFY(CloseHandle(hfile)); } tempstr.SetAs(tempfilename); WCHAR *wpath = GetWideString(tempstr.GetString()); Gdiplus::Graphics graphics(hdc); Gdiplus::Image *image = new Gdiplus::Image(wpath); HeapFree(GetProcessHeap(), 0, wpath); /* in win95 image will be null so we exit */ if(!image) goto ExitPara; /* the binary data might not be image so image.getlastatus will not return Ok */ if(image->GetLastStatus()!= Gdiplus::Ok) { delete image; goto ExitPara; } /* get the window width and calculate the correct render stats */ VERIFY(GetClientRect(m_hwndimage, &rectwin)); renderheight =(((LONG)image->GetHeight())> rectwin.bottom)?(rectwin.bottom):(image->GetHeight()); renderwidth =(((LONG)image->GetWidth())> rectwin.right)?(rectwin.right):(image->GetWidth()); graphics.DrawImage(image, 0, 0, renderwidth, renderheight); delete image; EndPaint(m_hwndimage, &ps); ExitPara: /* free up stuff */ VERIFY(DeleteFile(tempfilename)); if(stream) stream->Release(); VERIFY(GlobalFree(glbmem)== NULL); #endif return 0; }
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; }
BOOL COleControl::GetPropsetData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium, REFCLSID fmtid) { ASSERT_VALID(this); ASSERT(AfxIsValidAddress(lpFormatEtc, sizeof(FORMATETC), FALSE)); ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM))); BOOL bGetDataHere = (lpStgMedium->tymed != TYMED_NULL); // Allow IStream or IStorage as the storage medium. if (!(lpFormatEtc->tymed & (TYMED_ISTREAM|TYMED_ISTORAGE))) { TRACE0("Propset only supported for stream or storage.\n"); return FALSE; } LPSTORAGE lpStorage = NULL; LPSTREAM lpStream = NULL; if (lpFormatEtc->tymed & TYMED_ISTORAGE) { // Caller wants propset data in a storage object. if (bGetDataHere) { // Use the caller-supplied storage object. lpStorage = lpStgMedium->pstg; } else { // Create a storage object on a memory ILockBytes implementation. LPLOCKBYTES lpLockBytes = NULL; if (FAILED(CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes))) { TRACE0("CreateILockBytesOnHGlobal failed.\n"); return FALSE; } ASSERT_POINTER(lpLockBytes, ILockBytes); if (FAILED(StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &lpStorage))) { TRACE0("StgCreateDocfileOnILockBytes failed.\n"); lpLockBytes->Release(); return FALSE; } // Docfile now has reference to ILockBytes, so release ours. lpLockBytes->Release(); } ASSERT_POINTER(lpStorage, IStorage); // Create a stream within the storage. if (FAILED(lpStorage->CreateStream(OLESTR("Contents"), STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, 0, &lpStream))) { TRACE0("IStorage::CreateStream failed.\n"); if (!bGetDataHere) lpStorage->Release(); return FALSE; } } else { // Caller wants propset data in a stream object. if (bGetDataHere) { // Use the caller-supplied stream object lpStream = lpStgMedium->pstm; } else { lpStream = _AfxCreateMemoryStream(); if (lpStream == NULL) return FALSE; } } ASSERT_POINTER(lpStream, IStream); // Create the property set. CLSID clsid; GetClassID(&clsid); CPropertySet pset(clsid); pset.SetOSVersion(MAKELONG(LOWORD(GetVersion()), OSTYPE)); CPropertySection* ppsec = pset.AddSection(fmtid); if (ppsec == NULL) { TRACE0("CPropertySet::AddSection failed.\n"); lpStream->Release(); lpStorage->Release(); return FALSE; } // Set the name, based on the ambient display name (from the container). ppsec->SetSectionName(AmbientDisplayName()); CPropsetPropExchange propx(*ppsec, lpStorage, FALSE); BOOL bPropExchange = FALSE; TRY { DoPropExchange(&propx); bPropExchange = TRUE; } END_TRY if (!bPropExchange) { TRACE0("DoPropExchange failed.\n"); lpStream->Release(); lpStorage->Release(); return FALSE; } // Store the property set in the stream. if (FAILED(pset.WriteToStream(lpStream))) { TRACE0("CPropertySet::WriteToStream failed.\n"); lpStream->Release(); lpStorage->Release(); return FALSE; } // Return the property set in the requested medium. if (lpFormatEtc->tymed & TYMED_ISTORAGE) { // Return as a storage object. ASSERT_POINTER(lpStorage, IStorage); lpStream->Release(); lpStgMedium->pstg = lpStorage; lpStgMedium->tymed = TYMED_ISTORAGE; lpStgMedium->pUnkForRelease = NULL; } else { // Return as a stream. ASSERT_POINTER(lpStream, IStream); lpStgMedium->pstm = lpStream; lpStgMedium->tymed = TYMED_ISTREAM; lpStgMedium->pUnkForRelease = NULL; } return TRUE; }
/// @brief ÉèÖÃGIF¶¯»Í¼Æ¬,´ÓZIPѹËõ°üÖмÓÔØͼƬ. /// @param hEle ÔªËؾä±ú. /// @param pZipFileName ѹËõ°üÎļþ. /// @param pImageName GIFͼƬÃû. /// @param pPassword ѹËõ°üÃÜÂë. void WINAPI XGif_SetImageZip(HELE hEle,wchar_t *pZipFileName,wchar_t *pImageName,wchar_t *pPassword) { IsGifDebug(hEle,__FUNCTION__); gif_ *pObject=(gif_*)hEle; if(pObject->pGif) { delete pObject->pGif; pObject->pGif=NULL; } if(NULL==pZipFileName || NULL==pImageName) { return ; } IsImageTypeDebug(_T(__FUNCTION__),pImageName); char zipfilename[MAX_PATH]={0}; WideCharToMultiByte(CP_ACP,NULL,pZipFileName,wcslen(pZipFileName),zipfilename,MAX_PATH,NULL,NULL); char filename_to_extract[MAX_PATH]={0}; WideCharToMultiByte(CP_ACP,NULL,pImageName,wcslen(pImageName),filename_to_extract,MAX_PATH,NULL,NULL); char password[MAX_PATH]={0}; if(pPassword) WideCharToMultiByte(CP_ACP,NULL,pPassword,wcslen(pPassword),password,MAX_PATH,NULL,NULL); //const char *password=NULL; //char *zipfilename="C:\\Users\\mengfei\\Desktop\\myzip.zip"; //ѹËõ°ü //char *filename_to_extract="dirtt/123.txt"; //ÌáÈ¡ÎļþÃû //char *filename_to_extract="btn.bmp"; //ÌáÈ¡ÎļþÃû unzFile zipFile=NULL; zipFile = unzOpen64(zipfilename); //´ò¿ªÑ¹Ëõ°ü if (zipFile==NULL) { XTRACE("´ò¿ªZIPѹËõ°üʧ°Ü"); return ; } int outSize=0; void *data =NULL; if(pPassword) data=do_extract_onefile(zipFile, filename_to_extract,password,outSize); else data=do_extract_onefile(zipFile, filename_to_extract,NULL,outSize); unzClose(zipFile); if(data) { HGLOBAL hJPG = ::GlobalAlloc(GMEM_MOVEABLE, outSize); LPVOID lpJGP = ::GlobalLock(hJPG); memcpy(lpJGP, data, outSize); ::GlobalUnlock(hJPG); LPSTREAM pstm =NULL; HRESULT hr =CreateStreamOnHGlobal(hJPG, TRUE, &pstm); assert(SUCCEEDED(hr) && pstm); //Image *pImg=Image::FromStream(pstm); pObject->pGif=new ImageEx(pstm); pstm->Release(); free(data); if(Gdiplus::Ok != (pObject->pGif->GetLastStatus())) { delete pObject->pGif; pObject->pGif=NULL; } if(pObject->pGif->InitAnimation(0,0)) SetTimer(XEle_GetHWnd(hEle),(int)hEle,100,Gif_TimerProc); } }
BOOL CMapiMessage::CopyBinAttachToFile( LPATTACH lpAttach) { LPSTREAM lpStreamFile; m_ownsAttachFile = FALSE; m_attachPath.Truncate(); nsCOMPtr<nsIFile> tmpFile; nsresult rv = GetSpecialDirectoryWithFileName(NS_OS_TEMP_DIR, "mapiattach.tmp", getter_AddRefs(tmpFile)); NS_ENSURE_SUCCESS(rv, rv); rv = tmpFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 00600); NS_ENSURE_SUCCESS(rv, rv); nsCString tmpPath; tmpFile->GetNativePath(tmpPath); HRESULT hr = CMapiApi::OpenStreamOnFile( gpMapiAllocateBuffer, gpMapiFreeBuffer, STGM_READWRITE | STGM_CREATE, (char *) tmpPath.get(), NULL, &lpStreamFile); if (HR_FAILED(hr)) { MAPI_TRACE1("~~ERROR~~ OpenStreamOnFile failed - temp path: %s\r\n", tmpPath.get()); return( FALSE); } MAPI_TRACE1("\t\t** Attachment extracted to temp file: %s\r\n", m_attachPath.get()); BOOL bResult = TRUE; LPSTREAM lpAttachStream; hr = lpAttach->OpenProperty( PR_ATTACH_DATA_BIN, &IID_IStream, 0, 0, (LPUNKNOWN *)&lpAttachStream); if (HR_FAILED( hr)) { MAPI_TRACE0( "~~ERROR~~ OpenProperty failed for PR_ATTACH_DATA_BIN.\r\n"); lpAttachStream = NULL; bResult = FALSE; } else { STATSTG st; hr = lpAttachStream->Stat( &st, STATFLAG_NONAME); if (HR_FAILED( hr)) { MAPI_TRACE0( "~~ERROR~~ Stat failed for attachment stream\r\n"); bResult = FALSE; } else { hr = lpAttachStream->CopyTo( lpStreamFile, st.cbSize, NULL, NULL); if (HR_FAILED( hr)) { MAPI_TRACE0( "~~ERROR~~ Attach Stream CopyTo temp file failed.\r\n"); bResult = FALSE; } } } m_attachPath = tmpPath; if (lpAttachStream) lpAttachStream->Release(); lpStreamFile->Release(); if (!bResult) tmpFile->Remove(PR_FALSE); else m_ownsAttachFile = TRUE; return( bResult); }
BOOL CPropsetPropExchange::ExchangePersistentProp(LPCTSTR pszPropName, LPUNKNOWN* ppUnk, REFIID iid, LPUNKNOWN pUnkDefault) { ASSERT(AfxIsValidString(pszPropName)); ASSERT_POINTER(ppUnk, LPUNKNOWN); ASSERT_NULL_OR_POINTER(pUnkDefault, IUnknown); BOOL bSuccess = FALSE; if (m_bLoading) { RELEASE(*ppUnk); *ppUnk = NULL; DWORD vtType; LPSTREAM pstm = _AfxLoadStreamFromPropset(m_psec, pszPropName, vtType); if (pstm != NULL) { CLSID clsid; switch(vtType) { case VT_BLOB: if (_AfxPeekAtClassIDInStream(pstm, &clsid)) { if (IsEqualCLSID(clsid, CLSID_StdPicture) || IsEqualCLSID(clsid, _afx_CLSID_StdPicture_V1)) { // Special case: load the picture directly. bSuccess = SUCCEEDED(::ReadClassStm(pstm, &clsid)) && SUCCEEDED(::OleLoadPicture(pstm, 0, FALSE, iid, (LPVOID*)ppUnk)); } else { // Load the object. bSuccess = SUCCEEDED(::OleLoadFromStream(pstm, iid, (LPVOID*)ppUnk)); } } break; case VT_BLOB_PROPSET: *ppUnk = _AfxCreateObjectFromStreamedPropset(pstm, iid); break; default: break; } pstm->Release(); } if (!bSuccess && (pUnkDefault != NULL)) { bSuccess = SUCCEEDED(pUnkDefault->QueryInterface(iid, (LPVOID*)ppUnk)); } } else { if ((*ppUnk == NULL) || _AfxIsSameUnknownObject(iid, *ppUnk, pUnkDefault)) { bSuccess = TRUE; } else { ++m_dwPropID; bSuccess = m_psec.SetName(m_dwPropID, pszPropName) && _AfxSaveObjectInPropset(*ppUnk, m_psec, m_dwPropID); } } return bSuccess; }