1 /* IDirectMusicLoaderImpl
3 * Copyright (C) 2003-2004 Rok Mandeljc
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "dmloader_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmloader
);
24 static HRESULT
DMUSIC_InitLoaderSettings (LPDIRECTMUSICLOADER8 iface
);
25 static HRESULT
DMUSIC_GetLoaderSettings (LPDIRECTMUSICLOADER8 iface
, REFGUID pClassID
, WCHAR
* wszSearchPath
, LPBOOL pbCache
);
26 static HRESULT
DMUSIC_SetLoaderSettings (LPDIRECTMUSICLOADER8 iface
, REFGUID pClassID
, WCHAR
* wszSearchPath
, LPBOOL pbCache
);
28 static HRESULT
DMUSIC_CopyDescriptor (LPDMUS_OBJECTDESC pDst
, LPDMUS_OBJECTDESC pSrc
) {
29 TRACE(": copy\n%s\n", debugstr_DMUS_OBJECTDESC(pSrc
));
30 /* copy field by field */
31 if (pSrc
->dwValidData
& DMUS_OBJ_CLASS
) pDst
->guidClass
= pSrc
->guidClass
;
32 if (pSrc
->dwValidData
& DMUS_OBJ_OBJECT
) pDst
->guidObject
= pSrc
->guidObject
;
33 if (pSrc
->dwValidData
& DMUS_OBJ_DATE
) pDst
->ftDate
= pSrc
->ftDate
;
34 if (pSrc
->dwValidData
& DMUS_OBJ_VERSION
) pDst
->vVersion
= pSrc
->vVersion
;
35 if (pSrc
->dwValidData
& DMUS_OBJ_NAME
) strcpyW (pDst
->wszName
, pSrc
->wszName
);
36 if (pSrc
->dwValidData
& DMUS_OBJ_CATEGORY
) strcpyW (pDst
->wszCategory
, pSrc
->wszCategory
);
37 if (pSrc
->dwValidData
& DMUS_OBJ_FILENAME
) strcpyW (pDst
->wszFileName
, pSrc
->wszFileName
);
38 if (pSrc
->dwValidData
& DMUS_OBJ_STREAM
) IStream_Clone (pSrc
->pStream
, &pDst
->pStream
);
39 if (pSrc
->dwValidData
& DMUS_OBJ_MEMORY
) {
40 pDst
->pbMemData
= pSrc
->pbMemData
;
41 pDst
->llMemLength
= pSrc
->llMemLength
;
44 pDst
->dwValidData
|= pSrc
->dwValidData
;
49 static BOOL
DMUSIC_IsValidLoadableClass (REFCLSID pClassID
) {
50 if (IsEqualCLSID(pClassID
, &CLSID_DirectMusicAudioPathConfig
) ||
51 IsEqualCLSID(pClassID
, &CLSID_DirectMusicBand
) ||
52 IsEqualCLSID(pClassID
, &CLSID_DirectMusicContainer
) ||
53 IsEqualCLSID(pClassID
, &CLSID_DirectMusicCollection
) ||
54 IsEqualCLSID(pClassID
, &CLSID_DirectMusicChordMap
) ||
55 IsEqualCLSID(pClassID
, &CLSID_DirectMusicSegment
) ||
56 IsEqualCLSID(pClassID
, &CLSID_DirectMusicScript
) ||
57 IsEqualCLSID(pClassID
, &CLSID_DirectMusicSong
) ||
58 IsEqualCLSID(pClassID
, &CLSID_DirectMusicStyle
) ||
59 IsEqualCLSID(pClassID
, &CLSID_DirectMusicGraph
) ||
60 IsEqualCLSID(pClassID
, &CLSID_DirectSoundWave
) ||
61 IsEqualCLSID(pClassID
, &GUID_DirectMusicAllTypes
))
67 /*****************************************************************************
68 * IDirectMusicLoaderImpl implementation
70 /* IUnknown/IDirectMusicLoader(8) part: */
72 static HRESULT WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_QueryInterface (LPDIRECTMUSICLOADER8 iface
, REFIID riid
, LPVOID
*ppobj
) {
73 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
75 TRACE("(%p, %s, %p)\n",This
, debugstr_dmguid(riid
), ppobj
);
76 if (IsEqualIID (riid
, &IID_IUnknown
) ||
77 IsEqualIID (riid
, &IID_IDirectMusicLoader
) ||
78 IsEqualIID (riid
, &IID_IDirectMusicLoader8
)) {
79 IDirectMusicLoader_AddRef (iface
);
84 WARN(": not found\n");
88 static ULONG WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_AddRef (LPDIRECTMUSICLOADER8 iface
) {
89 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
90 TRACE("(%p): AddRef from %d\n", This
, This
->dwRef
);
91 return InterlockedIncrement (&This
->dwRef
);
94 static ULONG WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_Release (LPDIRECTMUSICLOADER8 iface
) {
95 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
97 DWORD dwRef
= InterlockedDecrement (&This
->dwRef
);
98 TRACE("(%p): ReleaseRef to %d\n", This
, This
->dwRef
);
100 /* firstly, release the cache */
101 IDirectMusicLoader8_ClearCache (iface
, &GUID_DirectMusicAllTypes
);
102 /* FIXME: release all allocated entries */
103 HeapFree (GetProcessHeap(), 0, This
);
110 static HRESULT WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_GetObject (LPDIRECTMUSICLOADER8 iface
, LPDMUS_OBJECTDESC pDesc
, REFIID riid
, LPVOID
* ppv
) {
111 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
112 HRESULT result
= S_OK
;
113 HRESULT ret
= S_OK
; /* used at the end of function, to determine whether everything went OK */
116 LPWINE_LOADER_ENTRY pObjectEntry
= NULL
;
118 IPersistStream
* pPersistStream
= NULL
;
120 LPDIRECTMUSICOBJECT pObject
;
121 DMUS_OBJECTDESC GotDesc
;
124 TRACE("(%p, %p, %s, %p): pDesc:\n%s\n", This
, pDesc
, debugstr_dmguid(riid
), ppv
, debugstr_DMUS_OBJECTDESC(pDesc
));
126 /* sometimes it happens that guidClass is missing... which is a BadThingTM */
127 if (!(pDesc
->dwValidData
& DMUS_OBJ_CLASS
)) {
128 ERR(": guidClass not valid but needed\n");
130 return DMUS_E_LOADER_NOCLASSID
;
133 /* OK, first we iterate through the list of objects we know about; these are either loaded (GetObject, LoadObjectFromFile)
134 or set via SetObject; */
135 TRACE(": looking if we have object in the cache or if it can be found via alias\n");
136 LIST_FOR_EACH(pEntry
, This
->pObjects
) {
137 LPWINE_LOADER_ENTRY pExistingEntry
= LIST_ENTRY(pEntry
, WINE_LOADER_ENTRY
, entry
);
138 if ((pDesc
->dwValidData
& DMUS_OBJ_OBJECT
) &&
139 (pExistingEntry
->Desc
.dwValidData
& DMUS_OBJ_OBJECT
) &&
140 IsEqualGUID (&pDesc
->guidObject
, &pExistingEntry
->Desc
.guidObject
)) {
141 TRACE(": found it by object GUID\n");
142 /* I suppose such stuff can happen only when GUID for object is given (GUID_DefaultGMCollection) */
143 if (pExistingEntry
->bInvalidDefaultDLS
) {
144 TRACE(": found faulty default DLS collection... enabling M$ compliant behaviour\n");
145 return DMUS_E_LOADER_NOFILENAME
;
147 if (pExistingEntry
->Desc
.dwValidData
& DMUS_OBJ_LOADED
) {
148 TRACE(": already loaded\n");
149 return IDirectMusicObject_QueryInterface (pExistingEntry
->pObject
, riid
, ppv
);
151 TRACE(": not loaded yet\n");
152 pObjectEntry
= pExistingEntry
;
155 else if ((pDesc
->dwValidData
& (DMUS_OBJ_FILENAME
| DMUS_OBJ_FULLPATH
)) &&
156 (pExistingEntry
->Desc
.dwValidData
& (DMUS_OBJ_FILENAME
| DMUS_OBJ_FULLPATH
)) &&
157 !strncmpW (pDesc
->wszFileName
, pExistingEntry
->Desc
.wszFileName
, DMUS_MAX_FILENAME
)) {
158 TRACE(": found it by fullpath filename\n");
159 if (pExistingEntry
->Desc
.dwValidData
& DMUS_OBJ_LOADED
) {
160 TRACE(": already loaded\n");
161 return IDirectMusicObject_QueryInterface (pExistingEntry
->pObject
, riid
, ppv
);
163 TRACE(": not loaded yet\n");
164 pObjectEntry
= pExistingEntry
;
167 else if ((pDesc
->dwValidData
& (DMUS_OBJ_NAME
| DMUS_OBJ_CATEGORY
)) &&
168 (pExistingEntry
->Desc
.dwValidData
& (DMUS_OBJ_NAME
| DMUS_OBJ_CATEGORY
)) &&
169 !strncmpW (pDesc
->wszName
, pExistingEntry
->Desc
.wszName
, DMUS_MAX_NAME
) &&
170 !strncmpW (pDesc
->wszCategory
, pExistingEntry
->Desc
.wszCategory
, DMUS_MAX_CATEGORY
)) {
171 TRACE(": found it by name and category\n");
172 if (pExistingEntry
->Desc
.dwValidData
& DMUS_OBJ_LOADED
) {
173 TRACE(": already loaded\n");
174 return IDirectMusicObject_QueryInterface (pExistingEntry
->pObject
, riid
, ppv
);
176 TRACE(": not loaded yet\n");
177 pObjectEntry
= pExistingEntry
;
180 else if ((pDesc
->dwValidData
& DMUS_OBJ_NAME
) &&
181 (pExistingEntry
->Desc
.dwValidData
& DMUS_OBJ_NAME
) &&
182 !strncmpW (pDesc
->wszName
, pExistingEntry
->Desc
.wszName
, DMUS_MAX_NAME
)) {
183 TRACE(": found it by name\n");
184 if (pExistingEntry
->Desc
.dwValidData
& DMUS_OBJ_LOADED
) {
185 TRACE(": already loaded\n");
186 return IDirectMusicObject_QueryInterface (pExistingEntry
->pObject
, riid
, ppv
);
188 TRACE(": not loaded yet\n");
189 pObjectEntry
= pExistingEntry
;
192 else if ((pDesc
->dwValidData
& DMUS_OBJ_FILENAME
) &&
193 (pExistingEntry
->Desc
.dwValidData
& DMUS_OBJ_FILENAME
) &&
194 !strncmpW (pDesc
->wszFileName
, pExistingEntry
->Desc
.wszFileName
, DMUS_MAX_FILENAME
)) {
195 TRACE(": found it by filename\n");
196 if (pExistingEntry
->Desc
.dwValidData
& DMUS_OBJ_LOADED
) {
197 TRACE(": already loaded\n");
198 return IDirectMusicObject_QueryInterface (pExistingEntry
->pObject
, riid
, ppv
);
200 TRACE(": not loaded yet\n");
201 pObjectEntry
= pExistingEntry
;
206 /* basically, if we found alias, we use its descriptor to load...
207 else we use info we were given */
209 TRACE(": found alias entry for requested object... using stored info\n");
210 /* I think in certain cases it can happen that entry's descriptor lacks info about
211 where to load from (e.g.: if we loaded from stream and then released object
212 from cache; then only its CLSID, GUID and perhaps name are left); so just
213 overwrite whatever info the entry has (since it ought to be 100% correct) */
214 DMUSIC_CopyDescriptor (pDesc
, &pObjectEntry
->Desc
);
215 /*pDesc = &pObjectEntry->Desc; */ /* FIXME: is this OK? */
217 TRACE(": no cache/alias entry found for requested object\n");
220 if (pDesc
->dwValidData
& DMUS_OBJ_URL
) {
221 TRACE(": loading from URLs not supported yet\n");
222 return DMUS_E_LOADER_FORMATNOTSUPPORTED
;
224 else if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
) {
225 /* load object from file */
226 /* generate filename; if it's full path, don't add search
227 directory path, otherwise do */
228 WCHAR wszFileName
[MAX_PATH
];
230 if (pDesc
->dwValidData
& DMUS_OBJ_FULLPATH
) {
231 lstrcpyW(wszFileName
, pDesc
->wszFileName
);
233 WCHAR
*p
, wszSearchPath
[MAX_PATH
];
234 DMUSIC_GetLoaderSettings (iface
, &pDesc
->guidClass
, wszSearchPath
, NULL
);
235 lstrcpyW(wszFileName
, wszSearchPath
);
236 p
= wszFileName
+ lstrlenW(wszFileName
);
237 if (p
> wszFileName
&& p
[-1] != '\\') *p
++ = '\\';
238 strcpyW(p
, pDesc
->wszFileName
);
240 TRACE(": loading from file (%s)\n", debugstr_w(wszFileName
));
241 /* create stream and associate it with file */
242 result
= DMUSIC_CreateDirectMusicLoaderFileStream ((LPVOID
*)&pStream
);
243 if (FAILED(result
)) {
244 ERR(": could not create file stream\n");
247 result
= IDirectMusicLoaderFileStream_Attach (pStream
, wszFileName
, iface
);
248 if (FAILED(result
)) {
249 ERR(": could not attach stream to file\n");
250 IStream_Release (pStream
);
254 else if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) {
255 /* load object from resource */
256 TRACE(": loading from resource\n");
257 /* create stream and associate it with given resource */
258 result
= DMUSIC_CreateDirectMusicLoaderResourceStream ((LPVOID
*)&pStream
);
259 if (FAILED(result
)) {
260 ERR(": could not create resource stream\n");
263 result
= IDirectMusicLoaderResourceStream_Attach (pStream
, pDesc
->pbMemData
, pDesc
->llMemLength
, 0, iface
);
264 if (FAILED(result
)) {
265 ERR(": could not attach stream to resource\n");
266 IStream_Release (pStream
);
270 else if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) {
271 /* load object from stream */
272 TRACE(": loading from stream\n");
273 /* create universal stream and associate it with given one */
274 result
= DMUSIC_CreateDirectMusicLoaderGenericStream ((LPVOID
*)&pStream
);
275 if (FAILED(result
)) {
276 ERR(": could not create generic stream\n");
279 result
= IDirectMusicLoaderGenericStream_Attach (pStream
, pDesc
->pStream
, iface
);
280 if (FAILED(result
)) {
281 ERR(": failed to attach stream\n");
282 IStream_Release (pStream
);
286 /* nowhere to load from */
287 FIXME(": unknown/unsupported way of loading\n");
288 return DMUS_E_LOADER_NOFILENAME
; /* test shows this is returned */
292 result
= CoCreateInstance (&pDesc
->guidClass
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicObject
, (LPVOID
*)&pObject
);
293 if (FAILED(result
)) {
294 ERR(": could not create object\n");
297 /* acquire PersistStream interface */
298 result
= IDirectMusicObject_QueryInterface (pObject
, &IID_IPersistStream
, (LPVOID
*)&pPersistStream
);
299 if (FAILED(result
)) {
300 ERR("failed to Query\n");
304 result
= IPersistStream_Load (pPersistStream
, pStream
);
305 if (result
!= S_OK
) {
306 WARN(": failed to (completely) load object (%s)\n", debugstr_dmreturn(result
));
310 DM_STRUCT_INIT(&GotDesc
);
311 result
= IDirectMusicObject_GetDescriptor (pObject
, &GotDesc
);
312 /* set filename (if we loaded via filename) */
313 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
) {
314 GotDesc
.dwValidData
|= (pDesc
->dwValidData
& (DMUS_OBJ_FILENAME
| DMUS_OBJ_FULLPATH
));
315 strcpyW (GotDesc
.wszFileName
, pDesc
->wszFileName
);
317 if (FAILED(result
)) {
318 ERR(": failed to get descriptor\n");
321 /* release all loading related stuff */
322 IStream_Release (pStream
);
323 IPersistStream_Release (pPersistStream
);
325 /* add object to cache/overwrite existing info (if cache is enabled) */
326 DMUSIC_GetLoaderSettings (iface
, &pDesc
->guidClass
, NULL
, &bCache
);
329 pObjectEntry
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(WINE_LOADER_ENTRY
));
330 DM_STRUCT_INIT(&pObjectEntry
->Desc
);
331 DMUSIC_CopyDescriptor (&pObjectEntry
->Desc
, &GotDesc
);
332 pObjectEntry
->pObject
= pObject
;
333 pObjectEntry
->bInvalidDefaultDLS
= FALSE
;
334 list_add_head (This
->pObjects
, &pObjectEntry
->entry
);
336 DMUSIC_CopyDescriptor (&pObjectEntry
->Desc
, &GotDesc
);
337 pObjectEntry
->pObject
= pObject
;
338 pObjectEntry
->bInvalidDefaultDLS
= FALSE
;
340 TRACE(": filled in cache entry\n");
341 } else TRACE(": caching disabled\n");
344 /* for debug purposes (e.g. to check if all files are cached) */
345 TRACE("*** Loader's cache ***\n");
347 LIST_FOR_EACH (pEntry
, This
->pObjects
) {
349 pObjectEntry
= LIST_ENTRY(pEntry
, WINE_LOADER_ENTRY
, entry
);
350 TRACE(": entry nr. %i:\n%s\n - bInvalidDefaultDLS = %i\n - pObject = %p\n", i
, debugstr_DMUS_OBJECTDESC(&pObjectEntry
->Desc
), pObjectEntry
->bInvalidDefaultDLS
, pObjectEntry
->pObject
);
354 result
= IDirectMusicObject_QueryInterface (pObject
, riid
, ppv
);
355 if (!bCache
) IDirectMusicObject_Release (pObject
); /* since loader's reference is not needed */
356 /* if there was trouble with loading, and if no other error occurred,
357 we should return DMUS_S_PARTIALLOAD; else, error is returned */
364 static HRESULT WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_SetObject (LPDIRECTMUSICLOADER8 iface
, LPDMUS_OBJECTDESC pDesc
) {
365 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
367 LPDIRECTMUSICOBJECT pObject
;
368 DMUS_OBJECTDESC Desc
;
370 LPWINE_LOADER_ENTRY pObjectEntry
, pNewEntry
;
373 TRACE("(%p, %p): pDesc:\n%s\n", This
, pDesc
, debugstr_DMUS_OBJECTDESC(pDesc
));
375 /* create stream and load additional info from it */
376 if (pDesc
->dwValidData
& DMUS_OBJ_FILENAME
) {
377 /* generate filename; if it's full path, don't add search
378 directory path, otherwise do */
379 WCHAR wszFileName
[MAX_PATH
];
381 if (pDesc
->dwValidData
& DMUS_OBJ_FULLPATH
) {
382 lstrcpyW(wszFileName
, pDesc
->wszFileName
);
385 WCHAR wszSearchPath
[MAX_PATH
];
386 DMUSIC_GetLoaderSettings (iface
, &pDesc
->guidClass
, wszSearchPath
, NULL
);
387 lstrcpyW(wszFileName
, wszSearchPath
);
388 p
= wszFileName
+ lstrlenW(wszFileName
);
389 if (p
> wszFileName
&& p
[-1] != '\\') *p
++ = '\\';
390 strcpyW(p
, pDesc
->wszFileName
);
393 hr
= DMUSIC_CreateDirectMusicLoaderFileStream ((LPVOID
*)&pStream
);
395 ERR(": could not create file stream\n");
396 return DMUS_E_LOADER_FAILEDOPEN
;
399 hr
= IDirectMusicLoaderFileStream_Attach (pStream
, wszFileName
, iface
);
401 ERR(": could not attach stream to file\n");
402 IStream_Release (pStream
);
403 return DMUS_E_LOADER_FAILEDOPEN
;
406 else if (pDesc
->dwValidData
& DMUS_OBJ_STREAM
) {
408 hr
= DMUSIC_CreateDirectMusicLoaderGenericStream ((LPVOID
*)&pStream
);
410 ERR(": could not create generic stream\n");
411 return DMUS_E_LOADER_FAILEDOPEN
;
414 hr
= IDirectMusicLoaderGenericStream_Attach (pStream
, pDesc
->pStream
, iface
);
416 ERR(": could not attach stream\n");
417 IStream_Release (pStream
);
418 return DMUS_E_LOADER_FAILEDOPEN
;
421 else if (pDesc
->dwValidData
& DMUS_OBJ_MEMORY
) {
423 hr
= DMUSIC_CreateDirectMusicLoaderResourceStream ((LPVOID
*)&pStream
);
425 ERR(": could not create resource stream\n");
426 return DMUS_E_LOADER_FAILEDOPEN
;
429 hr
= IDirectMusicLoaderResourceStream_Attach (pStream
, pDesc
->pbMemData
, pDesc
->llMemLength
, 0, iface
);
431 ERR(": could not attach stream to resource\n");
432 IStream_Release (pStream
);
433 return DMUS_E_LOADER_FAILEDOPEN
;
437 ERR(": no way to get additional info\n");
438 return DMUS_E_LOADER_FAILEDOPEN
;
442 CoCreateInstance (&pDesc
->guidClass
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectMusicObject
, (LPVOID
*)&pObject
);
444 /* *sigh*... some ms objects have lousy implementation of ParseDescriptor that clears input descriptor :( */
445 #ifdef NOW_WE_ARE_FREE
446 /* parse descriptor: we actually use input descriptor; fields that aren't available from stream remain,
447 otherwise real info is set */
448 IDirectMusicObject_ParseDescriptor (pObject
, pStream
, pDesc
);
450 /* hmph... due to some trouble I had with certain tests, we store current position and then set it back */
451 DM_STRUCT_INIT(&Desc
);
452 if (FAILED(IDirectMusicObject_ParseDescriptor (pObject
, pStream
, &Desc
))) {
453 ERR(": couldn't parse descriptor\n");
454 return DMUS_E_LOADER_FORMATNOTSUPPORTED
;
457 /* copy elements from parsed descriptor into input descriptor; this sets new info, overwriting if necessary,
458 but leaves info that's provided by input and not available from stream */
459 DMUSIC_CopyDescriptor (pDesc
, &Desc
);
461 /* release everything */
462 IDirectMusicObject_Release (pObject
);
463 IStream_Release (pStream
);
465 /* sometimes it happens that twisted programs call SetObject for same object twice...
466 in such cases, native loader returns S_OK and does nothing... a sound plan */
467 LIST_FOR_EACH (pEntry
, This
->pObjects
) {
468 pObjectEntry
= LIST_ENTRY (pEntry
, WINE_LOADER_ENTRY
, entry
);
469 if (!memcmp (&pObjectEntry
->Desc
, pDesc
, sizeof(DMUS_OBJECTDESC
))) {
470 TRACE(": exactly same entry already exists\n");
476 TRACE(": adding alias entry with following info:\n%s\n", debugstr_DMUS_OBJECTDESC(pDesc
));
477 pNewEntry
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(WINE_LOADER_ENTRY
));
478 /* use this function instead of pure memcpy due to streams (memcpy just copies pointer),
479 which is basically used further by app that called SetDescriptor... better safety than exception */
480 DMUSIC_CopyDescriptor (&pNewEntry
->Desc
, pDesc
);
481 list_add_head (This
->pObjects
, &pNewEntry
->entry
);
486 static HRESULT WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_SetSearchDirectory (LPDIRECTMUSICLOADER8 iface
, REFGUID rguidClass
, WCHAR
* pwzPath
, BOOL fClear
) {
487 WCHAR wszCurrentPath
[MAX_PATH
];
488 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
489 TRACE("(%p, %s, %s, %d)\n", This
, debugstr_dmguid(rguidClass
), debugstr_w(pwzPath
), fClear
);
490 FIXME(": fClear ignored\n");
491 DMUSIC_GetLoaderSettings (iface
, rguidClass
, wszCurrentPath
, NULL
);
492 if (!strncmpW(wszCurrentPath
, pwzPath
, MAX_PATH
)) {
495 /* FIXME: check if path is valid; else return DMUS_E_LOADER_BADPATH */
496 return DMUSIC_SetLoaderSettings (iface
, rguidClass
, pwzPath
, NULL
);
499 static HRESULT WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_ScanDirectory (LPDIRECTMUSICLOADER8 iface
, REFGUID rguidClass
, WCHAR
* pwzFileExtension
, WCHAR
* pwzScanFileName
) {
500 static const WCHAR wszAny
[] = {'*',0};
501 WIN32_FIND_DATAW FileData
;
503 WCHAR wszSearchString
[MAX_PATH
];
506 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
507 TRACE("(%p, %s, %p, %p)\n", This
, debugstr_dmguid(rguidClass
), pwzFileExtension
, pwzScanFileName
);
508 if (IsEqualGUID (rguidClass
, &GUID_DirectMusicAllTypes
) || !DMUSIC_IsValidLoadableClass(rguidClass
)) {
509 ERR(": rguidClass invalid CLSID\n");
510 return REGDB_E_CLASSNOTREG
;
513 /* get search path for given class */
514 DMUSIC_GetLoaderSettings (iface
, rguidClass
, wszSearchString
, NULL
);
516 p
= wszSearchString
+ lstrlenW(wszSearchString
);
517 if (p
> wszSearchString
&& p
[-1] != '\\') *p
++ = '\\';
518 *p
++ = '*'; /* any file */
519 if (strcmpW (pwzFileExtension
, wszAny
)) *p
++ = '.'; /* if we have actual extension, put a dot */
520 strcpyW (p
, pwzFileExtension
);
522 TRACE(": search string: %s\n", debugstr_w(wszSearchString
));
524 hSearch
= FindFirstFileW (wszSearchString
, &FileData
);
525 if (hSearch
== INVALID_HANDLE_VALUE
) {
526 TRACE(": no files found\n");
531 DMUS_OBJECTDESC Desc
;
532 DM_STRUCT_INIT(&Desc
);
533 Desc
.dwValidData
= DMUS_OBJ_CLASS
| DMUS_OBJ_FILENAME
| DMUS_OBJ_FULLPATH
| DMUS_OBJ_DATE
;
534 Desc
.guidClass
= *rguidClass
;
535 strcpyW (Desc
.wszFileName
, FileData
.cFileName
);
536 FileTimeToLocalFileTime (&FileData
.ftCreationTime
, &Desc
.ftDate
);
537 IDirectMusicLoader8_SetObject (iface
, &Desc
);
539 if (!FindNextFileW (hSearch
, &FileData
)) {
540 if (GetLastError () == ERROR_NO_MORE_FILES
) {
541 TRACE(": search completed\n");
544 ERR(": could not get next file\n");
553 static HRESULT WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_CacheObject (LPDIRECTMUSICLOADER8 iface
, IDirectMusicObject
* pObject
) {
554 DMUS_OBJECTDESC Desc
;
555 HRESULT result
= DMUS_E_LOADER_OBJECTNOTFOUND
;
557 LPWINE_LOADER_ENTRY pObjectEntry
= NULL
;
559 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
560 TRACE("(%p, %p)\n", This
, pObject
);
563 DM_STRUCT_INIT(&Desc
);
564 IDirectMusicObject_GetDescriptor (pObject
, &Desc
);
566 /* now iterate through the list and check if we have an alias (without object), corresponding
567 to the descriptor of the input object */
568 LIST_FOR_EACH(pEntry
, This
->pObjects
) {
569 pObjectEntry
= LIST_ENTRY(pEntry
, WINE_LOADER_ENTRY
, entry
);
570 if ((Desc
.dwValidData
& DMUS_OBJ_OBJECT
) &&
571 (pObjectEntry
->Desc
.dwValidData
& DMUS_OBJ_OBJECT
) &&
572 IsEqualGUID (&Desc
.guidObject
, &pObjectEntry
->Desc
.guidObject
)) {
573 TRACE(": found it by object GUID\n");
574 if ((pObjectEntry
->Desc
.dwValidData
& DMUS_OBJ_LOADED
) && pObjectEntry
->pObject
)
580 else if ((Desc
.dwValidData
& (DMUS_OBJ_FILENAME
| DMUS_OBJ_FULLPATH
)) &&
581 (pObjectEntry
->Desc
.dwValidData
& (DMUS_OBJ_FILENAME
| DMUS_OBJ_FULLPATH
)) &&
582 !strncmpW (Desc
.wszFileName
, pObjectEntry
->Desc
.wszFileName
, DMUS_MAX_FILENAME
)) {
583 TRACE(": found it by fullpath filename\n");
584 if ((pObjectEntry
->Desc
.dwValidData
& DMUS_OBJ_LOADED
) && pObjectEntry
->pObject
)
590 else if ((Desc
.dwValidData
& (DMUS_OBJ_NAME
| DMUS_OBJ_CATEGORY
)) &&
591 (pObjectEntry
->Desc
.dwValidData
& (DMUS_OBJ_NAME
| DMUS_OBJ_CATEGORY
)) &&
592 !strncmpW (Desc
.wszName
, pObjectEntry
->Desc
.wszName
, DMUS_MAX_NAME
) &&
593 !strncmpW (Desc
.wszCategory
, pObjectEntry
->Desc
.wszCategory
, DMUS_MAX_CATEGORY
)) {
594 TRACE(": found it by name and category\n");
595 if ((pObjectEntry
->Desc
.dwValidData
& DMUS_OBJ_LOADED
) && pObjectEntry
->pObject
)
601 else if ((Desc
.dwValidData
& DMUS_OBJ_NAME
) &&
602 (pObjectEntry
->Desc
.dwValidData
& DMUS_OBJ_NAME
) &&
603 !strncmpW (Desc
.wszName
, pObjectEntry
->Desc
.wszName
, DMUS_MAX_NAME
)) {
604 TRACE(": found it by name\n");
605 if ((pObjectEntry
->Desc
.dwValidData
& DMUS_OBJ_LOADED
) && pObjectEntry
->pObject
)
611 else if ((Desc
.dwValidData
& DMUS_OBJ_FILENAME
) &&
612 (pObjectEntry
->Desc
.dwValidData
& DMUS_OBJ_FILENAME
) &&
613 !strncmpW (Desc
.wszFileName
, pObjectEntry
->Desc
.wszFileName
, DMUS_MAX_FILENAME
)) {
614 TRACE(": found it by filename\n");
615 if ((pObjectEntry
->Desc
.dwValidData
& DMUS_OBJ_LOADED
) && pObjectEntry
->pObject
)
623 /* if we found such alias, then set everything */
624 if (result
== S_OK
) {
625 pObjectEntry
->Desc
.dwValidData
&= DMUS_OBJ_LOADED
;
626 pObjectEntry
->pObject
= pObject
;
627 IDirectMusicObject_AddRef (pObjectEntry
->pObject
);
633 static HRESULT WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_ReleaseObject (LPDIRECTMUSICLOADER8 iface
, IDirectMusicObject
* pObject
) {
634 DMUS_OBJECTDESC Desc
;
636 LPWINE_LOADER_ENTRY pObjectEntry
= NULL
;
637 HRESULT result
= S_FALSE
;
639 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
640 TRACE("(%p, %p)\n", This
, pObject
);
642 if(!pObject
) return E_POINTER
;
645 DM_STRUCT_INIT(&Desc
);
646 IDirectMusicObject_GetDescriptor (pObject
, &Desc
);
648 /* iterate through the list of objects we know about; check only those with DMUS_OBJ_LOADED */
649 TRACE(": looking for the object in cache\n");
650 LIST_FOR_EACH(pEntry
, This
->pObjects
) {
651 pObjectEntry
= LIST_ENTRY(pEntry
, WINE_LOADER_ENTRY
, entry
);
652 if ((Desc
.dwValidData
& DMUS_OBJ_OBJECT
) &&
653 (pObjectEntry
->Desc
.dwValidData
& (DMUS_OBJ_OBJECT
| DMUS_OBJ_LOADED
)) &&
654 IsEqualGUID (&Desc
.guidObject
, &pObjectEntry
->Desc
.guidObject
)) {
655 TRACE(": found it by object GUID\n%s\n", debugstr_DMUS_OBJECTDESC(&pObjectEntry
->Desc
));
659 else if ((Desc
.dwValidData
& (DMUS_OBJ_FILENAME
| DMUS_OBJ_FULLPATH
)) &&
660 (pObjectEntry
->Desc
.dwValidData
& (DMUS_OBJ_FILENAME
| DMUS_OBJ_FULLPATH
| DMUS_OBJ_LOADED
)) &&
661 !strncmpW (Desc
.wszFileName
, pObjectEntry
->Desc
.wszFileName
, DMUS_MAX_FILENAME
)) {
662 TRACE(": found it by fullpath filename\n");
666 else if ((Desc
.dwValidData
& (DMUS_OBJ_NAME
| DMUS_OBJ_CATEGORY
)) &&
667 (pObjectEntry
->Desc
.dwValidData
& (DMUS_OBJ_NAME
| DMUS_OBJ_CATEGORY
| DMUS_OBJ_LOADED
)) &&
668 !strncmpW (Desc
.wszName
, pObjectEntry
->Desc
.wszName
, DMUS_MAX_NAME
) &&
669 !strncmpW (Desc
.wszCategory
, pObjectEntry
->Desc
.wszCategory
, DMUS_MAX_CATEGORY
)) {
670 TRACE(": found it by name and category\n");
674 else if ((Desc
.dwValidData
& DMUS_OBJ_NAME
) &&
675 (pObjectEntry
->Desc
.dwValidData
& (DMUS_OBJ_NAME
| DMUS_OBJ_LOADED
)) &&
676 !strncmpW (Desc
.wszName
, pObjectEntry
->Desc
.wszName
, DMUS_MAX_NAME
)) {
677 TRACE(": found it by name\n");
681 else if ((Desc
.dwValidData
& DMUS_OBJ_FILENAME
) &&
682 (pObjectEntry
->Desc
.dwValidData
& (DMUS_OBJ_FILENAME
| DMUS_OBJ_LOADED
)) &&
683 !strncmpW (Desc
.wszFileName
, pObjectEntry
->Desc
.wszFileName
, DMUS_MAX_FILENAME
)) {
684 TRACE(": found it by filename\n");
689 if (result
== S_OK
) {
690 /*TRACE(": releasing:\n%s - bInvalidDefaultDLS = %i\n - pObject = %p\n", debugstr_DMUS_OBJECTDESC(&pObjectEntry->Desc), pObjectEntry->bInvalidDefaultDLS, pObjectEntry->pObject); */
691 IDirectMusicObject_Release (pObjectEntry
->pObject
);
692 pObjectEntry
->pObject
= NULL
;
693 pObjectEntry
->Desc
.dwValidData
&= ~DMUS_OBJ_LOADED
;
698 static HRESULT WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_ClearCache (LPDIRECTMUSICLOADER8 iface
, REFGUID rguidClass
) {
700 LPWINE_LOADER_ENTRY pObjectEntry
;
701 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
702 TRACE("(%p, %s)\n", This
, debugstr_dmguid(rguidClass
));
704 LIST_FOR_EACH (pEntry
, This
->pObjects
) {
705 pObjectEntry
= LIST_ENTRY (pEntry
, WINE_LOADER_ENTRY
, entry
);
707 if ((IsEqualGUID (rguidClass
, &GUID_DirectMusicAllTypes
) || IsEqualGUID (rguidClass
, &pObjectEntry
->Desc
.guidClass
)) &&
708 (pObjectEntry
->Desc
.dwValidData
& DMUS_OBJ_LOADED
)) {
709 /* basically, wrap to ReleaseObject for each object found */
710 IDirectMusicLoader8_ReleaseObject (iface
, pObjectEntry
->pObject
);
717 static HRESULT WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_EnableCache (LPDIRECTMUSICLOADER8 iface
, REFGUID rguidClass
, BOOL fEnable
) {
718 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
720 TRACE("(%p, %s, %d)\n", This
, debugstr_dmguid(rguidClass
), fEnable
);
721 DMUSIC_GetLoaderSettings (iface
, rguidClass
, NULL
, &bCurrent
);
722 if (bCurrent
== fEnable
)
725 return DMUSIC_SetLoaderSettings (iface
, rguidClass
, NULL
, &fEnable
);
728 static HRESULT WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_EnumObject (LPDIRECTMUSICLOADER8 iface
, REFGUID rguidClass
, DWORD dwIndex
, LPDMUS_OBJECTDESC pDesc
) {
731 LPWINE_LOADER_ENTRY pObjectEntry
;
732 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
733 TRACE("(%p, %s, %d, %p)\n", This
, debugstr_dmguid(rguidClass
), dwIndex
, pDesc
);
735 DM_STRUCT_INIT(pDesc
);
737 LIST_FOR_EACH (pEntry
, This
->pObjects
) {
738 pObjectEntry
= LIST_ENTRY (pEntry
, WINE_LOADER_ENTRY
, entry
);
740 if (IsEqualGUID (rguidClass
, &GUID_DirectMusicAllTypes
) || IsEqualGUID (rguidClass
, &pObjectEntry
->Desc
.guidClass
)) {
741 if (dwCount
== dwIndex
) {
742 *pDesc
= pObjectEntry
->Desc
;
743 /* we aren't supposed to reveal this info */
744 pDesc
->dwValidData
&= ~(DMUS_OBJ_MEMORY
| DMUS_OBJ_STREAM
);
745 pDesc
->pbMemData
= NULL
;
746 pDesc
->llMemLength
= 0;
747 pDesc
->pStream
= NULL
;
754 TRACE(": not found\n");
758 static void WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_CollectGarbage (LPDIRECTMUSICLOADER8 iface
) {
759 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
760 FIXME("(%p): stub\n", This
);
763 static HRESULT WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_ReleaseObjectByUnknown (LPDIRECTMUSICLOADER8 iface
, IUnknown
* pObject
) {
764 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
766 LPDIRECTMUSICOBJECT pObjectInterface
;
768 TRACE("(%p, %p)\n", This
, pObject
);
770 if (IsBadReadPtr (pObject
, sizeof(LPUNKNOWN
))) {
771 ERR(": pObject bad write pointer\n");
774 /* we simply get IDirectMusicObject interface */
775 result
= IUnknown_QueryInterface (pObject
, &IID_IDirectMusicObject
, (LPVOID
*)&pObjectInterface
);
776 if (FAILED(result
)) return result
;
777 /* and release it in old-fashioned way */
778 result
= IDirectMusicLoader8_ReleaseObject (iface
, pObjectInterface
);
779 IDirectMusicObject_Release (pObjectInterface
);
784 static HRESULT WINAPI
IDirectMusicLoaderImpl_IDirectMusicLoader_LoadObjectFromFile (LPDIRECTMUSICLOADER8 iface
, REFGUID rguidClassID
, REFIID iidInterfaceID
, WCHAR
* pwzFilePath
, void** ppObject
) {
785 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
786 DMUS_OBJECTDESC ObjDesc
;
787 WCHAR wszLoaderSearchPath
[MAX_PATH
];
789 TRACE("(%p, %s, %s, %s, %p): wrapping to IDirectMusicLoaderImpl_GetObject\n", This
, debugstr_dmguid(rguidClassID
), debugstr_dmguid(iidInterfaceID
), debugstr_w(pwzFilePath
), ppObject
);
791 DM_STRUCT_INIT(&ObjDesc
);
792 ObjDesc
.dwValidData
= DMUS_OBJ_FILENAME
| DMUS_OBJ_FULLPATH
| DMUS_OBJ_CLASS
; /* I believe I've read somewhere in MSDN that this function requires either full path or relative path */
793 ObjDesc
.guidClass
= *rguidClassID
;
794 /* OK, MSDN says that search order is the following:
795 - current directory (DONE)
796 - windows search path (FIXME: how do I get that?)
797 - loader's search path (DONE)
799 DMUSIC_GetLoaderSettings (iface
, rguidClassID
, wszLoaderSearchPath
, NULL
);
800 /* search in current directory */
801 if (!SearchPathW (NULL
, pwzFilePath
, NULL
, sizeof(ObjDesc
.wszFileName
)/sizeof(WCHAR
), ObjDesc
.wszFileName
, NULL
) &&
802 /* search in loader's search path */
803 !SearchPathW (wszLoaderSearchPath
, pwzFilePath
, NULL
, sizeof(ObjDesc
.wszFileName
)/sizeof(WCHAR
), ObjDesc
.wszFileName
, NULL
)) {
804 /* cannot find file */
805 TRACE(": cannot find file\n");
806 return DMUS_E_LOADER_FAILEDOPEN
;
809 TRACE(": full file path = %s\n", debugstr_w (ObjDesc
.wszFileName
));
811 return IDirectMusicLoaderImpl_IDirectMusicLoader_GetObject (iface
, &ObjDesc
, iidInterfaceID
, ppObject
);
814 static const IDirectMusicLoader8Vtbl DirectMusicLoader_Loader_Vtbl
= {
815 IDirectMusicLoaderImpl_IDirectMusicLoader_QueryInterface
,
816 IDirectMusicLoaderImpl_IDirectMusicLoader_AddRef
,
817 IDirectMusicLoaderImpl_IDirectMusicLoader_Release
,
818 IDirectMusicLoaderImpl_IDirectMusicLoader_GetObject
,
819 IDirectMusicLoaderImpl_IDirectMusicLoader_SetObject
,
820 IDirectMusicLoaderImpl_IDirectMusicLoader_SetSearchDirectory
,
821 IDirectMusicLoaderImpl_IDirectMusicLoader_ScanDirectory
,
822 IDirectMusicLoaderImpl_IDirectMusicLoader_CacheObject
,
823 IDirectMusicLoaderImpl_IDirectMusicLoader_ReleaseObject
,
824 IDirectMusicLoaderImpl_IDirectMusicLoader_ClearCache
,
825 IDirectMusicLoaderImpl_IDirectMusicLoader_EnableCache
,
826 IDirectMusicLoaderImpl_IDirectMusicLoader_EnumObject
,
827 IDirectMusicLoaderImpl_IDirectMusicLoader_CollectGarbage
,
828 IDirectMusicLoaderImpl_IDirectMusicLoader_ReleaseObjectByUnknown
,
829 IDirectMusicLoaderImpl_IDirectMusicLoader_LoadObjectFromFile
832 /* help function for DMUSIC_SetDefaultDLS */
833 static HRESULT
DMUSIC_GetDefaultGMPath (WCHAR wszPath
[MAX_PATH
]) {
835 DWORD returnType
, sizeOfReturnBuffer
= MAX_PATH
;
836 char szPath
[MAX_PATH
];
838 if ((RegOpenKeyExA (HKEY_LOCAL_MACHINE
, "Software\\Microsoft\\DirectMusic" , 0, KEY_READ
, &hkDM
) != ERROR_SUCCESS
) ||
839 (RegQueryValueExA (hkDM
, "GMFilePath", NULL
, &returnType
, (LPBYTE
) szPath
, &sizeOfReturnBuffer
) != ERROR_SUCCESS
)) {
840 WARN(": registry entry missing\n" );
843 /* FIXME: Check return types to ensure we're interpreting data right */
844 MultiByteToWideChar (CP_ACP
, 0, szPath
, -1, wszPath
, MAX_PATH
);
849 /* for ClassFactory */
850 HRESULT WINAPI
DMUSIC_CreateDirectMusicLoaderImpl (LPCGUID lpcGUID
, LPVOID
*ppobj
, LPUNKNOWN pUnkOuter
) {
851 IDirectMusicLoaderImpl
*obj
;
852 DMUS_OBJECTDESC Desc
;
853 LPWINE_LOADER_ENTRY pDefaultDLSEntry
;
856 TRACE("(%s, %p, %p)\n", debugstr_dmguid(lpcGUID
), ppobj
, pUnkOuter
);
857 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicLoaderImpl
));
860 return E_OUTOFMEMORY
;
862 obj
->LoaderVtbl
= &DirectMusicLoader_Loader_Vtbl
;
863 obj
->dwRef
= 0; /* will be inited with QueryInterface */
864 /* init cache/alias list */
865 obj
->pObjects
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(struct list
));
866 list_init (obj
->pObjects
);
868 obj
->pClassSettings
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(struct list
));
869 list_init (obj
->pClassSettings
);
870 DMUSIC_InitLoaderSettings ((LPDIRECTMUSICLOADER8
)obj
);
872 /* set default DLS collection (via SetObject... so that loading via DMUS_OBJ_OBJECT is possible) */
873 DM_STRUCT_INIT(&Desc
);
874 Desc
.dwValidData
= DMUS_OBJ_CLASS
| DMUS_OBJ_FILENAME
| DMUS_OBJ_FULLPATH
| DMUS_OBJ_OBJECT
;
875 Desc
.guidClass
= CLSID_DirectMusicCollection
;
876 Desc
.guidObject
= GUID_DefaultGMCollection
;
877 DMUSIC_GetDefaultGMPath (Desc
.wszFileName
);
878 IDirectMusicLoader_SetObject ((LPDIRECTMUSICLOADER8
)obj
, &Desc
);
879 /* and now the workaroundTM for "invalid" default DLS; basically,
880 my tests showed that if GUID chunk is present in default DLS
881 collection, loader treats it as "invalid" and returns
882 DMUS_E_LOADER_NOFILENAME for all requests for it; basically, we check
883 if out input guidObject was overwritten */
884 pEntry
= list_head (obj
->pObjects
);
885 pDefaultDLSEntry
= LIST_ENTRY (pEntry
, WINE_LOADER_ENTRY
, entry
);
886 if (!IsEqualGUID(&Desc
.guidObject
, &GUID_DefaultGMCollection
)) {
887 pDefaultDLSEntry
->bInvalidDefaultDLS
= TRUE
;
892 return IDirectMusicLoaderImpl_IDirectMusicLoader_QueryInterface ((LPDIRECTMUSICLOADER8
)obj
, lpcGUID
, ppobj
);
895 /* help function for retrieval of search path and caching option for certain class */
896 static HRESULT
DMUSIC_GetLoaderSettings (LPDIRECTMUSICLOADER8 iface
, REFGUID pClassID
, WCHAR
* wszSearchPath
, LPBOOL pbCache
) {
897 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
899 TRACE(": (%p, %s, %p, %p)\n", This
, debugstr_dmguid(pClassID
), wszSearchPath
, pbCache
);
901 LIST_FOR_EACH(pEntry
, This
->pClassSettings
) {
902 LPWINE_LOADER_OPTION pOptionEntry
= LIST_ENTRY(pEntry
, WINE_LOADER_OPTION
, entry
);
903 if (IsEqualCLSID (pClassID
, &pOptionEntry
->guidClass
)) {
905 strcpyW(wszSearchPath
, pOptionEntry
->wszSearchPath
);
907 *pbCache
= pOptionEntry
->bCache
;
914 /* help function for setting search path and caching option for certain class */
915 static HRESULT
DMUSIC_SetLoaderSettings (LPDIRECTMUSICLOADER8 iface
, REFGUID pClassID
, WCHAR
* wszSearchPath
, LPBOOL pbCache
) {
916 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
918 HRESULT result
= S_FALSE
; /* in case pClassID != GUID_DirectMusicAllTypes and not a valid CLSID */
919 TRACE(": (%p, %s, %p, %p)\n", This
, debugstr_dmguid(pClassID
), wszSearchPath
, pbCache
);
921 LIST_FOR_EACH(pEntry
, This
->pClassSettings
) {
922 LPWINE_LOADER_OPTION pOptionEntry
= LIST_ENTRY(pEntry
, WINE_LOADER_OPTION
, entry
);
923 /* well, either we have GUID_DirectMusicAllTypes and need to set it to all,
924 or specific CLSID is given and we set it only to it */
925 if (IsEqualGUID (pClassID
, &GUID_DirectMusicAllTypes
) ||
926 IsEqualCLSID (pClassID
, &pOptionEntry
->guidClass
)) {
928 strcpyW(pOptionEntry
->wszSearchPath
, wszSearchPath
);
930 pOptionEntry
->bCache
= *pbCache
;
938 static HRESULT
DMUSIC_InitLoaderSettings (LPDIRECTMUSICLOADER8 iface
) {
939 ICOM_THIS_MULTI(IDirectMusicLoaderImpl
, LoaderVtbl
, iface
);
941 /* hard-coded list of classes */
942 static REFCLSID classes
[] = {
943 &CLSID_DirectMusicAudioPathConfig
,
944 &CLSID_DirectMusicBand
,
945 &CLSID_DirectMusicContainer
,
946 &CLSID_DirectMusicCollection
,
947 &CLSID_DirectMusicChordMap
,
948 &CLSID_DirectMusicSegment
,
949 &CLSID_DirectMusicScript
,
950 &CLSID_DirectMusicSong
,
951 &CLSID_DirectMusicStyle
,
952 &CLSID_DirectMusicGraph
,
953 &CLSID_DirectSoundWave
957 WCHAR wszCurrent
[MAX_PATH
];
959 TRACE(": (%p)\n", This
);
960 GetCurrentDirectoryW (MAX_PATH
, wszCurrent
);
962 for (i
= 0; i
< sizeof(classes
)/sizeof(REFCLSID
); i
++) {
963 LPWINE_LOADER_OPTION pNewSetting
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(WINE_LOADER_OPTION
));
964 pNewSetting
->guidClass
= *classes
[i
];
965 strcpyW (pNewSetting
->wszSearchPath
, wszCurrent
);
966 pNewSetting
->bCache
= TRUE
;
967 list_add_tail (This
->pClassSettings
, &pNewSetting
->entry
);