48968b377985e0599da7675a94a7247e09bff82b
[reactos.git] / reactos / dll / directx / wine / msdmo / dmoreg.c
1 /*
2 * Copyright (C) 2003 Michael Günnewig
3 * Copyright (C) 2003 CodeWeavers Inc. (Ulrich Czekalla)
4 *
5 * This library 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.
9 *
10 * This library 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.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #include "precomp.h"
21
22 #include <winuser.h>
23 #include <winreg.h>
24 #include <wine/unicode.h>
25 #include <dmo.h>
26
27 #define MSDMO_MAJOR_VERSION 6
28
29 static const WCHAR szDMORootKey[] =
30 {
31 'D','i','r','e','c','t','S','h','o','w','\\',
32 'M','e','d','i','a','O','b','j','e','c','t','s',0
33 };
34
35 static const WCHAR szDMOInputType[] =
36 {
37 'I','n','p','u','t','T','y','p','e','s',0
38 };
39
40 static const WCHAR szDMOOutputType[] =
41 {
42 'O','u','t','p','u','t','T','y','p','e','s',0
43 };
44
45 static const WCHAR szDMOKeyed[] =
46 {
47 'K','e','y','e','d',0
48 };
49
50 static const WCHAR szDMOCategories[] =
51 {
52 'C','a','t','e','g','o','r','i','e','s',0
53 };
54
55 static const WCHAR szGUIDFmt[] =
56 {
57 '%','0','8','X','-','%','0','4','X','-','%','0','4','X','-','%','0',
58 '2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2',
59 'X','%','0','2','X','%','0','2','X','%','0','2','X',0
60 };
61
62 static const WCHAR szCat3Fmt[] =
63 {
64 '%','s','\\','%','s','\\','%','s',0
65 };
66
67 static const WCHAR szCat2Fmt[] =
68 {
69 '%','s','\\','%','s',0
70 };
71
72 static const WCHAR szToGuidFmt[] =
73 {
74 '{','%','s','}',0
75 };
76
77
78 typedef struct
79 {
80 IEnumDMO IEnumDMO_iface;
81 LONG ref;
82 DWORD index;
83 const GUID* guidCategory;
84 DWORD dwFlags;
85 DWORD cInTypes;
86 DMO_PARTIAL_MEDIATYPE *pInTypes;
87 DWORD cOutTypes;
88 DMO_PARTIAL_MEDIATYPE *pOutTypes;
89 HKEY hkey;
90 } IEnumDMOImpl;
91
92 static inline IEnumDMOImpl *impl_from_IEnumDMO(IEnumDMO *iface)
93 {
94 return CONTAINING_RECORD(iface, IEnumDMOImpl, IEnumDMO_iface);
95 }
96
97 static HRESULT read_types(HKEY root, LPCWSTR key, ULONG *supplied, ULONG requested, DMO_PARTIAL_MEDIATYPE* types);
98
99 static const IEnumDMOVtbl edmovt;
100
101 static LPWSTR GUIDToString(LPWSTR lpwstr, REFGUID lpcguid)
102 {
103 wsprintfW(lpwstr, szGUIDFmt, lpcguid->Data1, lpcguid->Data2,
104 lpcguid->Data3, lpcguid->Data4[0], lpcguid->Data4[1],
105 lpcguid->Data4[2], lpcguid->Data4[3], lpcguid->Data4[4],
106 lpcguid->Data4[5], lpcguid->Data4[6], lpcguid->Data4[7]);
107
108 return lpwstr;
109 }
110
111 static BOOL IsMediaTypeEqual(const DMO_PARTIAL_MEDIATYPE* mt1, const DMO_PARTIAL_MEDIATYPE* mt2)
112 {
113
114 return (IsEqualCLSID(&mt1->type, &mt2->type) ||
115 IsEqualCLSID(&mt2->type, &GUID_NULL) ||
116 IsEqualCLSID(&mt1->type, &GUID_NULL)) &&
117 (IsEqualCLSID(&mt1->subtype, &mt2->subtype) ||
118 IsEqualCLSID(&mt2->subtype, &GUID_NULL) ||
119 IsEqualCLSID(&mt1->subtype, &GUID_NULL));
120 }
121
122 static HRESULT write_types(HKEY hkey, LPCWSTR name, const DMO_PARTIAL_MEDIATYPE* types, DWORD count)
123 {
124 HRESULT hres = S_OK;
125 if (MSDMO_MAJOR_VERSION > 5)
126 {
127 hres = RegSetValueExW(hkey, name, 0, REG_BINARY, (const BYTE*) types,
128 count* sizeof(DMO_PARTIAL_MEDIATYPE));
129 }
130 else
131 {
132 HKEY skey1,skey2,skey3;
133 DWORD index = 0;
134 WCHAR szGuidKey[64];
135
136 hres = RegCreateKeyExW(hkey, name, 0, NULL, REG_OPTION_NON_VOLATILE,
137 KEY_WRITE, NULL, &skey1, NULL);
138 while (index < count)
139 {
140 GUIDToString(szGuidKey,&types[index].type);
141 hres = RegCreateKeyExW(skey1, szGuidKey, 0, NULL,
142 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &skey2, NULL);
143 GUIDToString(szGuidKey,&types[index].subtype);
144 hres = RegCreateKeyExW(skey2, szGuidKey, 0, NULL,
145 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &skey3, NULL);
146 RegCloseKey(skey3);
147 RegCloseKey(skey2);
148 index ++;
149 }
150 RegCloseKey(skey1);
151 }
152
153 return hres;
154 }
155
156 /***************************************************************
157 * DMORegister (MSDMO.@)
158 *
159 * Register a DirectX Media Object.
160 */
161 HRESULT WINAPI DMORegister(
162 LPCWSTR szName,
163 REFCLSID clsidDMO,
164 REFGUID guidCategory,
165 DWORD dwFlags,
166 DWORD cInTypes,
167 const DMO_PARTIAL_MEDIATYPE *pInTypes,
168 DWORD cOutTypes,
169 const DMO_PARTIAL_MEDIATYPE *pOutTypes
170 )
171 {
172 WCHAR szguid[64];
173 HRESULT hres;
174 HKEY hrkey = 0;
175 HKEY hkey = 0;
176 HKEY hckey = 0;
177 HKEY hclskey = 0;
178
179 TRACE("%s\n", debugstr_w(szName));
180
181 hres = RegCreateKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, NULL,
182 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hrkey, NULL);
183 if (ERROR_SUCCESS != hres)
184 goto lend;
185
186 /* Create clsidDMO key under MediaObjects */
187 hres = RegCreateKeyExW(hrkey, GUIDToString(szguid, clsidDMO), 0, NULL,
188 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
189 if (ERROR_SUCCESS != hres)
190 goto lend;
191
192 /* Set default Name value */
193 hres = RegSetValueExW(hkey, NULL, 0, REG_SZ, (const BYTE*) szName,
194 (strlenW(szName) + 1) * sizeof(WCHAR));
195
196 /* Set InputTypes */
197 hres = write_types(hkey, szDMOInputType, pInTypes, cInTypes);
198
199 /* Set OutputTypes */
200 hres = write_types(hkey, szDMOOutputType, pOutTypes, cOutTypes);
201
202 if (dwFlags & DMO_REGISTERF_IS_KEYED)
203 {
204 /* Create Keyed key */
205 hres = RegCreateKeyExW(hkey, szDMOKeyed, 0, NULL,
206 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hckey, NULL);
207 if (ERROR_SUCCESS != hres)
208 goto lend;
209 RegCloseKey(hckey);
210 }
211
212 /* Register the category */
213 hres = RegCreateKeyExW(hrkey, szDMOCategories, 0, NULL,
214 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hckey, NULL);
215 if (ERROR_SUCCESS != hres)
216 goto lend;
217
218 RegCloseKey(hkey);
219
220 hres = RegCreateKeyExW(hckey, GUIDToString(szguid, guidCategory), 0, NULL,
221 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
222 if (ERROR_SUCCESS != hres)
223 goto lend;
224 hres = RegCreateKeyExW(hkey, GUIDToString(szguid, clsidDMO), 0, NULL,
225 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hclskey, NULL);
226 if (ERROR_SUCCESS != hres)
227 goto lend;
228
229 lend:
230 if (hkey)
231 RegCloseKey(hkey);
232 if (hckey)
233 RegCloseKey(hckey);
234 if (hclskey)
235 RegCloseKey(hclskey);
236 if (hrkey)
237 RegCloseKey(hrkey);
238
239 TRACE(" hresult=0x%08x\n", hres);
240 return hres;
241 }
242
243
244 /***************************************************************
245 * DMOUnregister (MSDMO.@)
246 *
247 * Unregister a DirectX Media Object.
248 */
249 HRESULT WINAPI DMOUnregister(REFCLSID clsidDMO, REFGUID guidCategory)
250 {
251 HRESULT hres;
252 WCHAR szguid[64];
253 HKEY hrkey = 0;
254 HKEY hckey = 0;
255
256 GUIDToString(szguid, clsidDMO);
257
258 TRACE("%s %p\n", debugstr_w(szguid), guidCategory);
259
260 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, KEY_WRITE, &hrkey);
261 if (ERROR_SUCCESS != hres)
262 goto lend;
263
264 hres = RegDeleteKeyW(hrkey, szguid);
265 if (ERROR_SUCCESS != hres)
266 goto lend;
267
268 hres = RegOpenKeyExW(hrkey, szDMOCategories, 0, KEY_WRITE, &hckey);
269 if (ERROR_SUCCESS != hres)
270 goto lend;
271
272 hres = RegDeleteKeyW(hckey, szguid);
273 if (ERROR_SUCCESS != hres)
274 goto lend;
275
276 lend:
277 if (hckey)
278 RegCloseKey(hckey);
279 if (hrkey)
280 RegCloseKey(hrkey);
281
282 return hres;
283 }
284
285
286 /***************************************************************
287 * DMOGetName (MSDMO.@)
288 *
289 * Get DMP Name from the registry
290 */
291 HRESULT WINAPI DMOGetName(REFCLSID clsidDMO, WCHAR szName[])
292 {
293 WCHAR szguid[64];
294 HRESULT hres;
295 HKEY hrkey = 0;
296 HKEY hkey = 0;
297 static const INT max_name_len = 80;
298 DWORD count;
299
300 TRACE("%s\n", debugstr_guid(clsidDMO));
301
302 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey,
303 0, KEY_READ, &hrkey);
304 if (ERROR_SUCCESS != hres)
305 goto lend;
306
307 hres = RegOpenKeyExW(hrkey, GUIDToString(szguid, clsidDMO),
308 0, KEY_READ, &hkey);
309 if (ERROR_SUCCESS != hres)
310 goto lend;
311
312 count = max_name_len * sizeof(WCHAR);
313 hres = RegQueryValueExW(hkey, NULL, NULL, NULL,
314 (LPBYTE) szName, &count);
315
316 TRACE(" szName=%s\n", debugstr_w(szName));
317 lend:
318 if (hkey)
319 RegCloseKey(hrkey);
320 if (hkey)
321 RegCloseKey(hkey);
322
323 return hres;
324 }
325
326
327 /**************************************************************************
328 * IEnumDMOImpl_Destructor
329 */
330 static BOOL IEnumDMOImpl_Destructor(IEnumDMOImpl* This)
331 {
332 TRACE("%p\n", This);
333
334 if (This->hkey)
335 RegCloseKey(This->hkey);
336
337 HeapFree(GetProcessHeap(), 0, This->pInTypes);
338 HeapFree(GetProcessHeap(), 0, This->pOutTypes);
339
340 return TRUE;
341 }
342
343
344 /**************************************************************************
345 * IEnumDMO_Constructor
346 */
347 static IEnumDMO * IEnumDMO_Constructor(
348 REFGUID guidCategory,
349 DWORD dwFlags,
350 DWORD cInTypes,
351 const DMO_PARTIAL_MEDIATYPE *pInTypes,
352 DWORD cOutTypes,
353 const DMO_PARTIAL_MEDIATYPE *pOutTypes)
354 {
355 UINT size;
356 IEnumDMOImpl* lpedmo;
357 BOOL ret = FALSE;
358
359 lpedmo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumDMOImpl));
360
361 if (lpedmo)
362 {
363 lpedmo->ref = 1;
364 lpedmo->IEnumDMO_iface.lpVtbl = &edmovt;
365 lpedmo->index = -1;
366 lpedmo->guidCategory = guidCategory;
367 lpedmo->dwFlags = dwFlags;
368
369 if (cInTypes > 0)
370 {
371 size = cInTypes * sizeof(DMO_PARTIAL_MEDIATYPE);
372 lpedmo->pInTypes = HeapAlloc(GetProcessHeap(), 0, size);
373 if (!lpedmo->pInTypes)
374 goto lerr;
375 memcpy(lpedmo->pInTypes, pInTypes, size);
376 lpedmo->cInTypes = cInTypes;
377 }
378
379 if (cOutTypes > 0)
380 {
381 size = cOutTypes * sizeof(DMO_PARTIAL_MEDIATYPE);
382 lpedmo->pOutTypes = HeapAlloc(GetProcessHeap(), 0, size);
383 if (!lpedmo->pOutTypes)
384 goto lerr;
385 memcpy(lpedmo->pOutTypes, pOutTypes, size);
386 lpedmo->cOutTypes = cOutTypes;
387 }
388
389 /* If not filtering by category enum from media objects root */
390 if (IsEqualGUID(guidCategory, &GUID_NULL))
391 {
392 if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey,
393 0, KEY_READ, &lpedmo->hkey))
394 ret = TRUE;
395 }
396 else
397 {
398 WCHAR szguid[64];
399 WCHAR szKey[MAX_PATH];
400
401 wsprintfW(szKey, szCat3Fmt, szDMORootKey, szDMOCategories,
402 GUIDToString(szguid, guidCategory));
403 if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey,
404 0, KEY_READ, &lpedmo->hkey))
405 ret = TRUE;
406 }
407
408 lerr:
409 if(!ret)
410 {
411 IEnumDMOImpl_Destructor(lpedmo);
412 HeapFree(GetProcessHeap(),0,lpedmo);
413 lpedmo = NULL;
414 }
415 }
416
417 TRACE("returning %p\n", lpedmo);
418
419 return (IEnumDMO*)lpedmo;
420 }
421
422
423 /******************************************************************************
424 * IEnumDMO_fnAddRef
425 */
426 static ULONG WINAPI IEnumDMO_fnAddRef(IEnumDMO * iface)
427 {
428 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
429 return InterlockedIncrement(&This->ref);
430 }
431
432
433 /**************************************************************************
434 * EnumDMO_QueryInterface
435 */
436 static HRESULT WINAPI IEnumDMO_fnQueryInterface(
437 IEnumDMO* iface,
438 REFIID riid,
439 LPVOID *ppvObj)
440 {
441 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
442
443 *ppvObj = NULL;
444
445 if(IsEqualIID(riid, &IID_IUnknown))
446 *ppvObj = This;
447 else if(IsEqualIID(riid, &IID_IEnumDMO))
448 *ppvObj = This;
449
450 if(*ppvObj)
451 {
452 IEnumDMO_fnAddRef(*ppvObj);
453 return S_OK;
454 }
455
456 return E_NOINTERFACE;
457 }
458
459
460 /******************************************************************************
461 * IEnumDMO_fnRelease
462 */
463 static ULONG WINAPI IEnumDMO_fnRelease(IEnumDMO * iface)
464 {
465 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
466 ULONG refCount = InterlockedDecrement(&This->ref);
467
468 if (!refCount)
469 {
470 IEnumDMOImpl_Destructor(This);
471 HeapFree(GetProcessHeap(),0,This);
472 }
473 return refCount;
474 }
475
476
477 /******************************************************************************
478 * IEnumDMO_fnNext
479 */
480 static HRESULT WINAPI IEnumDMO_fnNext(
481 IEnumDMO * iface,
482 DWORD cItemsToFetch,
483 CLSID * pCLSID,
484 WCHAR ** Names,
485 DWORD * pcItemsFetched)
486 {
487 FILETIME ft;
488 HKEY hkey;
489 WCHAR szNextKey[MAX_PATH];
490 WCHAR szGuidKey[64];
491 WCHAR szKey[MAX_PATH];
492 WCHAR szValue[MAX_PATH];
493 DWORD len;
494 UINT count = 0;
495 HRESULT hres = S_OK;
496
497 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
498
499 TRACE("--> (%p) %d %p %p %p\n", iface, cItemsToFetch, pCLSID, Names, pcItemsFetched);
500
501 if (!pCLSID || !Names || !pcItemsFetched)
502 return E_POINTER;
503
504 while (count < cItemsToFetch)
505 {
506 This->index++;
507
508 len = MAX_PATH;
509 hres = RegEnumKeyExW(This->hkey, This->index, szNextKey, &len, NULL, NULL, NULL, &ft);
510 if (hres != ERROR_SUCCESS)
511 break;
512
513 TRACE("found %s\n", debugstr_w(szNextKey));
514
515 if (!(This->dwFlags & DMO_ENUMF_INCLUDE_KEYED))
516 {
517 wsprintfW(szKey, szCat3Fmt, szDMORootKey, szNextKey, szDMOKeyed);
518 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hkey);
519 if (ERROR_SUCCESS == hres)
520 {
521 RegCloseKey(hkey);
522 /* Skip Keyed entries */
523 continue;
524 }
525 }
526
527 wsprintfW(szKey, szCat2Fmt, szDMORootKey, szNextKey);
528 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hkey);
529
530 if (This->pInTypes)
531 {
532 UINT i, j;
533 DWORD cInTypes;
534 DMO_PARTIAL_MEDIATYPE* pInTypes;
535
536 hres = read_types(hkey, szDMOInputType, &cInTypes,
537 sizeof(szValue)/sizeof(DMO_PARTIAL_MEDIATYPE),
538 (DMO_PARTIAL_MEDIATYPE*)szValue);
539
540 if (ERROR_SUCCESS != hres)
541 {
542 RegCloseKey(hkey);
543 continue;
544 }
545
546 pInTypes = (DMO_PARTIAL_MEDIATYPE*) szValue;
547
548 for (i = 0; i < This->cInTypes; i++)
549 {
550 for (j = 0; j < cInTypes; j++)
551 {
552 if (IsMediaTypeEqual(&pInTypes[j], &This->pInTypes[i]))
553 break;
554 }
555
556 if (j >= cInTypes)
557 break;
558 }
559
560 if (i < This->cInTypes)
561 {
562 RegCloseKey(hkey);
563 continue;
564 }
565 }
566
567 if (This->pOutTypes)
568 {
569 UINT i, j;
570 DWORD cOutTypes;
571 DMO_PARTIAL_MEDIATYPE* pOutTypes;
572
573 hres = read_types(hkey, szDMOOutputType, &cOutTypes,
574 sizeof(szValue)/sizeof(DMO_PARTIAL_MEDIATYPE),
575 (DMO_PARTIAL_MEDIATYPE*)szValue);
576
577 if (ERROR_SUCCESS != hres)
578 {
579 RegCloseKey(hkey);
580 continue;
581 }
582
583 pOutTypes = (DMO_PARTIAL_MEDIATYPE*) szValue;
584
585 for (i = 0; i < This->cOutTypes; i++)
586 {
587 for (j = 0; j < cOutTypes; j++)
588 {
589 if (IsMediaTypeEqual(&pOutTypes[j], &This->pOutTypes[i]))
590 break;
591 }
592
593 if (j >= cOutTypes)
594 break;
595 }
596
597 if (i < This->cOutTypes)
598 {
599 RegCloseKey(hkey);
600 continue;
601 }
602 }
603
604 /* Media object wasn't filtered so add it to return list */
605 Names[count] = NULL;
606 len = MAX_PATH * sizeof(WCHAR);
607 hres = RegQueryValueExW(hkey, NULL, NULL, NULL, (LPBYTE) szValue, &len);
608 if (ERROR_SUCCESS == hres)
609 {
610 Names[count] = HeapAlloc(GetProcessHeap(), 0, strlenW(szValue) + 1);
611 if (Names[count])
612 strcmpW(Names[count], szValue);
613 }
614 wsprintfW(szGuidKey,szToGuidFmt,szNextKey);
615 CLSIDFromString(szGuidKey, &pCLSID[count]);
616
617 TRACE("found match %s %s\n", debugstr_w(szValue), debugstr_w(szNextKey));
618 RegCloseKey(hkey);
619 count++;
620 }
621
622 *pcItemsFetched = count;
623 if (*pcItemsFetched < cItemsToFetch)
624 hres = S_FALSE;
625
626 TRACE("<-- %i found\n",count);
627 return hres;
628 }
629
630
631 /******************************************************************************
632 * IEnumDMO_fnSkip
633 */
634 static HRESULT WINAPI IEnumDMO_fnSkip(IEnumDMO * iface, DWORD cItemsToSkip)
635 {
636 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
637
638 This->index += cItemsToSkip;
639
640 return S_OK;
641 }
642
643
644 /******************************************************************************
645 * IEnumDMO_fnReset
646 */
647 static HRESULT WINAPI IEnumDMO_fnReset(IEnumDMO * iface)
648 {
649 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
650
651 This->index = -1;
652
653 return S_OK;
654 }
655
656
657 /******************************************************************************
658 * IEnumDMO_fnClone
659 */
660 static HRESULT WINAPI IEnumDMO_fnClone(IEnumDMO * iface, IEnumDMO **ppEnum)
661 {
662 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
663
664 FIXME("(%p)->() to (%p)->() E_NOTIMPL\n", This, ppEnum);
665
666 return E_NOTIMPL;
667 }
668
669
670 /***************************************************************
671 * DMOEnum (MSDMO.@)
672 *
673 * Enumerate DirectX Media Objects in the registry.
674 */
675 HRESULT WINAPI DMOEnum(
676 REFGUID guidCategory,
677 DWORD dwFlags,
678 DWORD cInTypes,
679 const DMO_PARTIAL_MEDIATYPE *pInTypes,
680 DWORD cOutTypes,
681 const DMO_PARTIAL_MEDIATYPE *pOutTypes,
682 IEnumDMO **ppEnum)
683 {
684 HRESULT hres = E_FAIL;
685
686 TRACE("guidCategory=%p dwFlags=0x%08x cInTypes=%d cOutTypes=%d\n",
687 guidCategory, dwFlags, cInTypes, cOutTypes);
688
689 *ppEnum = IEnumDMO_Constructor(guidCategory, dwFlags, cInTypes,
690 pInTypes, cOutTypes, pOutTypes);
691 if (*ppEnum)
692 hres = S_OK;
693
694 return hres;
695 }
696
697
698 static const IEnumDMOVtbl edmovt =
699 {
700 IEnumDMO_fnQueryInterface,
701 IEnumDMO_fnAddRef,
702 IEnumDMO_fnRelease,
703 IEnumDMO_fnNext,
704 IEnumDMO_fnSkip,
705 IEnumDMO_fnReset,
706 IEnumDMO_fnClone,
707 };
708
709
710 HRESULT read_types(HKEY root, LPCWSTR key, ULONG *supplied, ULONG requested, DMO_PARTIAL_MEDIATYPE* types )
711 {
712 HRESULT ret = S_OK;
713 if (MSDMO_MAJOR_VERSION > 5)
714 {
715 DWORD len;
716 len = requested * sizeof(DMO_PARTIAL_MEDIATYPE);
717 ret = RegQueryValueExW(root, key, NULL, NULL, (LPBYTE) types, &len);
718 *supplied = len / sizeof(DMO_PARTIAL_MEDIATYPE);
719 }
720 else
721 {
722 HKEY hkey;
723 WCHAR szGuidKey[64];
724
725 *supplied = 0;
726 if (ERROR_SUCCESS == RegOpenKeyExW(root, key, 0, KEY_READ, &hkey))
727 {
728 int index = 0;
729 WCHAR szNextKey[MAX_PATH];
730 DWORD len;
731 LONG rc = ERROR_SUCCESS;
732
733 while (rc == ERROR_SUCCESS)
734 {
735 len = MAX_PATH;
736 rc = RegEnumKeyExW(hkey, index, szNextKey, &len, NULL, NULL, NULL, NULL);
737 if (rc == ERROR_SUCCESS)
738 {
739 HKEY subk;
740 int sub_index = 0;
741 LONG rcs = ERROR_SUCCESS;
742 WCHAR szSubKey[MAX_PATH];
743
744 RegOpenKeyExW(hkey, szNextKey, 0, KEY_READ, &subk);
745 while (rcs == ERROR_SUCCESS)
746 {
747 len = MAX_PATH;
748 rcs = RegEnumKeyExW(subk, sub_index, szSubKey, &len, NULL, NULL, NULL, NULL);
749 if (rcs == ERROR_SUCCESS)
750 {
751 if (*supplied >= requested)
752 {
753 /* Bailing */
754 ret = S_FALSE;
755 rc = ERROR_MORE_DATA;
756 rcs = ERROR_MORE_DATA;
757 break;
758 }
759
760 wsprintfW(szGuidKey,szToGuidFmt,szNextKey);
761 CLSIDFromString(szGuidKey, &types[*supplied].type);
762 wsprintfW(szGuidKey,szToGuidFmt,szSubKey);
763 CLSIDFromString(szGuidKey, &types[*supplied].subtype);
764 TRACE("Adding type %s subtype %s at index %i\n",
765 debugstr_guid(&types[*supplied].type),
766 debugstr_guid(&types[*supplied].subtype),
767 *supplied);
768 (*supplied)++;
769 }
770 sub_index++;
771 }
772 index++;
773 }
774 }
775 RegCloseKey(hkey);
776 }
777 }
778 return ret;
779 }
780
781 /***************************************************************
782 * DMOGetTypes (MSDMO.@)
783 */
784 HRESULT WINAPI DMOGetTypes(REFCLSID clsidDMO,
785 ULONG ulInputTypesRequested,
786 ULONG* pulInputTypesSupplied,
787 DMO_PARTIAL_MEDIATYPE* pInputTypes,
788 ULONG ulOutputTypesRequested,
789 ULONG* pulOutputTypesSupplied,
790 DMO_PARTIAL_MEDIATYPE* pOutputTypes)
791 {
792 HKEY root,hkey;
793 HRESULT ret = S_OK;
794 WCHAR szguid[64];
795
796 TRACE ("(%s,%u,%p,%p,%u,%p,%p)\n", debugstr_guid(clsidDMO), ulInputTypesRequested,
797 pulInputTypesSupplied, pInputTypes, ulOutputTypesRequested, pulOutputTypesSupplied,
798 pOutputTypes);
799
800 if (ERROR_SUCCESS != RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0,
801 KEY_READ, &root))
802 return E_FAIL;
803
804 if (ERROR_SUCCESS != RegOpenKeyExW(root,GUIDToString(szguid,clsidDMO) , 0,
805 KEY_READ, &hkey))
806 {
807 RegCloseKey(root);
808 return E_FAIL;
809 }
810
811 if (ulInputTypesRequested > 0)
812 {
813 ret = read_types(hkey, szDMOInputType, pulInputTypesSupplied, ulInputTypesRequested, pInputTypes );
814 }
815 else
816 *pulInputTypesSupplied = 0;
817
818 if (ulOutputTypesRequested > 0)
819 {
820 HRESULT ret2;
821 ret2 = read_types(hkey, szDMOOutputType, pulOutputTypesSupplied, ulOutputTypesRequested, pOutputTypes );
822
823 if (ret == S_OK)
824 ret = ret2;
825 }
826 else
827 *pulOutputTypesSupplied = 0;
828
829 return ret;
830 }