static HRESULT WINAPI PersistHistory_SaveHistory(IPersistHistory *iface, IStream *pStream) { HTMLDocument *This = impl_from_IPersistHistory(iface); ULONG len, written; BSTR display_uri; HRESULT hres; TRACE("(%p)->(%p)\n", This, pStream); if(!This->window || !This->window->uri) { FIXME("No current URI\n"); return E_FAIL; } /* NOTE: The format we store is *not* compatible with native MSHTML. We currently * store only URI of the page (as a length followed by a string) */ hres = IUri_GetDisplayUri(This->window->uri, &display_uri); if(FAILED(hres)) return hres; len = SysStringLen(display_uri); hres = IStream_Write(pStream, &len, sizeof(len), &written); if(SUCCEEDED(hres)) hres = IStream_Write(pStream, display_uri, len*sizeof(WCHAR), &written); SysFreeString(display_uri); return hres; }
/****************************************************************************** * ItemMoniker_Save ******************************************************************************/ static HRESULT WINAPI ItemMonikerImpl_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty) { ItemMonikerImpl *This = impl_from_IMoniker(iface); HRESULT res; CHAR *itemNameA,*itemDelimiterA; /* data written by this function are : 1) DWORD : size of item delimiter string ('\0' included ) */ /* 2) String (type A): item delimiter string ('\0' included) */ /* 3) DWORD : size of item name string ('\0' included) */ /* 4) String (type A): item name string ('\0' included) */ DWORD nameLength = WideCharToMultiByte( CP_ACP, 0, This->itemName, -1, NULL, 0, NULL, NULL); DWORD delimiterLength = WideCharToMultiByte( CP_ACP, 0, This->itemDelimiter, -1, NULL, 0, NULL, NULL); itemNameA=HeapAlloc(GetProcessHeap(),0,nameLength); itemDelimiterA=HeapAlloc(GetProcessHeap(),0,delimiterLength); WideCharToMultiByte( CP_ACP, 0, This->itemName, -1, itemNameA, nameLength, NULL, NULL); WideCharToMultiByte( CP_ACP, 0, This->itemDelimiter, -1, itemDelimiterA, delimiterLength, NULL, NULL); TRACE("%p, %s\n", pStm, fClearDirty ? "TRUE" : "FALSE"); res=IStream_Write(pStm,&delimiterLength,sizeof(DWORD),NULL); res=IStream_Write(pStm,itemDelimiterA,delimiterLength * sizeof(CHAR),NULL); res=IStream_Write(pStm,&nameLength,sizeof(DWORD),NULL); res=IStream_Write(pStm,itemNameA,nameLength * sizeof(CHAR),NULL); HeapFree(GetProcessHeap(), 0, itemNameA); HeapFree(GetProcessHeap(), 0, itemDelimiterA); return res; }
static HRESULT CALLBACK CB_Save(LPITEMDATA pInfo, IStream *pStm, LPARAM lp) { HRESULT hRes; ok(lp == 0xdeadbeef, "lp=%ld\n", lp); hRes = IStream_Write(pStm, &pInfo->iPos, sizeof(INT), NULL); ok(hRes == S_OK, "hRes=0x%x\n", hRes); hRes = IStream_Write(pStm, &pInfo->pvData, sizeof(PVOID), NULL); ok(hRes == S_OK, "hRes=0x%x\n", hRes); return S_OK; }
static HRESULT CALLBACK CB_Save(DPASTREAMINFO *pInfo, IStream *pStm, LPVOID lp) { HRESULT hRes; ok(lp == (LPVOID)0xdeadbeef, "lp=%p\n", lp); hRes = IStream_Write(pStm, &pInfo->iPos, sizeof(INT), NULL); expect(S_OK, hRes); hRes = IStream_Write(pStm, &pInfo->pvItem, sizeof(PVOID), NULL); expect(S_OK, hRes); return S_OK; }
/****************************************************************************** * ClassMoniker_Save ******************************************************************************/ static HRESULT WINAPI ClassMoniker_Save(IMoniker* iface, IStream* pStm, BOOL fClearDirty) { ClassMoniker *This = impl_from_IMoniker(iface); HRESULT hr; DWORD zero = 0; TRACE("(%p, %s)\n", pStm, fClearDirty ? "TRUE" : "FALSE"); hr = IStream_Write(pStm, &This->clsid, sizeof(This->clsid), NULL); if (FAILED(hr)) return hr; return IStream_Write(pStm, &zero, sizeof(zero), NULL); }
static HRESULT WINAPI FTMarshalImpl_MarshalInterface (LPMARSHAL iface, IStream * pStm, REFIID riid, void *pv, DWORD dwDestContext, void *pvDestContext, DWORD mshlflags) { IMarshal *pMarshal = NULL; HRESULT hres; TRACE("(%p, %s, %p, 0x%x, %p, 0x%x)\n", pStm, debugstr_guid(riid), pv, dwDestContext, pvDestContext, mshlflags); /* if the marshalling happens inside the same process the interface pointer is copied between the apartments */ if (dwDestContext == MSHCTX_INPROC || dwDestContext == MSHCTX_CROSSCTX) { void *object; DWORD constant = 0; GUID unknown_guid = { 0 }; hres = IUnknown_QueryInterface((IUnknown *)pv, riid, &object); if (FAILED(hres)) return hres; /* don't hold a reference to table-weak marshaled interfaces */ if (mshlflags & MSHLFLAGS_TABLEWEAK) IUnknown_Release((IUnknown *)object); hres = IStream_Write (pStm, &mshlflags, sizeof (mshlflags), NULL); if (hres != S_OK) return STG_E_MEDIUMFULL; hres = IStream_Write (pStm, &object, sizeof (object), NULL); if (hres != S_OK) return STG_E_MEDIUMFULL; if (sizeof(object) == sizeof(DWORD)) { hres = IStream_Write (pStm, &constant, sizeof (constant), NULL); if (hres != S_OK) return STG_E_MEDIUMFULL; } hres = IStream_Write (pStm, &unknown_guid, sizeof (unknown_guid), NULL); if (hres != S_OK) return STG_E_MEDIUMFULL; return S_OK; } /* use the standard marshaler to handle all other cases */ CoGetStandardMarshal (riid, pv, dwDestContext, pvDestContext, mshlflags, &pMarshal); hres = IMarshal_MarshalInterface (pMarshal, pStm, riid, pv, dwDestContext, pvDestContext, mshlflags); IMarshal_Release (pMarshal); return hres; }
/****************************************************************************** * AntiMoniker_Save ******************************************************************************/ static HRESULT WINAPI AntiMonikerImpl_Save(IMoniker* iface,IStream* pStm,BOOL fClearDirty) { static const DWORD constant = 1; /* data written by this function is only a DWORD constant set to 1 ! */ return IStream_Write(pStm,&constant,sizeof(constant),NULL); }
// Creates a set of sample files in the current user's Documents directory to use as items in the // custom category inserted into the Jump List. HRESULT CreateSampleFiles() { PWSTR pszPathDocuments; HRESULT hr = SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_CREATE, NULL, &pszPathDocuments); if (SUCCEEDED(hr)) { for (UINT i = 0; SUCCEEDED(hr) && i < ARRAYSIZE(c_rgpszFiles); i++) { WCHAR szPathSample[MAX_PATH]; hr = PathCombine(szPathSample, pszPathDocuments, c_rgpszFiles[i]) ? S_OK : E_FAIL; if (SUCCEEDED(hr)) { IStream *pstm; hr = SHCreateStreamOnFileEx(szPathSample, (STGM_WRITE | STGM_FAILIFTHERE), FILE_ATTRIBUTE_NORMAL, TRUE, NULL, &pstm); if (SUCCEEDED(hr)) { PCWSTR pszText = L"This is a sample file for the CustomJumpListSample.\r\n"; ULONG cb = (sizeof(pszText[0]) * (lstrlen(pszText) + 1)); hr = IStream_Write(pstm, pszText, cb); pstm->Release(); } else if (HRESULT_FROM_WIN32(ERROR_FILE_EXISTS) == hr) { // If the file exists, we're ok, we'll just reuse it hr = S_OK; } } } CoTaskMemFree(pszPathDocuments); } return hr; }
static HRESULT WINAPI XMLView_BindStatusCallback_OnDataAvailable( IBindStatusCallback *iface, DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed) { BindStatusCallback *This = impl_from_IBindStatusCallback(iface); char buf[1024]; DWORD size; HRESULT hres; TRACE("(%p)->(%x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed); if(!This->stream) return E_FAIL; do { hres = IStream_Read(pstgmed->u.pstm, buf, sizeof(buf), &size); IStream_Write(This->stream, buf, size, &size); } while(hres==S_OK && size); if(FAILED(hres) && hres!=E_PENDING) return hres; if(hres != S_FALSE) return S_OK; return handle_xml_load(This); }
static HRESULT WINAPI mxwriter_saxcontent_startDocument(ISAXContentHandler *iface) { mxwriter *This = impl_from_ISAXContentHandler( iface ); TRACE("(%p)\n", This); /* If properties have been changed since the last "endDocument" call * we need to reset the output buffer. If we don't the output buffer * could end up with multiple XML documents in it, plus this seems to * be how Windows works. */ if (This->prop_changed) { reset_output_buffer(This); This->prop_changed = FALSE; } if (This->props[MXWriter_OmitXmlDecl] == VARIANT_TRUE) return S_OK; write_prolog_buffer(This); if (This->dest && This->xml_enc == XmlEncoding_UTF16) { static const char utf16BOM[] = {0xff,0xfe}; if (This->props[MXWriter_BOM] == VARIANT_TRUE) /* Windows passes a NULL pointer as the pcbWritten parameter and * ignores any error codes returned from this Write call. */ IStream_Write(This->dest, utf16BOM, sizeof(utf16BOM), NULL); } return S_OK; }
static HRESULT WINAPI IcnsEncoder_Commit(IWICBitmapEncoder *iface) { IcnsEncoder *This = impl_from_IWICBitmapEncoder(iface); size_t buffer_size; HRESULT hr = S_OK; ULONG byteswritten; TRACE("(%p)\n", iface); EnterCriticalSection(&This->lock); if (!This->any_frame_committed || This->outstanding_commits > 0 || This->committed) { hr = WINCODEC_ERR_WRONGSTATE; goto end; } buffer_size = GetHandleSize((Handle)This->icns_family); hr = IStream_Write(This->stream, *This->icns_family, buffer_size, &byteswritten); if (FAILED(hr) || byteswritten != buffer_size) { WARN("writing file failed, hr = 0x%08X\n", hr); hr = E_FAIL; goto end; } This->committed = TRUE; end: LeaveCriticalSection(&This->lock); return hr; }
static HRESULT WINAPI PersistStreamInit_Save(IPersistStreamInit *iface, LPSTREAM pStm, BOOL fClearDirty) { HTMLDocument *This = impl_from_IPersistStreamInit(iface); char *str; DWORD written=0; HRESULT hres; TRACE("(%p)->(%p %x)\n", This, pStm, fClearDirty); hres = get_doc_string(This->doc_node, &str); if(FAILED(hres)) return hres; hres = IStream_Write(pStm, str, strlen(str), &written); if(FAILED(hres)) FIXME("Write failed: %08x\n", hres); heap_free(str); if(fClearDirty) set_dirty(This, VARIANT_FALSE); return S_OK; }
static HRESULT WINAPI bsc_OnDataAvailable( IBindStatusCallback* iface, DWORD grfBSCF, DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed) { bsc_t *This = impl_from_IBindStatusCallback(iface); BYTE buf[4096]; DWORD read, written; HRESULT hr; TRACE("(%p)->(%x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed); do { hr = IStream_Read(pstgmed->u.pstm, buf, sizeof(buf), &read); if(FAILED(hr)) break; hr = IStream_Write(This->memstream, buf, read, &written); } while(SUCCEEDED(hr) && written != 0 && read != 0); return S_OK; }
static HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Write (LPSTREAM iface, const void* pv, ULONG cb, ULONG* pcbWritten) { ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); TRACE_(dmfileraw)("(%p, %p, 0x%08lX, %p): redirecting to low-level stream\n", This, pv, cb, pcbWritten); if (!This->pStream) return E_FAIL; return IStream_Write (This->pStream, pv, cb, pcbWritten); }
static HRESULT write_hlink_string(IStream *pStm, LPCWSTR str) { DWORD len; HRESULT hr; TRACE("(%p, %s)\n", pStm, debugstr_w(str)); len = strlenW(str) + 1; hr = IStream_Write(pStm, &len, sizeof(len), NULL); if (FAILED(hr)) return hr; hr = IStream_Write(pStm, str, len * sizeof(WCHAR), NULL); if (FAILED(hr)) return hr; return S_OK; }
/****************************************************************************** * ClassMoniker_Save ******************************************************************************/ static HRESULT WINAPI ClassMoniker_Save(IMoniker* iface, IStream* pStm,/* pointer to the stream where the object is to be saved */ BOOL fClearDirty)/* Specifies whether to clear the dirty flag */ { ClassMoniker *This = (ClassMoniker *)iface; HRESULT hr; DWORD zero = 0; TRACE("(%p, %s)\n", pStm, fClearDirty ? "TRUE" : "FALSE"); hr = IStream_Write(pStm, &This->clsid, sizeof(This->clsid), NULL); if (FAILED(hr)) return hr; hr = IStream_Write(pStm, &zero, sizeof(zero), NULL); return hr; }
static HRESULT WINAPI IWICStreamImpl_Write(IWICStream *iface, void const *pv, ULONG cb, ULONG *pcbWritten) { IWICStreamImpl *This = impl_from_IWICStream(iface); TRACE("(%p): relay\n", This); if (!This->pStream) return WINCODEC_ERR_NOTINITIALIZED; return IStream_Write(This->pStream, pv, cb, pcbWritten); }
static HRESULT WINAPI URLMoniker_Save(IMoniker *iface, IStream* pStm, BOOL fClearDirty) { URLMoniker *This = impl_from_IMoniker(iface); HRESULT res; ULONG size; TRACE("(%p,%p,%d)\n", This, pStm, fClearDirty); if(!pStm) return E_INVALIDARG; size = (SysStringLen(This->URLName) + 1)*sizeof(WCHAR); res=IStream_Write(pStm,&size,sizeof(ULONG),NULL); if(SUCCEEDED(res)) res=IStream_Write(pStm,This->URLName,size,NULL); return res; }
/*** * This method is part of the IStream interface. * * It will copy the 'cb' Bytes to 'pstm' IStream. * * See the documentation of IStream for more info. */ static HRESULT WINAPI HGLOBALStreamImpl_CopyTo( IStream* iface, IStream* pstm, /* [unique][in] */ ULARGE_INTEGER cb, /* [in] */ ULARGE_INTEGER* pcbRead, /* [out] */ ULARGE_INTEGER* pcbWritten) /* [out] */ { HRESULT hr = S_OK; BYTE tmpBuffer[128]; ULONG bytesRead, bytesWritten, copySize; ULARGE_INTEGER totalBytesRead; ULARGE_INTEGER totalBytesWritten; TRACE("(%p, %p, %d, %p, %p)\n", iface, pstm, cb.u.LowPart, pcbRead, pcbWritten); if ( pstm == 0 ) return STG_E_INVALIDPOINTER; totalBytesRead.QuadPart = 0; totalBytesWritten.QuadPart = 0; while ( cb.QuadPart > 0 ) { if ( cb.QuadPart >= sizeof(tmpBuffer) ) copySize = sizeof(tmpBuffer); else copySize = cb.u.LowPart; hr = IStream_Read(iface, tmpBuffer, copySize, &bytesRead); if (FAILED(hr)) break; totalBytesRead.QuadPart += bytesRead; if (bytesRead) { hr = IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten); if (FAILED(hr)) break; totalBytesWritten.QuadPart += bytesWritten; } if (bytesRead!=copySize) cb.QuadPart = 0; else cb.QuadPart -= bytesRead; } if (pcbRead) pcbRead->QuadPart = totalBytesRead.QuadPart; if (pcbWritten) pcbWritten->QuadPart = totalBytesWritten.QuadPart; return hr; }
static void test_copyto(void) { IStream *pStream, *pStream2; HRESULT hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream); static const char szHello[] = "Hello"; ULARGE_INTEGER cb; static const char *methods_copyto[] = { "TestStream_Write", NULL }; ULONG written; ULARGE_INTEGER ullRead; ULARGE_INTEGER ullWritten; ULARGE_INTEGER libNewPosition; static const LARGE_INTEGER llZero; char buffer[15]; ok_ole_success(hr, "CreateStreamOnHGlobal"); expected_method_list = methods_copyto; hr = IStream_Write(pStream, szHello, sizeof(szHello), &written); ok_ole_success(hr, "IStream_Write"); ok(written == sizeof(szHello), "only %d bytes written\n", written); hr = IStream_Seek(pStream, llZero, STREAM_SEEK_SET, NULL); ok_ole_success(hr, "IStream_Seek"); cb.QuadPart = sizeof(szHello); hr = IStream_CopyTo(pStream, &Test_Stream, cb, &ullRead, &ullWritten); ok(ullWritten.QuadPart == 5, "ullWritten was %d instead\n", (ULONG)ullWritten.QuadPart); ok(ullRead.QuadPart == sizeof(szHello), "only %d bytes read\n", (ULONG)ullRead.QuadPart); ok_ole_success(hr, "IStream_CopyTo"); ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list); hr = IStream_Clone(pStream, &pStream2); ok_ole_success(hr, "IStream_Clone"); hr = IStream_Seek(pStream2, llZero, STREAM_SEEK_CUR, &libNewPosition); ok_ole_success(hr, "IStream_Seek"); ok(libNewPosition.QuadPart == sizeof(szHello), "libNewPosition wasn't set correctly for the cloned stream\n"); hr = IStream_Seek(pStream2, llZero, STREAM_SEEK_SET, NULL); ok_ole_success(hr, "IStream_Seek"); hr = IStream_Read(pStream2, buffer, sizeof(buffer), NULL); ok_ole_success(hr, "IStream_Read"); ok(!strcmp(buffer, szHello), "read data \"%s\" didn't match originally written data\n", buffer); IStream_Release(pStream2); IStream_Release(pStream); }
/****************************************************************************** * URLMoniker_Save ******************************************************************************/ static HRESULT WINAPI URLMonikerImpl_Save(IMoniker* iface, IStream* pStm,/* pointer to the stream where the object is to be saved */ BOOL fClearDirty)/* Specifies whether to clear the dirty flag */ { URLMonikerImpl *This = (URLMonikerImpl *)iface; HRESULT res; ULONG size; TRACE("(%p,%p,%d)\n",This,pStm,fClearDirty); if(!pStm) return E_INVALIDARG; size = (strlenW(This->URLName) + 1)*sizeof(WCHAR); res=IStream_Write(pStm,&size,sizeof(ULONG),NULL); if(SUCCEEDED(res)) res=IStream_Write(pStm,This->URLName,size,NULL); return res; }
static HRESULT WINAPI xmldoc_IPersistStreamInit_Load( IPersistStreamInit *iface, LPSTREAM pStm) { xmldoc *This = impl_from_IPersistStreamInit(iface); HRESULT hr; HGLOBAL hglobal; DWORD read, written, len; BYTE buf[4096]; char *ptr; TRACE("(%p, %p)\n", iface, pStm); if (!pStm) return E_INVALIDARG; /* release previously allocated stream */ if (This->stream) IStream_Release(This->stream); hr = CreateStreamOnHGlobal(NULL, TRUE, &This->stream); if (FAILED(hr)) return hr; do { IStream_Read(pStm, buf, sizeof(buf), &read); hr = IStream_Write(This->stream, buf, read, &written); } while(SUCCEEDED(hr) && written != 0 && read != 0); if (FAILED(hr)) { ERR("Failed to copy stream\n"); return hr; } hr = GetHGlobalFromStream(This->stream, &hglobal); if (FAILED(hr)) return hr; len = GlobalSize(hglobal); ptr = GlobalLock(hglobal); if (len != 0) { xmlFreeDoc(This->xmldoc); This->xmldoc = parse_xml(ptr, len); } GlobalUnlock(hglobal); if (!This->xmldoc) { ERR("Failed to parse xml\n"); return E_FAIL; } return S_OK; }
static void user_write_data(png_structp png_ptr, png_bytep data, png_size_t length) { PngEncoder *This = ppng_get_io_ptr(png_ptr); HRESULT hr; ULONG byteswritten; hr = IStream_Write(This->stream, data, length, &byteswritten); if (FAILED(hr) || byteswritten != length) { ppng_error(png_ptr, "failed writing data"); } }
static HRESULT WINAPI NoStatStreamImpl_CopyTo( IStream* iface, IStream* pstm, /* [unique][in] */ ULARGE_INTEGER cb, /* [in] */ ULARGE_INTEGER* pcbRead, /* [out] */ ULARGE_INTEGER* pcbWritten) /* [out] */ { HRESULT hr = S_OK; BYTE tmpBuffer[128]; ULONG bytesRead, bytesWritten, copySize; ULARGE_INTEGER totalBytesRead; ULARGE_INTEGER totalBytesWritten; if ( pstm == 0 ) return STG_E_INVALIDPOINTER; totalBytesRead.u.LowPart = totalBytesRead.u.HighPart = 0; totalBytesWritten.u.LowPart = totalBytesWritten.u.HighPart = 0; while ( cb.u.LowPart > 0 ) { if ( cb.u.LowPart >= 128 ) copySize = 128; else copySize = cb.u.LowPart; IStream_Read(iface, tmpBuffer, copySize, &bytesRead); totalBytesRead.u.LowPart += bytesRead; IStream_Write(pstm, tmpBuffer, bytesRead, &bytesWritten); totalBytesWritten.u.LowPart += bytesWritten; if (bytesRead != bytesWritten) { hr = STG_E_MEDIUMFULL; break; } if (bytesRead!=copySize) cb.u.LowPart = 0; else cb.u.LowPart -= bytesRead; } if (pcbRead) { pcbRead->u.LowPart = totalBytesRead.u.LowPart; pcbRead->u.HighPart = totalBytesRead.u.HighPart; } if (pcbWritten) { pcbWritten->u.LowPart = totalBytesWritten.u.LowPart; pcbWritten->u.HighPart = totalBytesWritten.u.HighPart; } return hr; }
/************************************************************************* * @ [SHLWAPI.17] * * Write a DataBlock list to an IStream object. * * PARAMS * lpStream [I] IStream object to write the list to * lpList [I] List of items to write * * RETURNS * Success: S_OK. The object is written to the stream. * Failure: An HRESULT error code * * NOTES * Ordinals 17,18,19,20,21 and 22 are related and together provide a compact * list structure (a "DataBlock List"), which may be stored and retrieved from * an IStream object. * * The exposed API consists of: * * - SHWriteDataBlockList() - Write a DataBlock list to a stream, * - SHReadDataBlockList() - Read and create a list from a stream, * - SHFreeDataBlockList() - Free a list, * - SHAddDataBlock() - Insert a new item into a list, * - SHRemoveDataBlock() - Remove an item from a list, * - SHFindDataBlock() - Find an item in a list. * * The DataBlock list is stored packed into a memory array. Each element has a * size and an associated ID. Elements must be less than 64k if the list is * to be subsequently read from a stream. * * Elements are aligned on DWORD boundaries. If an elements data size is not * a DWORD size multiple, the element is wrapped by inserting a surrounding * element with an Id of 0xFFFFFFFF, and size sufficient to pad to a DWORD boundary. * * These functions are slow for large objects and long lists. */ HRESULT WINAPI SHWriteDataBlockList(IStream* lpStream, LPDBLIST lpList) { ULONG ulSize; HRESULT hRet = S_OK; TRACE("(%p,%p)\n", lpStream, lpList); if(lpList) { while (lpList->cbSize) { LPDATABLOCK_HEADER lpItem = lpList; if(lpList->dwSignature == CLIST_ID_CONTAINER) lpItem++; hRet = IStream_Write(lpStream,lpItem,lpItem->cbSize,&ulSize); if (FAILED(hRet)) return hRet; if(lpItem->cbSize != ulSize) return STG_E_MEDIUMFULL; lpList = NextItem(lpList); } } if(SUCCEEDED(hRet)) { ULONG ulDummy; ulSize = 0; /* Write a terminating list entry with zero size */ hRet = IStream_Write(lpStream, &ulSize,sizeof(ulSize),&ulDummy); } return hRet; }
/************************************************************************* * @ [SHLWAPI.212] * * Call IStream_Write() on a stream. * * PARAMS * lpStream [I] IStream object * lpvSrc [I] Source for data to write * ulSize [I] Size of data * * RETURNS * Success: S_OK. ulSize bytes have been written to the stream from lpvSrc. * Failure: An HRESULT error code, or E_FAIL if the write succeeded but the * number of bytes written does not match. */ HRESULT WINAPI SHIStream_Write(IStream *lpStream, LPCVOID lpvSrc, ULONG ulSize) { ULONG ulWritten; HRESULT hRet; TRACE("(%p,%p,%d)\n", lpStream, lpvSrc, ulSize); hRet = IStream_Write(lpStream, lpvSrc, ulSize, &ulWritten); if (SUCCEEDED(hRet) && ulWritten != ulSize) hRet = E_FAIL; return hRet; }
static void dest_mgr_term_destination(j_compress_ptr cinfo) { JpegEncoder *This = encoder_from_compress(cinfo); ULONG byteswritten; HRESULT hr; if (This->dest_mgr.free_in_buffer != sizeof(This->dest_buffer)) { hr = IStream_Write(This->stream, This->dest_buffer, sizeof(This->dest_buffer) - This->dest_mgr.free_in_buffer, &byteswritten); if (hr != S_OK || byteswritten == 0) ERR("Failed writing data, hr=%x\n", hr); } }
static void test_freed_hglobal(void) { static const char teststring[] = "this is a test string"; HRESULT hr; IStream *pStream; HGLOBAL hglobal; char *p; char buffer[sizeof(teststring) + 8]; ULARGE_INTEGER ull; ULONG read, written; hglobal = GlobalAlloc(GMEM_DDESHARE|GMEM_NODISCARD|GMEM_MOVEABLE, strlen(teststring) + 1); ok(hglobal != NULL, "GlobalAlloc failed with error %d\n", GetLastError()); p = GlobalLock(hglobal); strcpy(p, teststring); GlobalUnlock(hglobal); hr = CreateStreamOnHGlobal(hglobal, FALSE, &pStream); ok_ole_success(hr, "CreateStreamOnHGlobal"); hr = IStream_Read(pStream, buffer, sizeof(buffer), &read); ok_ole_success(hr, "IStream_Read"); ok(!strcmp(buffer, teststring), "buffer data %s differs\n", buffer); ok(read == sizeof(teststring) || broken(read == ((sizeof(teststring) + 3) & ~3)), /* win9x rounds the size */ "read should be sizeof(teststring) instead of %d\n", read); GlobalFree(hglobal); memset(buffer, 0, sizeof(buffer)); read = -1; hr = IStream_Read(pStream, buffer, sizeof(buffer), &read); ok_ole_success(hr, "IStream_Read"); ok(buffer[0] == 0, "buffer data should be untouched\n"); ok(read == 0, "read should be 0 instead of %d\n", read); ull.QuadPart = sizeof(buffer); hr = IStream_SetSize(pStream, ull); ok(hr == E_OUTOFMEMORY, "IStream_SetSize with invalid HGLOBAL should return E_OUTOFMEMORY instead of 0x%08x\n", hr); hr = IStream_Write(pStream, buffer, sizeof(buffer), &written); ok(hr == E_OUTOFMEMORY, "IStream_Write with invalid HGLOBAL should return E_OUTOFMEMORY instead of 0x%08x\n", hr); ok(written == 0, "written should be 0 instead of %d\n", written); IStream_Release(pStream); }
static jpeg_boolean dest_mgr_empty_output_buffer(j_compress_ptr cinfo) { JpegEncoder *This = encoder_from_compress(cinfo); HRESULT hr; ULONG byteswritten; hr = IStream_Write(This->stream, This->dest_buffer, sizeof(This->dest_buffer), &byteswritten); if (hr != S_OK || byteswritten == 0) { ERR("Failed writing data, hr=%x\n", hr); return FALSE; } This->dest_mgr.next_output_byte = This->dest_buffer; This->dest_mgr.free_in_buffer = sizeof(This->dest_buffer); return TRUE; }
static HRESULT WINAPI StreamOnStreamRange_Write(IStream *iface, void const *pv, ULONG cb, ULONG *pcbWritten) { StreamOnStreamRange *This = StreamOnStreamRange_from_IStream(iface); HRESULT hr; ULARGE_INTEGER OldPosition; LARGE_INTEGER SetPosition; ULONG uBytesWritten=0; TRACE("(%p)\n", This); if (!pv) return E_INVALIDARG; EnterCriticalSection(&This->lock); SetPosition.QuadPart = 0; hr = IStream_Seek(This->stream, SetPosition, STREAM_SEEK_CUR, &OldPosition); if (SUCCEEDED(hr)) { SetPosition.QuadPart = This->pos.QuadPart + This->offset.QuadPart; hr = IStream_Seek(This->stream, SetPosition, STREAM_SEEK_SET, NULL); } if (SUCCEEDED(hr)) { if (This->pos.QuadPart + cb > This->max_size.QuadPart) { /* This would read past the end of the stream. */ if (This->pos.QuadPart > This->max_size.QuadPart) cb = 0; else cb = This->max_size.QuadPart - This->pos.QuadPart; } hr = IStream_Write(This->stream, pv, cb, &uBytesWritten); SetPosition.QuadPart = OldPosition.QuadPart; IStream_Seek(This->stream, SetPosition, STREAM_SEEK_SET, NULL); } if (SUCCEEDED(hr)) This->pos.QuadPart += uBytesWritten; LeaveCriticalSection(&This->lock); if (SUCCEEDED(hr) && pcbWritten) *pcbWritten = uBytesWritten; return hr; }