From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dmloader/Makefile.in | 2 +- dlls/dmloader/dmloader_private.h | 20 --- dlls/dmloader/loader.c | 54 +++----- dlls/dmloader/loaderstream.c | 217 ------------------------------- 4 files changed, 18 insertions(+), 275 deletions(-)
diff --git a/dlls/dmloader/Makefile.in b/dlls/dmloader/Makefile.in index a8d3698ab6c..51f171b6286 100644 --- a/dlls/dmloader/Makefile.in +++ b/dlls/dmloader/Makefile.in @@ -1,5 +1,5 @@ MODULE = dmloader.dll -IMPORTS = dxguid uuid ole32 advapi32 +IMPORTS = dxguid uuid ole32 advapi32 shcore PARENTSRC = ../dmusic
C_SRCS = \ diff --git a/dlls/dmloader/dmloader_private.h b/dlls/dmloader/dmloader_private.h index 87fcf087bc0..2b3603dc94b 100644 --- a/dlls/dmloader/dmloader_private.h +++ b/dlls/dmloader/dmloader_private.h @@ -60,7 +60,6 @@ typedef struct IDirectMusicLoaderGenericStream IDirectMusicLoaderGenericStream; extern HRESULT create_dmloader(REFIID riid, void **ret_iface); extern HRESULT create_dmcontainer(REFIID riid, void **ret_iface); extern HRESULT DMUSIC_CreateDirectMusicLoaderFileStream(void **ppobj); -extern HRESULT DMUSIC_CreateDirectMusicLoaderResourceStream(void **ppobj);
/***************************************************************************** * IDirectMusicLoaderFileStream implementation structure @@ -78,25 +77,6 @@ struct IDirectMusicLoaderFileStream { /* Custom: */ extern HRESULT WINAPI IDirectMusicLoaderFileStream_Attach(LPSTREAM iface, LPCWSTR wzFile);
-/***************************************************************************** - * IDirectMusicLoaderResourceStream implementation structure - */ -struct IDirectMusicLoaderResourceStream { - /* IUnknown fields */ - const IStreamVtbl *StreamVtbl; - /* reference counter */ - LONG dwRef; - /* data */ - LPBYTE pbMemData; - LONGLONG llMemLength; - /* current position */ - LONGLONG llPos; -}; - -/* Custom: */ -extern HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach(LPSTREAM iface, LPBYTE pbMemData, - LONGLONG llMemLength, LONGLONG llPos); - extern HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream, IStream **ret_iface);
#include "debug.h" diff --git a/dlls/dmloader/loader.c b/dlls/dmloader/loader.c index ef1a8c3dfe0..7d5132a34a6 100644 --- a/dlls/dmloader/loader.c +++ b/dlls/dmloader/loader.c @@ -18,6 +18,8 @@
#include "dmloader_private.h"
+#include "shlwapi.h" + WINE_DEFAULT_DEBUG_CHANNEL(dmloader);
static const GUID *classes[] = { @@ -339,23 +341,11 @@ static HRESULT WINAPI loader_GetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE return result; } } - else if (pDesc->dwValidData & DMUS_OBJ_MEMORY) { - /* load object from resource */ - TRACE(": loading from resource\n"); - /* create stream and associate it with given resource */ - result = DMUSIC_CreateDirectMusicLoaderResourceStream ((LPVOID*)&pStream); - if (FAILED(result)) { - ERR(": could not create resource stream\n"); - return result; - } - result = IDirectMusicLoaderResourceStream_Attach(pStream, pDesc->pbMemData, pDesc->llMemLength, 0); - if (FAILED(result)) - { - ERR(": could not attach stream to resource\n"); - IStream_Release (pStream); - return result; - } - } + else if (pDesc->dwValidData & DMUS_OBJ_MEMORY) + { + pStream = SHCreateMemStream(pDesc->pbMemData, pDesc->llMemLength); + if (!pStream) return E_OUTOFMEMORY; + } else if (pDesc->dwValidData & DMUS_OBJ_STREAM) { pStream = pDesc->pStream; @@ -494,26 +484,16 @@ static HRESULT WINAPI loader_SetObject(IDirectMusicLoader8 *iface, DMUS_OBJECTDE pStream = pDesc->pStream; IStream_AddRef(pStream); } - else if (pDesc->dwValidData & DMUS_OBJ_MEMORY) { - /* create stream */ - hr = DMUSIC_CreateDirectMusicLoaderResourceStream ((LPVOID*)&pStream); - if (FAILED(hr)) { - ERR(": could not create resource stream\n"); - return DMUS_E_LOADER_FAILEDOPEN; - } - /* attach stream */ - hr = IDirectMusicLoaderResourceStream_Attach(pStream, pDesc->pbMemData, pDesc->llMemLength, 0); - if (FAILED(hr)) - { - ERR(": could not attach stream to resource\n"); - IStream_Release (pStream); - return DMUS_E_LOADER_FAILEDOPEN; - } - } - else { - ERR(": no way to get additional info\n"); - return DMUS_E_LOADER_FAILEDOPEN; - } + else if (pDesc->dwValidData & DMUS_OBJ_MEMORY) + { + pStream = SHCreateMemStream(pDesc->pbMemData, pDesc->llMemLength); + if (!pStream) return E_OUTOFMEMORY; + } + else + { + ERR(": no way to get additional info\n"); + return DMUS_E_LOADER_FAILEDOPEN; + }
if (FAILED(hr = loader_stream_create((IDirectMusicLoader *)iface, pStream, &loader_stream))) return hr; diff --git a/dlls/dmloader/loaderstream.c b/dlls/dmloader/loaderstream.c index 5b7862c16f8..b7130065e32 100644 --- a/dlls/dmloader/loaderstream.c +++ b/dlls/dmloader/loaderstream.c @@ -285,7 +285,6 @@ HRESULT loader_stream_create(IDirectMusicLoader *loader, IStream *stream, }
static ULONG WINAPI IDirectMusicLoaderFileStream_IStream_AddRef (LPSTREAM iface); -static ULONG WINAPI IDirectMusicLoaderResourceStream_IStream_AddRef (LPSTREAM iface);
/***************************************************************************** @@ -493,219 +492,3 @@ HRESULT DMUSIC_CreateDirectMusicLoaderFileStream (void** ppobj) {
return IDirectMusicLoaderFileStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj); } - - -/***************************************************************************** - * IDirectMusicLoaderResourceStream implementation - */ -/* Custom : */ - -static void IDirectMusicLoaderResourceStream_Detach (LPSTREAM iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - TRACE("(%p)\n", This); - - This->pbMemData = NULL; - This->llMemLength = 0; -} - -HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach (LPSTREAM iface, LPBYTE pbMemData, LONGLONG llMemLength, LONGLONG llPos) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - - TRACE("(%p, %p, %s, %s)\n", This, pbMemData, wine_dbgstr_longlong(llMemLength), wine_dbgstr_longlong(llPos)); - if (!pbMemData || !llMemLength) { - WARN(": invalid pbMemData or llMemLength\n"); - return E_FAIL; - } - IDirectMusicLoaderResourceStream_Detach (iface); - This->pbMemData = pbMemData; - This->llMemLength = llMemLength; - This->llPos = llPos; - - return S_OK; -} - - -/* IUnknown/IStream part: */ -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_QueryInterface (LPSTREAM iface, REFIID riid, void** ppobj) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - - TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj); - if (IsEqualIID (riid, &IID_IUnknown) || - IsEqualIID (riid, &IID_IStream)) { - *ppobj = &This->StreamVtbl; - IDirectMusicLoaderResourceStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl); - return S_OK; - } - - WARN(": not found\n"); - return E_NOINTERFACE; -} - -static ULONG WINAPI IDirectMusicLoaderResourceStream_IStream_AddRef (LPSTREAM iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - TRACE("(%p): AddRef from %ld\n", This, This->dwRef); - return InterlockedIncrement (&This->dwRef); -} - -static ULONG WINAPI IDirectMusicLoaderResourceStream_IStream_Release (LPSTREAM iface) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - - DWORD dwRef = InterlockedDecrement (&This->dwRef); - TRACE("(%p): ReleaseRef to %ld\n", This, dwRef); - if (dwRef == 0) { - IDirectMusicLoaderResourceStream_Detach (iface); - free(This); - } - - return dwRef; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Read (LPSTREAM iface, void* pv, ULONG cb, ULONG* pcbRead) { - LPBYTE pByte; - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - - TRACE_(dmfileraw)("(%p, %p, %#lx, %p)\n", This, pv, cb, pcbRead); - if ((This->llPos + cb) > This->llMemLength) { - WARN_(dmfileraw)(": requested size out of range\n"); - return E_FAIL; - } - - pByte = &This->pbMemData[This->llPos]; - memcpy (pv, pByte, cb); - This->llPos += cb; /* move pointer */ - /* FIXME: error checking would be nice */ - if (pcbRead) *pcbRead = cb; - - TRACE_(dmfileraw)(": data (size = %#lx): %s\n", cb, debugstr_an(pv, cb)); - return S_OK; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Seek (LPSTREAM iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - TRACE_(dmfileraw)("(%p, %s, %s, %p)\n", This, wine_dbgstr_longlong(dlibMove.QuadPart), resolve_STREAM_SEEK(dwOrigin), plibNewPosition); - - switch (dwOrigin) { - case STREAM_SEEK_CUR: { - if ((This->llPos + dlibMove.QuadPart) > This->llMemLength) { - WARN_(dmfileraw)(": requested offset out of range\n"); - return E_FAIL; - } - break; - } - case STREAM_SEEK_SET: { - if (dlibMove.QuadPart > This->llMemLength) { - WARN_(dmfileraw)(": requested offset out of range\n"); - return E_FAIL; - } - /* set to the beginning of the stream */ - This->llPos = 0; - break; - } - case STREAM_SEEK_END: { - /* TODO: check if this is true... I do think offset should be negative in this case */ - if (dlibMove.QuadPart > 0) { - WARN_(dmfileraw)(": requested offset out of range\n"); - return E_FAIL; - } - /* set to the end of the stream */ - This->llPos = This->llMemLength; - break; - } - default: { - ERR_(dmfileraw)(": invalid dwOrigin\n"); - return E_FAIL; - } - } - /* now simply add */ - This->llPos += dlibMove.QuadPart; - - if (plibNewPosition) plibNewPosition->QuadPart = This->llPos; - - return S_OK; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Clone (LPSTREAM iface, IStream** ppstm) { - ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface); - LPSTREAM pOther = NULL; - HRESULT result; - - TRACE("(%p, %p)\n", iface, ppstm); - result = DMUSIC_CreateDirectMusicLoaderResourceStream ((LPVOID*)&pOther); - if (FAILED(result)) return result; - - IDirectMusicLoaderResourceStream_Attach (pOther, This->pbMemData, This->llMemLength, This->llPos); - - TRACE(": succeeded\n"); - *ppstm = pOther; - return S_OK; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Write (LPSTREAM iface, const void* pv, ULONG cb, ULONG* pcbWritten) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_SetSize (LPSTREAM iface, ULARGE_INTEGER libNewSize) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_CopyTo (LPSTREAM iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Commit (LPSTREAM iface, DWORD grfCommitFlags) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Revert (LPSTREAM iface) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_LockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_UnlockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Stat (LPSTREAM iface, STATSTG* pstatstg, DWORD grfStatFlag) { - ERR(": should not be needed\n"); - return E_NOTIMPL; -} - -static const IStreamVtbl DirectMusicLoaderResourceStream_Stream_Vtbl = { - IDirectMusicLoaderResourceStream_IStream_QueryInterface, - IDirectMusicLoaderResourceStream_IStream_AddRef, - IDirectMusicLoaderResourceStream_IStream_Release, - IDirectMusicLoaderResourceStream_IStream_Read, - IDirectMusicLoaderResourceStream_IStream_Write, - IDirectMusicLoaderResourceStream_IStream_Seek, - IDirectMusicLoaderResourceStream_IStream_SetSize, - IDirectMusicLoaderResourceStream_IStream_CopyTo, - IDirectMusicLoaderResourceStream_IStream_Commit, - IDirectMusicLoaderResourceStream_IStream_Revert, - IDirectMusicLoaderResourceStream_IStream_LockRegion, - IDirectMusicLoaderResourceStream_IStream_UnlockRegion, - IDirectMusicLoaderResourceStream_IStream_Stat, - IDirectMusicLoaderResourceStream_IStream_Clone -}; - -HRESULT DMUSIC_CreateDirectMusicLoaderResourceStream (void** ppobj) { - IDirectMusicLoaderResourceStream *obj; - - TRACE("(%p)\n", ppobj); - - *ppobj = NULL; - if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; - obj->StreamVtbl = &DirectMusicLoaderResourceStream_Stream_Vtbl; - obj->dwRef = 0; /* will be inited with QueryInterface */ - - return IDirectMusicLoaderResourceStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj); -}