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