1 /* IDirectMusicLoaderFileStream
2 * IDirectMusicLoaderResourceStream
3 * IDirectMusicLoaderGenericStream
5 * Copyright (C) 2003-2004 Rok Mandeljc
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * After extensive testing and structure dumping I came to a conclusion that
25 * DirectMusic as in present state implements three types of streams:
26 * 1. IDirectMusicLoaderFileStream: stream that was most obvious, since
27 * it's used for loading from files; it is sort of wrapper around
28 * CreateFile, ReadFile, WriteFile and SetFilePointer and it supports
30 * 2. IDirectMusicLoaderResourceStream: a stream that had to exist, since
31 * according to MSDN, IDirectMusicLoader supports loading from resource
32 * as well; in this case, data is represented as a big chunk of bytes,
33 * from which we "read" (copy) data and keep the trace of our position;
34 * it supports read only
35 * 3. IDirectMusicLoaderGenericStream: this one was the most problematic,
36 * since I thought it was URL-related; besides, there's no obvious need
37 * for it, since input streams can simply be cloned, lest loading from
38 * stream is requested; but if one really thinks about it, input stream
39 * could be none of 1. or 2.; in this case, a wrapper that offers
40 * IDirectMusicGetLoader interface would be nice, and this is what this
41 * stream is; as such, all functions are supported, as long as underlying
42 * ("low-level") stream supports them
44 * - Rok Mandeljc; 24. april, 2004
47 #define NONAMELESSUNION
48 #define NONAMELESSSTRUCT
50 #include "dmloader_private.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(dmloader);
53 WINE_DECLARE_DEBUG_CHANNEL(dmfileraw);
55 /*****************************************************************************
56 * IDirectMusicLoaderFileStream implementation
59 HRESULT WINAPI IDirectMusicLoaderFileStream_Attach (LPSTREAM iface, LPCWSTR wzFile, LPDIRECTMUSICLOADER pLoader) {
60 ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface);
61 TRACE("(%p, %s, %p)\n", This, debugstr_w(wzFile), pLoader);
62 IDirectMusicLoaderFileStream_Detach (iface);
63 This->hFile = CreateFileW (wzFile, (GENERIC_READ | GENERIC_WRITE), (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
64 if (This->hFile == INVALID_HANDLE_VALUE) {
66 return DMUS_E_LOADER_FAILEDOPEN;
68 /* create IDirectMusicGetLoader */
69 (LPDIRECTMUSICLOADER) This->pLoader = pLoader;
70 strncpyW (This->wzFileName, wzFile, MAX_PATH);
71 TRACE(": succeeded\n");
75 void WINAPI IDirectMusicLoaderFileStream_Detach (LPSTREAM iface) {
76 ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface);
77 TRACE("(%p)\n", This);
78 if (This->hFile != INVALID_HANDLE_VALUE) {
79 CloseHandle(This->hFile);
81 This->wzFileName[0] = (L'\0');
85 /* IUnknown/IStream part: */
86 HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_QueryInterface (LPSTREAM iface, REFIID riid, void** ppobj) {
87 ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface);
89 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
90 if (IsEqualIID (riid, &IID_IUnknown) ||
91 IsEqualIID (riid, &IID_IStream)) {
92 *ppobj = (LPVOID)&This->StreamVtbl;
93 IDirectMusicLoaderFileStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl);
95 } else if (IsEqualIID (riid, &IID_IDirectMusicGetLoader)) {
96 *ppobj = (LPVOID)&This->GetLoaderVtbl;
97 IDirectMusicLoaderFileStream_IDirectMusicGetLoader_AddRef ((LPDIRECTMUSICGETLOADER)&This->GetLoaderVtbl);
101 WARN(": not found\n");
102 return E_NOINTERFACE;
105 ULONG WINAPI IDirectMusicLoaderFileStream_IStream_AddRef (LPSTREAM iface) {
106 ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface);
107 TRACE("(%p): AddRef from %ld\n", This, This->dwRef);
108 return InterlockedIncrement (&This->dwRef);
111 ULONG WINAPI IDirectMusicLoaderFileStream_IStream_Release (LPSTREAM iface) {
112 ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface);
114 DWORD dwRef = InterlockedDecrement (&This->dwRef);
115 TRACE("(%p): ReleaseRef to %ld\n", This, dwRef);
117 DMUSIC_DestroyDirectMusicLoaderFileStream (iface);
123 HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Read (LPSTREAM iface, void* pv, ULONG cb, ULONG* pcbRead) {
124 ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface);
127 TRACE_(dmfileraw)("(%p, %p, 0x%08lX, %p)\n", This, pv, cb, pcbRead);
128 if (This->hFile == INVALID_HANDLE_VALUE) return E_FAIL;
129 if (pcbRead == NULL) pcbRead = &cbRead;
130 if (!ReadFile (This->hFile, pv, cb, pcbRead, NULL) || *pcbRead != cb) return E_FAIL;
132 TRACE_(dmfileraw)(": data (size = 0x%08lX): '%s'\n", *pcbRead, debugstr_an(pv, *pcbRead));
136 HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Seek (LPSTREAM iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) {
137 ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface);
138 LARGE_INTEGER liNewPos;
140 TRACE_(dmfileraw)("(%p, 0x%08llX, %s, %p)\n", This, dlibMove.QuadPart, resolve_STREAM_SEEK(dwOrigin), plibNewPosition);
142 if (This->hFile == INVALID_HANDLE_VALUE) return E_FAIL;
144 liNewPos.u.HighPart = dlibMove.u.HighPart;
145 liNewPos.u.LowPart = SetFilePointer (This->hFile, dlibMove.u.LowPart, &liNewPos.u.HighPart, dwOrigin);
147 if (liNewPos.u.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) return E_FAIL;
148 if (plibNewPosition) plibNewPosition->QuadPart = liNewPos.QuadPart;
153 HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Clone (LPSTREAM iface, IStream** ppstm) {
154 ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface);
155 LPSTREAM pOther = NULL;
158 TRACE("(%p, %p)\n", iface, ppstm);
159 result = DMUSIC_CreateDirectMusicLoaderFileStream ((LPVOID*)&pOther);
160 if (FAILED(result)) return result;
161 if (This->hFile != INVALID_HANDLE_VALUE) {
162 ULARGE_INTEGER ullCurrentPosition;
163 result = IDirectMusicLoaderFileStream_Attach (pOther, This->wzFileName, (LPDIRECTMUSICLOADER)This->pLoader);
164 if (SUCCEEDED(result)) {
165 LARGE_INTEGER liZero;
167 result = IDirectMusicLoaderFileStream_IStream_Seek (iface, liZero, STREAM_SEEK_CUR, &ullCurrentPosition); /* get current position in current stream */
169 if (SUCCEEDED(result)) {
170 LARGE_INTEGER liNewPosition;
171 liNewPosition.QuadPart = ullCurrentPosition.QuadPart;
172 result = IDirectMusicLoaderFileStream_IStream_Seek ((LPSTREAM)pOther, liNewPosition, STREAM_SEEK_SET, &ullCurrentPosition);
174 if (FAILED(result)) {
176 IDirectMusicLoaderFileStream_IStream_Release ((LPSTREAM)pOther);
180 TRACE(": succeeded\n");
181 *ppstm = (IStream*)pOther;
185 HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Write (LPSTREAM iface, const void* pv, ULONG cb, ULONG* pcbWritten) {
186 ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface);
189 TRACE_(dmfileraw)("(%p, %p, 0x%08lX, %p)\n", This, pv, cb, pcbWritten);
190 if (This->hFile == INVALID_HANDLE_VALUE) return E_FAIL;
191 if (pcbWritten == NULL) pcbWritten = &cbWrite;
192 if (!WriteFile (This->hFile, pv, cb, pcbWritten, NULL) || *pcbWritten != cb) return E_FAIL;
194 TRACE_(dmfileraw)(": data (size = 0x%08lX): '%s'\n", *pcbWritten, debugstr_an(pv, *pcbWritten));
198 HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_SetSize (LPSTREAM iface, ULARGE_INTEGER libNewSize) {
199 ERR(": should not be needed\n");
203 HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_CopyTo (LPSTREAM iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten) {
204 ERR(": should not be needed\n");
208 HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Commit (LPSTREAM iface, DWORD grfCommitFlags) {
209 ERR(": should not be needed\n");
213 HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Revert (LPSTREAM iface) {
214 ERR(": should not be needed\n");
218 HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_LockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) {
219 ERR(": should not be needed\n");
223 HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_UnlockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) {
224 ERR(": should not be needed\n");
228 HRESULT WINAPI IDirectMusicLoaderFileStream_IStream_Stat (LPSTREAM iface, STATSTG* pstatstg, DWORD grfStatFlag) {
229 ERR(": should not be needed\n");
233 ICOM_VTABLE(IStream) DirectMusicLoaderFileStream_Stream_Vtbl = {
234 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
235 IDirectMusicLoaderFileStream_IStream_QueryInterface,
236 IDirectMusicLoaderFileStream_IStream_AddRef,
237 IDirectMusicLoaderFileStream_IStream_Release,
238 IDirectMusicLoaderFileStream_IStream_Read,
239 IDirectMusicLoaderFileStream_IStream_Write,
240 IDirectMusicLoaderFileStream_IStream_Seek,
241 IDirectMusicLoaderFileStream_IStream_SetSize,
242 IDirectMusicLoaderFileStream_IStream_CopyTo,
243 IDirectMusicLoaderFileStream_IStream_Commit,
244 IDirectMusicLoaderFileStream_IStream_Revert,
245 IDirectMusicLoaderFileStream_IStream_LockRegion,
246 IDirectMusicLoaderFileStream_IStream_UnlockRegion,
247 IDirectMusicLoaderFileStream_IStream_Stat,
248 IDirectMusicLoaderFileStream_IStream_Clone
251 /* IDirectMusicGetLoader part: */
252 HRESULT WINAPI IDirectMusicLoaderFileStream_IDirectMusicGetLoader_QueryInterface (LPDIRECTMUSICGETLOADER iface, REFIID riid, void** ppobj) {
253 ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, GetLoaderVtbl, iface);
254 return IDirectMusicLoaderFileStream_IStream_QueryInterface ((LPSTREAM)&This->StreamVtbl, riid, ppobj);
257 ULONG WINAPI IDirectMusicLoaderFileStream_IDirectMusicGetLoader_AddRef (LPDIRECTMUSICGETLOADER iface) {
258 ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, GetLoaderVtbl, iface);
259 return IDirectMusicLoaderFileStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl);
262 ULONG WINAPI IDirectMusicLoaderFileStream_IDirectMusicGetLoader_Release (LPDIRECTMUSICGETLOADER iface) {
263 ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, GetLoaderVtbl, iface);
264 return IDirectMusicLoaderFileStream_IStream_Release ((LPSTREAM)&This->StreamVtbl);
267 HRESULT WINAPI IDirectMusicLoaderFileStream_IDirectMusicGetLoader_GetLoader (LPDIRECTMUSICGETLOADER iface, IDirectMusicLoader **ppLoader) {
268 ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, GetLoaderVtbl, iface);
270 TRACE("(%p, %p)\n", This, ppLoader);
271 *ppLoader = (LPDIRECTMUSICLOADER)This->pLoader;
272 IDirectMusicLoader8_AddRef ((LPDIRECTMUSICLOADER8)*ppLoader);
277 ICOM_VTABLE(IDirectMusicGetLoader) DirectMusicLoaderFileStream_GetLoader_Vtbl = {
278 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
279 IDirectMusicLoaderFileStream_IDirectMusicGetLoader_QueryInterface,
280 IDirectMusicLoaderFileStream_IDirectMusicGetLoader_AddRef,
281 IDirectMusicLoaderFileStream_IDirectMusicGetLoader_Release,
282 IDirectMusicLoaderFileStream_IDirectMusicGetLoader_GetLoader
285 HRESULT WINAPI DMUSIC_CreateDirectMusicLoaderFileStream (LPVOID* ppobj) {
286 IDirectMusicLoaderFileStream *obj;
288 TRACE("(%p)\n", ppobj);
289 obj = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(IDirectMusicLoaderFileStream));
291 *ppobj = (LPVOID) NULL;
292 return E_OUTOFMEMORY;
294 obj->StreamVtbl = &DirectMusicLoaderFileStream_Stream_Vtbl;
295 obj->GetLoaderVtbl = &DirectMusicLoaderFileStream_GetLoader_Vtbl;
296 obj->dwRef = 0; /* will be inited with QueryInterface */
298 return IDirectMusicLoaderFileStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj);
301 HRESULT WINAPI DMUSIC_DestroyDirectMusicLoaderFileStream (LPSTREAM iface) {
302 ICOM_THIS_MULTI(IDirectMusicLoaderFileStream, StreamVtbl, iface);
304 TRACE("(%p)\n", iface);
306 IDirectMusicLoaderFileStream_Detach (iface);
307 HeapFree (GetProcessHeap(), 0, This);
313 /*****************************************************************************
314 * IDirectMusicLoaderResourceStream implementation
317 HRESULT WINAPI IDirectMusicLoaderResourceStream_Attach (LPSTREAM iface, LPBYTE pbMemData, LONGLONG llMemLength, LONGLONG llPos, LPDIRECTMUSICLOADER pLoader) {
318 ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface);
320 TRACE("(%p, %p, 0x%08llX, 0x%08llx, %p)\n", This, pbMemData, llMemLength, llPos, pLoader);
321 if (!pbMemData || !llMemLength) {
322 WARN(": invalid pbMemData or llMemLength\n");
325 IDirectMusicLoaderResourceStream_Detach (iface);
326 This->pbMemData = pbMemData;
327 This->llMemLength = llMemLength;
329 This->pLoader = pLoader;
334 void WINAPI IDirectMusicLoaderResourceStream_Detach (LPSTREAM iface) {
335 ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface);
336 TRACE("(%p)\n", This);
338 This->pbMemData = NULL;
339 This->llMemLength = 0;
343 /* IUnknown/IStream part: */
344 HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_QueryInterface (LPSTREAM iface, REFIID riid, void** ppobj) {
345 ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface);
347 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
348 if (IsEqualIID (riid, &IID_IUnknown) ||
349 IsEqualIID (riid, &IID_IStream)) {
350 *ppobj = (LPVOID)&This->StreamVtbl;
351 IDirectMusicLoaderResourceStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl);
353 } else if (IsEqualIID (riid, &IID_IDirectMusicGetLoader)) {
354 *ppobj = (LPVOID)&This->GetLoaderVtbl;
355 IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_AddRef ((LPDIRECTMUSICGETLOADER)&This->GetLoaderVtbl);
359 WARN(": not found\n");
360 return E_NOINTERFACE;
363 ULONG WINAPI IDirectMusicLoaderResourceStream_IStream_AddRef (LPSTREAM iface) {
364 ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface);
365 TRACE("(%p): AddRef from %ld\n", This, This->dwRef);
366 return InterlockedIncrement (&This->dwRef);
369 ULONG WINAPI IDirectMusicLoaderResourceStream_IStream_Release (LPSTREAM iface) {
370 ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface);
372 DWORD dwRef = InterlockedDecrement (&This->dwRef);
373 TRACE("(%p): ReleaseRef to %ld\n", This, dwRef);
375 DMUSIC_DestroyDirectMusicLoaderResourceStream (iface);
381 HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Read (LPSTREAM iface, void* pv, ULONG cb, ULONG* pcbRead) {
383 ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface);
385 TRACE_(dmfileraw)("(%p, %p, 0x%08lX, %p)\n", This, pv, cb, pcbRead);
386 if ((This->llPos + cb) > This->llMemLength) {
387 WARN_(dmfileraw)(": requested size out of range\n");
391 pByte = &This->pbMemData[This->llPos];
392 memcpy (pv, pByte, cb);
393 This->llPos += cb; /* move pointer */
394 /* FIXME: error checking would be nice */
397 TRACE_(dmfileraw)(": data (size = 0x%08lX): '%s'\n", *pcbRead, debugstr_an(pv, *pcbRead));
401 HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Seek (LPSTREAM iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) {
402 ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface);
403 TRACE_(dmfileraw)("(%p, 0x%08llX, %s, %p)\n", This, dlibMove.QuadPart, resolve_STREAM_SEEK(dwOrigin), plibNewPosition);
406 case STREAM_SEEK_CUR: {
407 if ((This->llPos + dlibMove.QuadPart) > This->llMemLength) {
408 WARN_(dmfileraw)(": requested offset out of range\n");
413 case STREAM_SEEK_SET: {
414 if (dlibMove.QuadPart > This->llMemLength) {
415 WARN_(dmfileraw)(": requested offset out of range\n");
418 /* set to the beginning of the stream */
422 case STREAM_SEEK_END: {
423 /* TODO: check if this is true... I do think offset should be negative in this case */
424 if (dlibMove.QuadPart > 0) {
425 WARN_(dmfileraw)(": requested offset out of range\n");
428 /* set to the end of the stream */
429 This->llPos = This->llMemLength;
433 ERR_(dmfileraw)(": invalid dwOrigin\n");
438 This->llPos += dlibMove.QuadPart;
440 if (plibNewPosition) plibNewPosition->QuadPart = This->llPos;
445 HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Clone (LPSTREAM iface, IStream** ppstm) {
446 ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface);
447 LPSTREAM pOther = NULL;
450 TRACE("(%p, %p)\n", iface, ppstm);
451 result = DMUSIC_CreateDirectMusicLoaderResourceStream ((LPVOID*)&pOther);
452 if (FAILED(result)) return result;
454 IDirectMusicLoaderResourceStream_Attach (pOther, This->pbMemData, This->llMemLength, This->llPos, This->pLoader);
456 TRACE(": succeeded\n");
457 *ppstm = (IStream*)pOther;
461 HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Write (LPSTREAM iface, const void* pv, ULONG cb, ULONG* pcbWritten) {
462 ERR(": should not be needed\n");
466 HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_SetSize (LPSTREAM iface, ULARGE_INTEGER libNewSize) {
467 ERR(": should not be needed\n");
471 HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_CopyTo (LPSTREAM iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten) {
472 ERR(": should not be needed\n");
476 HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Commit (LPSTREAM iface, DWORD grfCommitFlags) {
477 ERR(": should not be needed\n");
481 HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Revert (LPSTREAM iface) {
482 ERR(": should not be needed\n");
486 HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_LockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) {
487 ERR(": should not be needed\n");
491 HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_UnlockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) {
492 ERR(": should not be needed\n");
496 HRESULT WINAPI IDirectMusicLoaderResourceStream_IStream_Stat (LPSTREAM iface, STATSTG* pstatstg, DWORD grfStatFlag) {
497 ERR(": should not be needed\n");
501 ICOM_VTABLE(IStream) DirectMusicLoaderResourceStream_Stream_Vtbl = {
502 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
503 IDirectMusicLoaderResourceStream_IStream_QueryInterface,
504 IDirectMusicLoaderResourceStream_IStream_AddRef,
505 IDirectMusicLoaderResourceStream_IStream_Release,
506 IDirectMusicLoaderResourceStream_IStream_Read,
507 IDirectMusicLoaderResourceStream_IStream_Write,
508 IDirectMusicLoaderResourceStream_IStream_Seek,
509 IDirectMusicLoaderResourceStream_IStream_SetSize,
510 IDirectMusicLoaderResourceStream_IStream_CopyTo,
511 IDirectMusicLoaderResourceStream_IStream_Commit,
512 IDirectMusicLoaderResourceStream_IStream_Revert,
513 IDirectMusicLoaderResourceStream_IStream_LockRegion,
514 IDirectMusicLoaderResourceStream_IStream_UnlockRegion,
515 IDirectMusicLoaderResourceStream_IStream_Stat,
516 IDirectMusicLoaderResourceStream_IStream_Clone
519 /* IDirectMusicGetLoader part: */
520 HRESULT WINAPI IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_QueryInterface (LPDIRECTMUSICGETLOADER iface, REFIID riid, void** ppobj) {
521 ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, GetLoaderVtbl, iface);
522 return IDirectMusicLoaderResourceStream_IStream_QueryInterface ((LPSTREAM)&This->StreamVtbl, riid, ppobj);
525 ULONG WINAPI IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_AddRef (LPDIRECTMUSICGETLOADER iface) {
526 ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, GetLoaderVtbl, iface);
527 return IDirectMusicLoaderResourceStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl);
530 ULONG WINAPI IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_Release (LPDIRECTMUSICGETLOADER iface) {
531 ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, GetLoaderVtbl, iface);
532 return IDirectMusicLoaderResourceStream_IStream_Release ((LPSTREAM)&This->StreamVtbl);
535 HRESULT WINAPI IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_GetLoader (LPDIRECTMUSICGETLOADER iface, IDirectMusicLoader **ppLoader) {
536 ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, GetLoaderVtbl, iface);
538 TRACE("(%p, %p)\n", This, ppLoader);
539 *ppLoader = (LPDIRECTMUSICLOADER)This->pLoader;
540 IDirectMusicLoader8_AddRef ((LPDIRECTMUSICLOADER8)*ppLoader);
545 ICOM_VTABLE(IDirectMusicGetLoader) DirectMusicLoaderResourceStream_GetLoader_Vtbl = {
546 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
547 IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_QueryInterface,
548 IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_AddRef,
549 IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_Release,
550 IDirectMusicLoaderResourceStream_IDirectMusicGetLoader_GetLoader
553 HRESULT WINAPI DMUSIC_CreateDirectMusicLoaderResourceStream (LPVOID* ppobj) {
554 IDirectMusicLoaderResourceStream *obj;
556 TRACE("(%p)\n", ppobj);
557 obj = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(IDirectMusicLoaderResourceStream));
559 *ppobj = (LPVOID) NULL;
560 return E_OUTOFMEMORY;
562 obj->StreamVtbl = &DirectMusicLoaderResourceStream_Stream_Vtbl;
563 obj->GetLoaderVtbl = &DirectMusicLoaderResourceStream_GetLoader_Vtbl;
564 obj->dwRef = 0; /* will be inited with QueryInterface */
566 return IDirectMusicLoaderResourceStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj);
569 HRESULT WINAPI DMUSIC_DestroyDirectMusicLoaderResourceStream (LPSTREAM iface) {
570 ICOM_THIS_MULTI(IDirectMusicLoaderResourceStream, StreamVtbl, iface);
572 TRACE("(%p)\n", iface);
573 IDirectMusicLoaderResourceStream_Detach (iface);
574 HeapFree (GetProcessHeap(), 0, This);
579 /*****************************************************************************
580 * IDirectMusicLoaderGenericStream implementation
583 HRESULT WINAPI IDirectMusicLoaderGenericStream_Attach (LPSTREAM iface, LPSTREAM pStream, LPDIRECTMUSICLOADER pLoader) {
584 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
586 TRACE("(%p, %p, %p)\n", This, pStream, pLoader);
588 WARN(": invalid pStream\n");
592 WARN(": invalid pLoader\n");
596 IDirectMusicLoaderGenericStream_Detach (iface);
597 IStream_Clone (pStream, &This->pStream);
598 This->pLoader = pLoader;
603 void WINAPI IDirectMusicLoaderGenericStream_Detach (LPSTREAM iface) {
604 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
607 IStream_Release (This->pStream);
608 This->pStream = NULL;
612 /* IUnknown/IStream part: */
613 HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_QueryInterface (LPSTREAM iface, REFIID riid, void** ppobj) {
614 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
616 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
617 if (IsEqualIID (riid, &IID_IUnknown) ||
618 IsEqualIID (riid, &IID_IStream)) {
619 *ppobj = (LPVOID)&This->StreamVtbl;
620 IDirectMusicLoaderGenericStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl);
622 } else if (IsEqualIID (riid, &IID_IDirectMusicGetLoader)) {
623 *ppobj = (LPVOID)&This->GetLoaderVtbl;
624 IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_AddRef ((LPDIRECTMUSICGETLOADER)&This->GetLoaderVtbl);
628 WARN(": not found\n");
629 return E_NOINTERFACE;
632 ULONG WINAPI IDirectMusicLoaderGenericStream_IStream_AddRef (LPSTREAM iface) {
633 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
634 TRACE("(%p): AddRef from %ld\n", This, This->dwRef);
635 return InterlockedIncrement (&This->dwRef);
638 ULONG WINAPI IDirectMusicLoaderGenericStream_IStream_Release (LPSTREAM iface) {
639 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
641 DWORD dwRef = InterlockedDecrement (&This->dwRef);
642 TRACE("(%p): ReleaseRef to %ld\n", This, dwRef);
644 DMUSIC_DestroyDirectMusicLoaderGenericStream (iface);
650 HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Read (LPSTREAM iface, void* pv, ULONG cb, ULONG* pcbRead) {
651 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
653 TRACE_(dmfileraw)("(%p, %p, 0x%08lX, %p): redirecting to low-level stream\n", This, pv, cb, pcbRead);
657 return IStream_Read (This->pStream, pv, cb, pcbRead);
660 HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Seek (LPSTREAM iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition) {
661 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
662 TRACE_(dmfileraw)("(%p, 0x%08llX, %s, %p): redirecting to low-level stream\n", This, dlibMove.QuadPart, resolve_STREAM_SEEK(dwOrigin), plibNewPosition);
666 return IStream_Seek (This->pStream, dlibMove, dwOrigin, plibNewPosition);
669 HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Clone (LPSTREAM iface, IStream** ppstm) {
670 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
671 LPSTREAM pOther = NULL;
672 LPSTREAM pLowLevel = NULL;
675 TRACE("(%p, %p)\n", iface, ppstm);
676 result = DMUSIC_CreateDirectMusicLoaderGenericStream ((LPVOID*)&pOther);
677 if (FAILED(result)) return result;
679 if (FAILED(IStream_Clone (This->pStream, &pLowLevel)))
682 IDirectMusicLoaderGenericStream_Attach (pOther, pLowLevel, This->pLoader);
684 TRACE(": succeeded\n");
685 *ppstm = (IStream*)pOther;
689 HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Write (LPSTREAM iface, const void* pv, ULONG cb, ULONG* pcbWritten) {
690 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
691 TRACE_(dmfileraw)("(%p, %p, 0x%08lX, %p): redirecting to low-level stream\n", This, pv, cb, pcbWritten);
695 return IStream_Write (This->pStream, pv, cb, pcbWritten);
698 HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_SetSize (LPSTREAM iface, ULARGE_INTEGER libNewSize) {
699 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
700 TRACE("(%p, 0x%08llX): redirecting to low-level stream\n", This, libNewSize.QuadPart);
704 return IStream_SetSize (This->pStream, libNewSize);
707 HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_CopyTo (LPSTREAM iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten) {
708 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
709 TRACE("(%p, %p, 0x%08llX, %p, %p): redirecting to low-level stream\n", This, pstm, cb.QuadPart, pcbRead, pcbWritten);
713 return IStream_CopyTo (This->pStream, pstm, cb, pcbRead, pcbWritten);
716 HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Commit (LPSTREAM iface, DWORD grfCommitFlags) {
717 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
718 TRACE("(%p, 0x%08lX): redirecting to low-level stream\n", This, grfCommitFlags);
722 return IStream_Commit (This->pStream, grfCommitFlags);
725 HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Revert (LPSTREAM iface) {
726 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
727 TRACE("(%p): redirecting to low-level stream\n", This);
731 return IStream_Revert (This->pStream);
734 HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_LockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) {
735 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
736 TRACE("(%p, 0x%08llX, 0x%08llX, 0x%08lX): redirecting to low-level stream\n", This, libOffset.QuadPart, cb.QuadPart, dwLockType);
740 return IStream_LockRegion (This->pStream, libOffset, cb, dwLockType);
743 HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_UnlockRegion (LPSTREAM iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) {
744 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
745 TRACE("(%p, 0x%08llX, 0x%08llX, 0x%08lX): redirecting to low-level stream\n", This, libOffset.QuadPart, cb.QuadPart, dwLockType);
749 return IStream_UnlockRegion (This->pStream, libOffset, cb, dwLockType);
752 HRESULT WINAPI IDirectMusicLoaderGenericStream_IStream_Stat (LPSTREAM iface, STATSTG* pstatstg, DWORD grfStatFlag) {
753 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
754 TRACE("(%p, %p, 0x%08lX): redirecting to low-level stream\n", This, pstatstg, grfStatFlag);
758 return IStream_Stat (This->pStream, pstatstg, grfStatFlag);
761 ICOM_VTABLE(IStream) DirectMusicLoaderGenericStream_Stream_Vtbl = {
762 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
763 IDirectMusicLoaderGenericStream_IStream_QueryInterface,
764 IDirectMusicLoaderGenericStream_IStream_AddRef,
765 IDirectMusicLoaderGenericStream_IStream_Release,
766 IDirectMusicLoaderGenericStream_IStream_Read,
767 IDirectMusicLoaderGenericStream_IStream_Write,
768 IDirectMusicLoaderGenericStream_IStream_Seek,
769 IDirectMusicLoaderGenericStream_IStream_SetSize,
770 IDirectMusicLoaderGenericStream_IStream_CopyTo,
771 IDirectMusicLoaderGenericStream_IStream_Commit,
772 IDirectMusicLoaderGenericStream_IStream_Revert,
773 IDirectMusicLoaderGenericStream_IStream_LockRegion,
774 IDirectMusicLoaderGenericStream_IStream_UnlockRegion,
775 IDirectMusicLoaderGenericStream_IStream_Stat,
776 IDirectMusicLoaderGenericStream_IStream_Clone
779 /* IDirectMusicGetLoader part: */
780 HRESULT WINAPI IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_QueryInterface (LPDIRECTMUSICGETLOADER iface, REFIID riid, void** ppobj) {
781 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, GetLoaderVtbl, iface);
782 return IDirectMusicLoaderGenericStream_IStream_QueryInterface ((LPSTREAM)&This->StreamVtbl, riid, ppobj);
785 ULONG WINAPI IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_AddRef (LPDIRECTMUSICGETLOADER iface) {
786 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, GetLoaderVtbl, iface);
787 return IDirectMusicLoaderGenericStream_IStream_AddRef ((LPSTREAM)&This->StreamVtbl);
790 ULONG WINAPI IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_Release (LPDIRECTMUSICGETLOADER iface) {
791 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, GetLoaderVtbl, iface);
792 return IDirectMusicLoaderGenericStream_IStream_Release ((LPSTREAM)&This->StreamVtbl);
795 HRESULT WINAPI IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_GetLoader (LPDIRECTMUSICGETLOADER iface, IDirectMusicLoader **ppLoader) {
796 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, GetLoaderVtbl, iface);
798 TRACE("(%p, %p)\n", This, ppLoader);
799 *ppLoader = (LPDIRECTMUSICLOADER)This->pLoader;
800 IDirectMusicLoader8_AddRef ((LPDIRECTMUSICLOADER8)*ppLoader);
805 ICOM_VTABLE(IDirectMusicGetLoader) DirectMusicLoaderGenericStream_GetLoader_Vtbl = {
806 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
807 IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_QueryInterface,
808 IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_AddRef,
809 IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_Release,
810 IDirectMusicLoaderGenericStream_IDirectMusicGetLoader_GetLoader
813 HRESULT WINAPI DMUSIC_CreateDirectMusicLoaderGenericStream (LPVOID* ppobj) {
814 IDirectMusicLoaderGenericStream *obj;
816 TRACE("(%p)\n", ppobj);
817 obj = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(IDirectMusicLoaderGenericStream));
819 *ppobj = (LPVOID) NULL;
820 return E_OUTOFMEMORY;
822 obj->StreamVtbl = &DirectMusicLoaderGenericStream_Stream_Vtbl;
823 obj->GetLoaderVtbl = &DirectMusicLoaderGenericStream_GetLoader_Vtbl;
824 obj->dwRef = 0; /* will be inited with QueryInterface */
826 return IDirectMusicLoaderGenericStream_IStream_QueryInterface ((LPSTREAM)&obj->StreamVtbl, &IID_IStream, ppobj);
829 HRESULT WINAPI DMUSIC_DestroyDirectMusicLoaderGenericStream (LPSTREAM iface) {
830 ICOM_THIS_MULTI(IDirectMusicLoaderGenericStream, StreamVtbl, iface);
832 TRACE("(%p)\n", iface);
833 IDirectMusicLoaderGenericStream_Detach (iface);
834 HeapFree (GetProcessHeap(), 0, This);