static void test_URLOpenBlockingStreamW(void) { HRESULT hr; IStream *pStream = NULL; char buffer[256]; hr = URLOpenBlockingStreamW(NULL, NULL, &pStream, 0, &BindStatusCallback); ok(hr == E_INVALIDARG, "URLOpenBlockingStreamW should have failed with E_INVALIDARG instead of 0x%08x\n", hr); if (0) /* crashes on Win2k */ { hr = URLOpenBlockingStreamW(NULL, INDEX_HTML, NULL, 0, &BindStatusCallback); ok(hr == E_INVALIDARG, "URLOpenBlockingStreamW should have failed with E_INVALIDARG instead of 0x%08x\n", hr); } SET_EXPECT(GetBindInfo); SET_EXPECT(QueryInterface_IServiceProvider); SET_EXPECT(OnStartBinding); SET_EXPECT(OnProgress_SENDINGREQUEST); SET_EXPECT(OnProgress_MIMETYPEAVAILABLE); SET_EXPECT(OnProgress_BEGINDOWNLOADDATA); SET_EXPECT(OnProgress_ENDDOWNLOADDATA); SET_EXPECT(OnStopBinding); hr = URLOpenBlockingStreamW(NULL, INDEX_HTML, &pStream, 0, &BindStatusCallback); ok(hr == S_OK, "URLOpenBlockingStreamW failed with error 0x%08x\n", hr); CHECK_CALLED(GetBindInfo); todo_wine CHECK_CALLED(QueryInterface_IServiceProvider); CHECK_CALLED(OnStartBinding); CHECK_CALLED(OnProgress_SENDINGREQUEST); CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE); CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA); CHECK_CALLED(OnProgress_ENDDOWNLOADDATA); CHECK_CALLED(OnStopBinding); ok(pStream != NULL, "pStream is NULL\n"); if(pStream) { buffer[0] = 0; hr = IStream_Read(pStream, buffer, sizeof(buffer), NULL); ok(hr == S_OK, "IStream_Read failed with error 0x%08x\n", hr); ok(!memcmp(buffer, szHtmlDoc, sizeof(szHtmlDoc)-1), "read data differs from file\n"); IStream_Release(pStream); } hr = URLOpenBlockingStreamW(NULL, INDEX_HTML, &pStream, 0, NULL); ok(hr == S_OK, "URLOpenBlockingStreamW failed with error 0x%08x\n", hr); ok(pStream != NULL, "pStream is NULL\n"); if(pStream) { buffer[0] = 0; hr = IStream_Read(pStream, buffer, sizeof(buffer), NULL); ok(hr == S_OK, "IStream_Read failed with error 0x%08x\n", hr); ok(!memcmp(buffer, szHtmlDoc, sizeof(szHtmlDoc)-1), "read data differs from file\n"); IStream_Release(pStream); } }
static HRESULT WINAPI xmldoc_put_URL(IXMLDocument *iface, BSTR p) { WCHAR url[INTERNET_MAX_URL_LENGTH]; IStream *stream; IBindCtx *bctx; IMoniker *moniker; IPersistStreamInit *persist; HRESULT hr; TRACE("(%p, %s)\n", iface, debugstr_w(p)); if (!p) return E_INVALIDARG; if (!PathIsURLW(p)) { WCHAR fullpath[MAX_PATH]; DWORD needed = sizeof(url) / sizeof(WCHAR); if (!PathSearchAndQualifyW(p, fullpath, sizeof(fullpath) / sizeof(WCHAR))) { ERR("can't find path\n"); return E_FAIL; } if (FAILED(UrlCreateFromPathW(fullpath, url, &needed, 0))) { ERR("can't create url from path\n"); return E_FAIL; } p = url; } hr = CreateURLMoniker(NULL, p, &moniker); if (FAILED(hr)) return hr; CreateAsyncBindCtx(0, &xmldoc_bsc.IBindStatusCallback_iface, 0, &bctx); hr = IMoniker_BindToStorage(moniker, bctx, NULL, &IID_IStream, (LPVOID *)&stream); IBindCtx_Release(bctx); IMoniker_Release(moniker); if (FAILED(hr)) return hr; hr = IXMLDocument_QueryInterface(iface, &IID_IPersistStreamInit, (LPVOID *)&persist); if (FAILED(hr)) { IStream_Release(stream); return hr; } hr = IPersistStreamInit_Load(persist, stream); IPersistStreamInit_Release(persist); IStream_Release(stream); return hr; }
static gboolean gdip_save_bitmap_to_callback (GpBitmap *bitmap, const CLSID *format, const EncoderParameters *encoder_params, GdkPixbufSaveFunc save_func, gpointer user_data, GError **error) { HRESULT hr; IStream *streamOut = NULL; gboolean success = FALSE; guint64 zero = 0; GpStatus status; hr = CreateStreamOnHGlobal (NULL, TRUE, &streamOut); if (!SUCCEEDED (hr)) { gdip_set_error_from_hresult (error, GDK_PIXBUF_ERROR_FAILED, hr, _("Could not create stream: %s")); return FALSE; } status = GdipSaveImageToStream ((GpImage *)bitmap, streamOut, format, encoder_params); if (Ok != status) { gdip_set_error_from_gpstatus (error, GDK_PIXBUF_ERROR_FAILED, status); IStream_Release (streamOut); return FALSE; } /* seek back to the beginning of the stream */ hr = IStream_Seek (streamOut, *(LARGE_INTEGER *)&zero, STREAM_SEEK_SET, NULL); if (!SUCCEEDED (hr)) { gdip_set_error_from_hresult (error, GDK_PIXBUF_ERROR_FAILED, hr, _("Could not seek stream: %s")); IStream_Release (streamOut); return FALSE; } for (;;) { char buffer[LOAD_BUFFER_SIZE]; ULONG nread; hr = IStream_Read (streamOut, buffer, sizeof(buffer), &nread); if (!SUCCEEDED (hr)) { gdip_set_error_from_hresult (error, GDK_PIXBUF_ERROR_FAILED, hr, _("Could not read from stream: %s")); break; } else if (0 == nread) { success = TRUE; /* EOF */ break; } else if (!(*save_func) (buffer, nread, error, user_data)) break; } IStream_Release (streamOut); return success; }
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); }
static void rot_entry_delete(struct rot_entry *rot_entry) { if (rot_entry->cookie) { InterfaceData *object = NULL; InterfaceData *moniker = NULL; __TRY { IrotRevoke(get_irot_handle(), rot_entry->cookie, &rot_entry->ctxt_handle, &object, &moniker); } __EXCEPT(rpc_filter) { } __ENDTRY MIDL_user_free(object); if (moniker) { IStream *stream; HRESULT hr; hr = create_stream_on_mip_ro(moniker, &stream); if (hr == S_OK) { CoReleaseMarshalData(stream); IStream_Release(stream); } } MIDL_user_free(moniker); }
static void test_writeendelement(void) { static const WCHAR aW[] = {'a',0}; static const WCHAR bW[] = {'b',0}; IXmlWriter *writer; IStream *stream; HRESULT hr; hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); stream = writer_set_output(writer); hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteStartElement(writer, NULL, bW, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteEndElement(writer); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteEndElement(writer); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_Flush(writer); ok(hr == S_OK, "got 0x%08x\n", hr); CHECK_OUTPUT(stream, "<a><b /></a>"); IXmlWriter_Release(writer); IStream_Release(stream); }
static IHTMLDocument2 *create_doc_with_string(const char *str) { IPersistStreamInit *init; IStream *stream; IHTMLDocument2 *doc; HGLOBAL mem; SIZE_T len; notif_doc = doc = create_document(); if(!doc) return NULL; doc_complete = FALSE; len = strlen(str); mem = GlobalAlloc(0, len); memcpy(mem, str, len); CreateStreamOnHGlobal(mem, TRUE, &stream); IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init); IPersistStreamInit_Load(init, stream); IPersistStreamInit_Release(init); IStream_Release(stream); return doc; }
static UINT msi_dump_stream_to_file( IStream *stm, LPCWSTR name ) { ULARGE_INTEGER size; LARGE_INTEGER pos; IStream *out; DWORD stgm; HRESULT r; stgm = STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_FAILIFTHERE; r = SHCreateStreamOnFileW( name, stgm, &out ); if( FAILED( r ) ) return ERROR_FUNCTION_FAILED; pos.QuadPart = 0; r = IStream_Seek( stm, pos, STREAM_SEEK_END, &size ); if( FAILED( r ) ) goto end; pos.QuadPart = 0; r = IStream_Seek( stm, pos, STREAM_SEEK_SET, NULL ); if( FAILED( r ) ) goto end; r = IStream_CopyTo( stm, out, size, NULL, NULL ); end: IStream_Release( out ); if( FAILED( r ) ) return ERROR_FUNCTION_FAILED; return ERROR_SUCCESS; }
static HRESULT write_post_stream(Protocol *protocol) { BYTE buf[0x20000]; DWORD written; ULONG size; BOOL res; HRESULT hres; protocol->flags &= ~FLAG_REQUEST_COMPLETE; while(1) { size = 0; hres = IStream_Read(protocol->post_stream, buf, sizeof(buf), &size); if(FAILED(hres) || !size) break; res = InternetWriteFile(protocol->request, buf, size, &written); if(!res) { FIXME("InternetWriteFile failed: %u\n", GetLastError()); hres = E_FAIL; break; } } if(SUCCEEDED(hres)) { IStream_Release(protocol->post_stream); protocol->post_stream = NULL; hres = protocol->vtbl->end_request(protocol); } if(FAILED(hres)) return report_result(protocol, hres); return S_OK; }
static HRESULT WINAPI IWICStreamImpl_InitializeFromFilename(IWICStream *iface, LPCWSTR wzFileName, DWORD dwDesiredAccess) { IWICStreamImpl *This = impl_from_IWICStream(iface); HRESULT hr; DWORD dwMode; IStream *stream; TRACE("(%p, %s, %u)\n", iface, debugstr_w(wzFileName), dwDesiredAccess); if (This->pStream) return WINCODEC_ERR_WRONGSTATE; if(dwDesiredAccess & GENERIC_WRITE) dwMode = STGM_SHARE_DENY_WRITE | STGM_WRITE | STGM_CREATE; else if(dwDesiredAccess & GENERIC_READ) dwMode = STGM_SHARE_DENY_WRITE | STGM_READ | STGM_FAILIFTHERE; else return E_INVALIDARG; hr = SHCreateStreamOnFileW(wzFileName, dwMode, &stream); if (SUCCEEDED(hr)) { if (InterlockedCompareExchangePointer((void**)&This->pStream, stream, NULL)) { /* Some other thread set the stream first. */ IStream_Release(stream); hr = WINCODEC_ERR_WRONGSTATE; } } return hr; }
/****************************************** * IWICStream_InitializeFromMemory * * Initializes the internal IStream object to retrieve its data from a memory chunk. * * PARAMS * pbBuffer [I] pointer to the memory chunk * cbBufferSize [I] number of bytes to use from the memory chunk * * RETURNS * SUCCESS: S_OK * FAILURE: E_INVALIDARG, if pbBuffer is NULL * E_OUTOFMEMORY, if we run out of memory * WINCODEC_ERR_WRONGSTATE, if the IStream object has already been initialized before * */ static HRESULT WINAPI IWICStreamImpl_InitializeFromMemory(IWICStream *iface, BYTE *pbBuffer, DWORD cbBufferSize) { IWICStreamImpl *This = impl_from_IWICStream(iface); StreamOnMemory *pObject; TRACE("(%p,%p)\n", iface, pbBuffer); if (!pbBuffer) return E_INVALIDARG; if (This->pStream) return WINCODEC_ERR_WRONGSTATE; pObject = HeapAlloc(GetProcessHeap(), 0, sizeof(StreamOnMemory)); if (!pObject) return E_OUTOFMEMORY; pObject->IStream_iface.lpVtbl = &StreamOnMemory_Vtbl; pObject->ref = 1; pObject->pbMemory = pbBuffer; pObject->dwMemsize = cbBufferSize; pObject->dwCurPos = 0; InitializeCriticalSection(&pObject->lock); pObject->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": StreamOnMemory.lock"); if (InterlockedCompareExchangePointer((void**)&This->pStream, pObject, NULL)) { /* Some other thread set the stream first. */ IStream_Release(&pObject->IStream_iface); return WINCODEC_ERR_WRONGSTATE; } return S_OK; }
static IWICBitmapDecoder *create_decoder(const void *image_data, UINT image_size) { HGLOBAL hmem; BYTE *data; HRESULT hr; IWICBitmapDecoder *decoder = NULL; IStream *stream; GUID format; hmem = GlobalAlloc(0, image_size); data = GlobalLock(hmem); memcpy(data, image_data, image_size); GlobalUnlock(hmem); hr = CreateStreamOnHGlobal(hmem, TRUE, &stream); ok(hr == S_OK, "CreateStreamOnHGlobal error %#x\n", hr); hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder); ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr); hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format); ok(hr == S_OK, "GetContainerFormat error %#x\n", hr); ok(IsEqualGUID(&format, &GUID_ContainerFormatGif), "wrong container format %s\n", wine_dbgstr_guid(&format)); IStream_Release(stream); return decoder; }
static HRESULT WINAPI IWICStreamImpl_InitializeFromIStreamRegion(IWICStream *iface, IStream *pIStream, ULARGE_INTEGER ulOffset, ULARGE_INTEGER ulMaxSize) { IWICStreamImpl *This = impl_from_IWICStream(iface); StreamOnStreamRange *pObject; TRACE("(%p,%p)\n", iface, pIStream); if (!pIStream) return E_INVALIDARG; if (This->pStream) return WINCODEC_ERR_WRONGSTATE; pObject = HeapAlloc(GetProcessHeap(), 0, sizeof(StreamOnStreamRange)); if (!pObject) return E_OUTOFMEMORY; pObject->IStream_iface.lpVtbl = &StreamOnStreamRange_Vtbl; pObject->ref = 1; IStream_AddRef(pIStream); pObject->stream = pIStream; pObject->pos.QuadPart = 0; pObject->offset = ulOffset; pObject->max_size = ulMaxSize; InitializeCriticalSection(&pObject->lock); pObject->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": StreamOnStreamRange.lock"); if (InterlockedCompareExchangePointer((void**)&This->pStream, pObject, NULL)) { /* Some other thread set the stream first. */ IStream_Release(&pObject->IStream_iface); return WINCODEC_ERR_WRONGSTATE; } return S_OK; }
static DWORD WINAPI download_proc(PVOID arg) { IMoniker *mon; IBindCtx *bctx; IStream *str = NULL; HRESULT hres; CreateURLMoniker(NULL, url, &mon); heap_free(url); url = NULL; CreateAsyncBindCtx(0, &InstallCallback, 0, &bctx); hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&str); IBindCtx_Release(bctx); if(FAILED(hres)) { ERR("BindToStorage failed: %08x\n", hres); return 0; } if(str) IStream_Release(str); return 0; }
static HRESULT create_decoder(const void *image_data, UINT image_size, IWICBitmapDecoder **decoder) { HGLOBAL hmem; BYTE *data; HRESULT hr; IStream *stream; GUID format; LONG refcount; *decoder = NULL; hmem = GlobalAlloc(0, image_size); data = GlobalLock(hmem); memcpy(data, image_data, image_size); GlobalUnlock(hmem); hr = CreateStreamOnHGlobal(hmem, TRUE, &stream); ok(hr == S_OK, "CreateStreamOnHGlobal error %#x\n", hr); hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, decoder); if (hr == S_OK) { hr = IWICBitmapDecoder_GetContainerFormat(*decoder, &format); ok(hr == S_OK, "GetContainerFormat error %#x\n", hr); ok(IsEqualGUID(&format, &GUID_ContainerFormatPng), "wrong container format %s\n", wine_dbgstr_guid(&format)); refcount = IStream_Release(stream); ok(refcount > 0, "expected stream refcount > 0\n"); } return hr; }
/*********************************************************************** * NdrInterfacePointerMarshall [RPCRT4.@] */ unsigned char * WINAPI NdrInterfacePointerMarshall(PMIDL_STUB_MESSAGE pStubMsg, unsigned char *pMemory, PFORMAT_STRING pFormat) { const IID *riid = get_ip_iid(pStubMsg, pMemory, pFormat); LPSTREAM stream; HRESULT hr; TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat); pStubMsg->MaxCount = 0; if (!LoadCOM()) return NULL; if (pStubMsg->Buffer + sizeof(DWORD) <= (unsigned char *)pStubMsg->RpcMsg->Buffer + pStubMsg->BufferLength) { stream = RpcStream_Create(pStubMsg, TRUE); if (stream) { if (pMemory) hr = COM_MarshalInterface(stream, riid, (LPUNKNOWN)pMemory, pStubMsg->dwDestContext, pStubMsg->pvDestContext, MSHLFLAGS_NORMAL); else hr = S_OK; IStream_Release(stream); if (FAILED(hr)) RpcRaiseException(hr); } } return NULL; }
static ULONG WINAPI Binding_Release(IBinding* iface) { Binding *This = (Binding*)iface; ULONG ref = InterlockedDecrement(&This->ref); TRACE("(%p) ref=%d\n",This, ref); if(!ref) { heap_free(This->URLName); if (This->hCacheFile) CloseHandle(This->hCacheFile); if (This->pstrCache) { UMCloseCacheFileStream(This->pstrCache); IStream_Release((IStream *)This->pstrCache); } if (This->pbscb) IBindStatusCallback_Release(This->pbscb); heap_free(This); URLMON_UnlockModule(); } return ref; }
static inline HRESULT report_data(BindStatusCallback *This) { FORMATETC formatetc = {0, NULL, 1, -1, TYMED_ISTREAM}; STGMEDIUM stgmedium; LARGE_INTEGER off; ULARGE_INTEGER size; HRESULT hres; off.QuadPart = 0; hres = IStream_Seek(This->stream, off, STREAM_SEEK_CUR, &size); if(FAILED(hres)) return hres; hres = IStream_Seek(This->stream, off, STREAM_SEEK_SET, NULL); if(FAILED(hres)) return hres; stgmedium.tymed = TYMED_ISTREAM; stgmedium.u.pstm = This->stream; stgmedium.pUnkForRelease = NULL; hres = IBindStatusCallback_OnDataAvailable(This->bsc, BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION, size.u.LowPart, &formatetc, &stgmedium); IStream_Release(This->stream); This->stream = NULL; return hres; }
void WINAPI IDirectMusicLoaderGenericStream_Detach (LPSTREAM iface) { ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface); if (This->pStream) IStream_Release (This->pStream); This->pStream = NULL; }
/* helper: called for VT_DISPATCH variants to marshal the IDispatch* into the buffer. returns Buffer on failure, new position otherwise */ static unsigned char* interface_variant_marshal(unsigned long *pFlags, unsigned char *Buffer, REFIID riid, VARIANT *pvar) { IStream *working; HGLOBAL working_mem; void *working_memlocked; unsigned char *oldpos; ULONG size; HRESULT hr; TRACE("pFlags=%ld, Buffer=%p, pvar=%p\n", *pFlags, Buffer, pvar); oldpos = Buffer; /* CoMarshalInterface needs a stream, whereas at this level we are operating in terms of buffers. * We create a stream on an HGLOBAL, so we can simply do a memcpy to move it to the buffer. * in rpcrt4/ndr_ole.c, a simple IStream implementation is wrapped around the buffer object, * but that would be overkill here, hence this implementation. We save the size because the unmarshal * code has no way to know how long the marshalled buffer is. */ size = wire_extra_user_size(pFlags, 0, pvar); working_mem = GlobalAlloc(0, size); if (!working_mem) return oldpos; hr = CreateStreamOnHGlobal(working_mem, TRUE, &working); if (hr != S_OK) { GlobalFree(working_mem); return oldpos; } hr = CoMarshalInterface(working, riid, V_UNKNOWN(pvar), LOWORD(*pFlags), NULL, MSHLFLAGS_NORMAL); if (hr != S_OK) { IStream_Release(working); /* this also releases the hglobal */ return oldpos; } working_memlocked = GlobalLock(working_mem); memcpy(Buffer, &size, sizeof(ULONG)); /* copy the buffersize */ memcpy(Buffer + sizeof(ULONG), working_memlocked, size - sizeof(ULONG)); GlobalUnlock(working_mem); IStream_Release(working); /* size includes the ULONG for the size written above */ TRACE("done, size=%ld\n", size); return Buffer + size; }
static void SMTPTransport_CallbackMessageSendDOT(IInternetTransport *iface, char *pBuffer, int cbBuffer) { SMTPTransport *This = (SMTPTransport *)iface; IStream_Release(This->pending_message.pstmMsg); InternetTransport_DoCommand(&This->InetTransport, "\n.\n", SMTPTransport_CallbackMessageReadResponse); }
static void Binding_CloseCacheDownload(Binding *This) { CloseHandle(This->hCacheFile); This->hCacheFile = 0; UMCloseCacheFileStream(This->pstrCache); IStream_Release((IStream *)This->pstrCache); This->pstrCache = 0; }
static void test_read_xmldeclaration(void) { IXmlReader *reader; IStream *stream; HRESULT hr; XmlNodeType type; UINT count = 0; hr = pCreateXmlReader(&IID_IXmlReader, (LPVOID*)&reader, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* position methods with Null args */ hr = IXmlReader_GetLineNumber(reader, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); hr = IXmlReader_GetLinePosition(reader, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); stream = create_stream_on_data(xmldecl_full, sizeof(xmldecl_full)); hr = IXmlReader_SetInput(reader, (IUnknown*)stream); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok_pos(reader, 0, 0, -1, -1, FALSE); type = -1; hr = IXmlReader_Read(reader, &type); todo_wine { ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(type == XmlNodeType_XmlDeclaration, "Expected XmlNodeType_XmlDeclaration, got %s\n", type_to_str(type)); } /* new version 1.2.x and 1.3.x properly update postition for <?xml ?> */ ok_pos(reader, 1, 3, -1, 55, TRUE); /* check attributes */ hr = IXmlReader_MoveToNextAttribute(reader); todo_wine ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok_pos(reader, 1, 7, -1, 55, TRUE); hr = IXmlReader_MoveToFirstAttribute(reader); todo_wine ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok_pos(reader, 1, 7, -1, 55, TRUE); hr = IXmlReader_GetAttributeCount(reader, &count); todo_wine { ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(count == 3, "Expected 3, got %d\n", count); } hr = IXmlReader_GetDepth(reader, &count); todo_wine { ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(count == 1, "Expected 1, got %d\n", count); } IStream_Release(stream); IXmlReader_Release(reader); }
static HRESULT WINAPI CFProxy_CreateInstance( LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter,/* [in] */ REFIID riid, /* [in] */ LPVOID *ppv /* [out] */ ) { ICOM_THIS_MULTI(CFProxy,lpvtbl_cf,iface); HRESULT hres; LPSTREAM pStream; HGLOBAL hGlobal; ULONG srstatus; RPCOLEMESSAGE msg; TRACE("(%p,%s,%p)\n",pUnkOuter,debugstr_guid(riid),ppv); /* Send CreateInstance to the remote classfactory. * * Data: Only the 'IID'. */ msg.iMethod = 3; msg.cbBuffer = sizeof(*riid); msg.Buffer = NULL; hres = IRpcChannelBuffer_GetBuffer(This->chanbuf,&msg,&IID_IClassFactory); if (hres) { FIXME("IRpcChannelBuffer_GetBuffer failed with %lx?\n",hres); return hres; } memcpy(msg.Buffer,riid,sizeof(*riid)); hres = IRpcChannelBuffer_SendReceive(This->chanbuf,&msg,&srstatus); if (hres) { FIXME("IRpcChannelBuffer_SendReceive failed with %lx?\n",hres); return hres; } if (!msg.cbBuffer) /* interface not found on remote */ return srstatus; /* We got back: [Marshalled Interface data] */ TRACE("got %ld bytes data.\n",msg.cbBuffer); hGlobal = GlobalAlloc(GMEM_MOVEABLE|GMEM_NODISCARD|GMEM_SHARE,msg.cbBuffer); memcpy(GlobalLock(hGlobal),msg.Buffer,msg.cbBuffer); hres = CreateStreamOnHGlobal(hGlobal,TRUE,&pStream); if (hres) { FIXME("CreateStreamOnHGlobal failed with %lx\n",hres); return hres; } hres = CoUnmarshalInterface( pStream, riid, ppv ); IStream_Release(pStream); /* Does GlobalFree hGlobal too. */ if (hres) { FIXME("CoMarshalInterface failed, %lx\n",hres); return hres; } return S_OK; }
static void test_writeenddocument(void) { static const WCHAR aW[] = {'a',0}; static const WCHAR bW[] = {'b',0}; IXmlWriter *writer; IStream *stream; HGLOBAL hglobal; HRESULT hr; char *ptr; hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); hr = IXmlWriter_WriteEndDocument(writer); ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr); stream = writer_set_output(writer); /* WriteEndDocument resets it to initial state */ hr = IXmlWriter_WriteEndDocument(writer); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); hr = IXmlWriter_WriteEndDocument(writer); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Omit); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); hr = IXmlWriter_SetOutput(writer, (IUnknown*)stream); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteStartElement(writer, NULL, aW, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteStartElement(writer, NULL, bW, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteEndDocument(writer); ok(hr == S_OK, "got 0x%08x\n", hr); hr = GetHGlobalFromStream(stream, &hglobal); ok(hr == S_OK, "got 0x%08x\n", hr); ptr = GlobalLock(hglobal); ok(ptr == NULL, "got %p\n", ptr); /* we still need to flush manually, WriteEndDocument doesn't do that */ hr = IXmlWriter_Flush(writer); ok(hr == S_OK, "got 0x%08x\n", hr); CHECK_OUTPUT(stream, "<a><b /></a>"); IXmlWriter_Release(writer); IStream_Release(stream); }
static HRESULT WINAPI mxwriter_put_output(IMXWriter *iface, VARIANT dest) { mxwriter *This = impl_from_IMXWriter( iface ); HRESULT hr; TRACE("(%p)->(%s)\n", This, debugstr_variant(&dest)); hr = flush_output_buffer(This); if (FAILED(hr)) return hr; switch (V_VT(&dest)) { case VT_EMPTY: { if (This->dest) IStream_Release(This->dest); This->dest = NULL; reset_output_buffer(This); break; } case VT_UNKNOWN: { IStream *stream; hr = IUnknown_QueryInterface(V_UNKNOWN(&dest), &IID_IStream, (void**)&stream); if (hr == S_OK) { /* Recreate the output buffer to make sure it's using the correct encoding. */ reset_output_buffer(This); if (This->dest) IStream_Release(This->dest); This->dest = stream; break; } FIXME("unhandled interface type for VT_UNKNOWN destination\n"); return E_NOTIMPL; } default: FIXME("unhandled destination type %s\n", debugstr_variant(&dest)); return E_NOTIMPL; } return S_OK; }
static void test_WriteRaw(void) { static const WCHAR rawW[] = {'a','<',':',0}; static const WCHAR aW[] = {'a',0}; IXmlWriter *writer; IStream *stream; HRESULT hr; hr = CreateXmlWriter(&IID_IXmlWriter, (void**)&writer, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); hr = IXmlWriter_WriteRaw(writer, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteRaw(writer, rawW); ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr); stream = writer_set_output(writer); hr = IXmlWriter_WriteRaw(writer, NULL); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteRaw(writer, rawW); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteRaw(writer, rawW); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteComment(writer, rawW); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteRaw(writer, rawW); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteElementString(writer, NULL, aW, NULL, aW); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IXmlWriter_WriteStartDocument(writer, XmlStandalone_Yes); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); hr = IXmlWriter_WriteComment(writer, rawW); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); hr = IXmlWriter_WriteEndDocument(writer); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); hr = IXmlWriter_WriteRaw(writer, rawW); ok(hr == WR_E_INVALIDACTION, "got 0x%08x\n", hr); hr = IXmlWriter_Flush(writer); ok(hr == S_OK, "got 0x%08x\n", hr); CHECK_OUTPUT(stream, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>a<:a<:<!--a<:-->a<:<a>a</a>"); IXmlWriter_Release(writer); IStream_Release(stream); }
/* helper: called for VT_DISPATCH / VT_UNKNOWN variants to unmarshal the buffer. returns Buffer on failure, new position otherwise */ static unsigned char *interface_variant_unmarshal(unsigned long *pFlags, unsigned char *Buffer, REFIID riid, VARIANT *pvar) { IStream *working; HGLOBAL working_mem; void *working_memlocked; unsigned char *oldpos; ULONG size; HRESULT hr; TRACE("pFlags=%ld, Buffer=%p, pvar=%p\n", *pFlags, Buffer, pvar); oldpos = Buffer; /* get the buffersize */ memcpy(&size, Buffer, sizeof(ULONG)); TRACE("buffersize=%ld\n", size); working_mem = GlobalAlloc(0, size); if (!working_mem) return oldpos; hr = CreateStreamOnHGlobal(working_mem, TRUE, &working); if (hr != S_OK) { GlobalFree(working_mem); return oldpos; } working_memlocked = GlobalLock(working_mem); /* now we copy the contents of the marshalling buffer to working_memlocked, unlock it, and demarshal the stream */ memcpy(working_memlocked, Buffer + sizeof(ULONG), size); GlobalUnlock(working_mem); hr = CoUnmarshalInterface(working, riid, (void**)&V_UNKNOWN(pvar)); if (hr != S_OK) { IStream_Release(working); return oldpos; } IStream_Release(working); /* this also frees the underlying hglobal */ /* size includes the ULONG for the size written above */ TRACE("done, processed=%ld bytes\n", size); return Buffer + size; }
static void test_create_reader(void) { HRESULT hr; IWICComponentFactory *factory; IStream *stream; IWICMetadataReader *reader; UINT count=0; GUID format; hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICComponentFactory, (void**)&factory); todo_wine ok(hr == S_OK, "CoCreateInstance failed, hr=%x\n", hr); if (FAILED(hr)) return; stream = create_stream(metadata_tEXt, sizeof(metadata_tEXt)); hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory, &GUID_ContainerFormatPng, NULL, WICPersistOptionsDefault, stream, &reader); ok(hr == S_OK, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr); if (SUCCEEDED(hr)) { hr = IWICMetadataReader_GetCount(reader, &count); ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); ok(count == 1, "unexpected count %i\n", count); hr = IWICMetadataReader_GetMetadataFormat(reader, &format); ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr); ok(IsEqualGUID(&format, &GUID_MetadataFormatChunktEXt), "unexpected format %s\n", debugstr_guid(&format)); IWICMetadataReader_Release(reader); } hr = IWICComponentFactory_CreateMetadataReaderFromContainer(factory, &GUID_ContainerFormatWmp, NULL, WICPersistOptionsDefault, stream, &reader); ok(hr == S_OK, "CreateMetadataReaderFromContainer failed, hr=%x\n", hr); if (SUCCEEDED(hr)) { hr = IWICMetadataReader_GetCount(reader, &count); ok(hr == S_OK, "GetCount failed, hr=%x\n", hr); ok(count == 1, "unexpected count %i\n", count); hr = IWICMetadataReader_GetMetadataFormat(reader, &format); ok(hr == S_OK, "GetMetadataFormat failed, hr=%x\n", hr); ok(IsEqualGUID(&format, &GUID_MetadataFormatUnknown), "unexpected format %s\n", debugstr_guid(&format)); IWICMetadataReader_Release(reader); } IStream_Release(stream); IWICComponentFactory_Release(factory); }
static void test_CreateVirtualStream(void) { HRESULT hr; IStream *pstm; hr = MimeOleCreateVirtualStream(&pstm); ok(hr == S_OK, "ret %08x\n", hr); IStream_Release(pstm); }