regedit: Allow importing strings with escaped NULL.
[wine.git] / dlls / msdmo / dmoreg.c
blobe8f67c56d6d7d49e84845221bb0c74948e9d48b0
1 /*
2 * Copyright (C) 2003 Michael Günnewig
3 * Copyright (C) 2003 CodeWeavers Inc. (Ulrich Czekalla)
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.
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.
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
20 #include <stdarg.h>
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"
33 WINE_DEFAULT_DEBUG_CHANNEL(msdmo);
35 #define MSDMO_MAJOR_VERSION 6
37 static const WCHAR szDMORootKey[] =
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 };
43 static const WCHAR szDMOInputType[] =
45 'I','n','p','u','t','T','y','p','e','s',0
48 static const WCHAR szDMOOutputType[] =
50 'O','u','t','p','u','t','T','y','p','e','s',0
53 static const WCHAR szDMOKeyed[] =
55 'K','e','y','e','d',0
58 static const WCHAR szDMOCategories[] =
60 'C','a','t','e','g','o','r','i','e','s',0
63 static const WCHAR szGUIDFmt[] =
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
70 static const WCHAR szCat3Fmt[] =
72 '%','s','\\','%','s','\\','%','s',0
75 static const WCHAR szCat2Fmt[] =
77 '%','s','\\','%','s',0
80 static const WCHAR szToGuidFmt[] =
82 '{','%','s','}',0
86 typedef struct
88 IEnumDMO IEnumDMO_iface;
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;
100 static inline IEnumDMOImpl *impl_from_IEnumDMO(IEnumDMO *iface)
102 return CONTAINING_RECORD(iface, IEnumDMOImpl, IEnumDMO_iface);
105 static HRESULT read_types(HKEY root, LPCWSTR key, ULONG *supplied, ULONG requested, DMO_PARTIAL_MEDIATYPE* types);
107 static const IEnumDMOVtbl edmovt;
109 static LPWSTR GUIDToString(LPWSTR lpwstr, REFGUID lpcguid)
111 wsprintfW(lpwstr, szGUIDFmt, lpcguid->Data1, lpcguid->Data2,
112 lpcguid->Data3, lpcguid->Data4[0], lpcguid->Data4[1],
113 lpcguid->Data4[2], lpcguid->Data4[3], lpcguid->Data4[4],
114 lpcguid->Data4[5], lpcguid->Data4[6], lpcguid->Data4[7]);
116 return lpwstr;
119 static BOOL IsMediaTypeEqual(const DMO_PARTIAL_MEDIATYPE* mt1, const DMO_PARTIAL_MEDIATYPE* mt2)
122 return (IsEqualCLSID(&mt1->type, &mt2->type) ||
123 IsEqualCLSID(&mt2->type, &GUID_NULL) ||
124 IsEqualCLSID(&mt1->type, &GUID_NULL)) &&
125 (IsEqualCLSID(&mt1->subtype, &mt2->subtype) ||
126 IsEqualCLSID(&mt2->subtype, &GUID_NULL) ||
127 IsEqualCLSID(&mt1->subtype, &GUID_NULL));
130 static HRESULT write_types(HKEY hkey, LPCWSTR name, const DMO_PARTIAL_MEDIATYPE* types, DWORD count)
132 HRESULT hres = S_OK;
133 if (MSDMO_MAJOR_VERSION > 5)
135 hres = RegSetValueExW(hkey, name, 0, REG_BINARY, (const BYTE*) types,
136 count* sizeof(DMO_PARTIAL_MEDIATYPE));
138 else
140 HKEY skey1,skey2,skey3;
141 DWORD index = 0;
142 WCHAR szGuidKey[64];
144 hres = RegCreateKeyExW(hkey, name, 0, NULL, REG_OPTION_NON_VOLATILE,
145 KEY_WRITE, NULL, &skey1, NULL);
146 while (index < count)
148 GUIDToString(szGuidKey,&types[index].type);
149 hres = RegCreateKeyExW(skey1, szGuidKey, 0, NULL,
150 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &skey2, NULL);
151 GUIDToString(szGuidKey,&types[index].subtype);
152 hres = RegCreateKeyExW(skey2, szGuidKey, 0, NULL,
153 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &skey3, NULL);
154 RegCloseKey(skey3);
155 RegCloseKey(skey2);
156 index ++;
158 RegCloseKey(skey1);
161 return hres;
164 /***************************************************************
165 * DMORegister (MSDMO.@)
167 * Register a DirectX Media Object.
169 HRESULT WINAPI DMORegister(
170 LPCWSTR szName,
171 REFCLSID clsidDMO,
172 REFGUID guidCategory,
173 DWORD dwFlags,
174 DWORD cInTypes,
175 const DMO_PARTIAL_MEDIATYPE *pInTypes,
176 DWORD cOutTypes,
177 const DMO_PARTIAL_MEDIATYPE *pOutTypes
180 WCHAR szguid[64];
181 HRESULT hres;
182 HKEY hrkey = 0;
183 HKEY hkey = 0;
184 HKEY hckey = 0;
185 HKEY hclskey = 0;
187 TRACE("%s\n", debugstr_w(szName));
189 hres = RegCreateKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, NULL,
190 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hrkey, NULL);
191 if (ERROR_SUCCESS != hres)
192 goto lend;
194 /* Create clsidDMO key under MediaObjects */
195 hres = RegCreateKeyExW(hrkey, GUIDToString(szguid, clsidDMO), 0, NULL,
196 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
197 if (ERROR_SUCCESS != hres)
198 goto lend;
200 /* Set default Name value */
201 hres = RegSetValueExW(hkey, NULL, 0, REG_SZ, (const BYTE*) szName,
202 (strlenW(szName) + 1) * sizeof(WCHAR));
204 /* Set InputTypes */
205 hres = write_types(hkey, szDMOInputType, pInTypes, cInTypes);
207 /* Set OutputTypes */
208 hres = write_types(hkey, szDMOOutputType, pOutTypes, cOutTypes);
210 if (dwFlags & DMO_REGISTERF_IS_KEYED)
212 /* Create Keyed key */
213 hres = RegCreateKeyExW(hkey, szDMOKeyed, 0, NULL,
214 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hckey, NULL);
215 if (ERROR_SUCCESS != hres)
216 goto lend;
217 RegCloseKey(hckey);
220 /* Register the category */
221 hres = RegCreateKeyExW(hrkey, szDMOCategories, 0, NULL,
222 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hckey, NULL);
223 if (ERROR_SUCCESS != hres)
224 goto lend;
226 RegCloseKey(hkey);
228 hres = RegCreateKeyExW(hckey, GUIDToString(szguid, guidCategory), 0, NULL,
229 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
230 if (ERROR_SUCCESS != hres)
231 goto lend;
232 hres = RegCreateKeyExW(hkey, GUIDToString(szguid, clsidDMO), 0, NULL,
233 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hclskey, NULL);
234 if (ERROR_SUCCESS != hres)
235 goto lend;
237 lend:
238 if (hkey)
239 RegCloseKey(hkey);
240 if (hckey)
241 RegCloseKey(hckey);
242 if (hclskey)
243 RegCloseKey(hclskey);
244 if (hrkey)
245 RegCloseKey(hrkey);
247 TRACE(" hresult=0x%08x\n", hres);
248 return hres;
252 /***************************************************************
253 * DMOUnregister (MSDMO.@)
255 * Unregister a DirectX Media Object.
257 HRESULT WINAPI DMOUnregister(REFCLSID clsidDMO, REFGUID guidCategory)
259 HRESULT hres;
260 WCHAR szguid[64];
261 HKEY hrkey = 0;
262 HKEY hckey = 0;
264 GUIDToString(szguid, clsidDMO);
266 TRACE("%s %p\n", debugstr_w(szguid), guidCategory);
268 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, KEY_WRITE, &hrkey);
269 if (ERROR_SUCCESS != hres)
270 goto lend;
272 hres = RegDeleteKeyW(hrkey, szguid);
273 if (ERROR_SUCCESS != hres)
274 goto lend;
276 hres = RegOpenKeyExW(hrkey, szDMOCategories, 0, KEY_WRITE, &hckey);
277 if (ERROR_SUCCESS != hres)
278 goto lend;
280 hres = RegDeleteKeyW(hckey, szguid);
281 if (ERROR_SUCCESS != hres)
282 goto lend;
284 lend:
285 if (hckey)
286 RegCloseKey(hckey);
287 if (hrkey)
288 RegCloseKey(hrkey);
290 return hres;
294 /***************************************************************
295 * DMOGetName (MSDMO.@)
297 * Get DMP Name from the registry
299 HRESULT WINAPI DMOGetName(REFCLSID clsidDMO, WCHAR szName[])
301 WCHAR szguid[64];
302 HRESULT hres;
303 HKEY hrkey = 0;
304 HKEY hkey = 0;
305 static const INT max_name_len = 80;
306 DWORD count;
308 TRACE("%s\n", debugstr_guid(clsidDMO));
310 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey,
311 0, KEY_READ, &hrkey);
312 if (ERROR_SUCCESS != hres)
313 goto lend;
315 hres = RegOpenKeyExW(hrkey, GUIDToString(szguid, clsidDMO),
316 0, KEY_READ, &hkey);
317 if (ERROR_SUCCESS != hres)
318 goto lend;
320 count = max_name_len * sizeof(WCHAR);
321 hres = RegQueryValueExW(hkey, NULL, NULL, NULL,
322 (LPBYTE) szName, &count);
324 TRACE(" szName=%s\n", debugstr_w(szName));
325 lend:
326 if (hkey)
327 RegCloseKey(hrkey);
328 if (hkey)
329 RegCloseKey(hkey);
331 return hres;
335 /**************************************************************************
336 * IEnumDMOImpl_Destructor
338 static BOOL IEnumDMOImpl_Destructor(IEnumDMOImpl* This)
340 TRACE("%p\n", This);
342 if (This->hkey)
343 RegCloseKey(This->hkey);
345 HeapFree(GetProcessHeap(), 0, This->pInTypes);
346 HeapFree(GetProcessHeap(), 0, This->pOutTypes);
348 return TRUE;
352 /**************************************************************************
353 * IEnumDMO_Constructor
355 static HRESULT IEnumDMO_Constructor(
356 REFGUID guidCategory,
357 DWORD dwFlags,
358 DWORD cInTypes,
359 const DMO_PARTIAL_MEDIATYPE *pInTypes,
360 DWORD cOutTypes,
361 const DMO_PARTIAL_MEDIATYPE *pOutTypes,
362 IEnumDMO **obj)
364 IEnumDMOImpl* lpedmo;
365 HRESULT hr = S_OK;
366 UINT size;
368 *obj = NULL;
370 lpedmo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumDMOImpl));
371 if (!lpedmo)
372 return E_OUTOFMEMORY;
374 lpedmo->IEnumDMO_iface.lpVtbl = &edmovt;
375 lpedmo->ref = 1;
376 lpedmo->index = -1;
377 lpedmo->guidCategory = guidCategory;
378 lpedmo->dwFlags = dwFlags;
380 if (cInTypes > 0)
382 size = cInTypes * sizeof(DMO_PARTIAL_MEDIATYPE);
383 lpedmo->pInTypes = HeapAlloc(GetProcessHeap(), 0, size);
384 if (!lpedmo->pInTypes)
386 hr = E_OUTOFMEMORY;
387 goto lerr;
389 memcpy(lpedmo->pInTypes, pInTypes, size);
390 lpedmo->cInTypes = cInTypes;
393 if (cOutTypes > 0)
395 size = cOutTypes * sizeof(DMO_PARTIAL_MEDIATYPE);
396 lpedmo->pOutTypes = HeapAlloc(GetProcessHeap(), 0, size);
397 if (!lpedmo->pOutTypes)
399 hr = E_OUTOFMEMORY;
400 goto lerr;
402 memcpy(lpedmo->pOutTypes, pOutTypes, size);
403 lpedmo->cOutTypes = cOutTypes;
406 /* If not filtering by category enum from media objects root */
407 if (IsEqualGUID(guidCategory, &GUID_NULL))
409 if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, KEY_READ, &lpedmo->hkey))
410 hr = E_FAIL;
412 else
414 WCHAR szguid[64];
415 WCHAR szKey[MAX_PATH];
417 wsprintfW(szKey, szCat3Fmt, szDMORootKey, szDMOCategories,
418 GUIDToString(szguid, guidCategory));
419 if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &lpedmo->hkey))
420 hr = E_FAIL;
423 lerr:
425 if (FAILED(hr))
427 IEnumDMOImpl_Destructor(lpedmo);
428 HeapFree(GetProcessHeap(), 0, lpedmo);
430 else
432 TRACE("returning %p\n", lpedmo);
433 *obj = &lpedmo->IEnumDMO_iface;
436 return hr;
439 /******************************************************************************
440 * IEnumDMO_fnAddRef
442 static ULONG WINAPI IEnumDMO_fnAddRef(IEnumDMO * iface)
444 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
445 ULONG refCount = InterlockedIncrement(&This->ref);
446 TRACE("(%p)->(%d)\n", This, refCount);
447 return refCount;
450 /**************************************************************************
451 * EnumDMO_QueryInterface
453 static HRESULT WINAPI IEnumDMO_fnQueryInterface(IEnumDMO* iface, REFIID riid, void **ppvObj)
455 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
457 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObj);
459 *ppvObj = NULL;
461 if (IsEqualIID(riid, &IID_IEnumDMO) ||
462 IsEqualIID(riid, &IID_IUnknown))
464 *ppvObj = iface;
465 IEnumDMO_fnAddRef(iface);
468 return *ppvObj ? S_OK : E_NOINTERFACE;
471 /******************************************************************************
472 * IEnumDMO_fnRelease
474 static ULONG WINAPI IEnumDMO_fnRelease(IEnumDMO * iface)
476 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
477 ULONG refCount = InterlockedDecrement(&This->ref);
479 TRACE("(%p)->(%d)\n", This, refCount);
481 if (!refCount)
483 IEnumDMOImpl_Destructor(This);
484 HeapFree(GetProcessHeap(),0,This);
486 return refCount;
490 /******************************************************************************
491 * IEnumDMO_fnNext
493 static HRESULT WINAPI IEnumDMO_fnNext(
494 IEnumDMO * iface,
495 DWORD cItemsToFetch,
496 CLSID * pCLSID,
497 WCHAR ** Names,
498 DWORD * pcItemsFetched)
500 FILETIME ft;
501 HKEY hkey;
502 WCHAR szNextKey[MAX_PATH];
503 WCHAR szGuidKey[64];
504 WCHAR szKey[MAX_PATH];
505 WCHAR szValue[MAX_PATH];
506 DWORD len;
507 UINT count = 0;
508 HRESULT hres = S_OK;
510 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
512 TRACE("(%p)->(%d %p %p %p)\n", This, cItemsToFetch, pCLSID, Names, pcItemsFetched);
514 if (!pCLSID || !Names || !pcItemsFetched)
515 return E_POINTER;
517 while (count < cItemsToFetch)
519 This->index++;
521 len = MAX_PATH;
522 hres = RegEnumKeyExW(This->hkey, This->index, szNextKey, &len, NULL, NULL, NULL, &ft);
523 if (hres != ERROR_SUCCESS)
524 break;
526 TRACE("found %s\n", debugstr_w(szNextKey));
528 if (!(This->dwFlags & DMO_ENUMF_INCLUDE_KEYED))
530 wsprintfW(szKey, szCat3Fmt, szDMORootKey, szNextKey, szDMOKeyed);
531 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hkey);
532 if (ERROR_SUCCESS == hres)
534 RegCloseKey(hkey);
535 /* Skip Keyed entries */
536 continue;
540 wsprintfW(szKey, szCat2Fmt, szDMORootKey, szNextKey);
541 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hkey);
543 if (This->pInTypes)
545 UINT i, j;
546 DWORD cInTypes;
547 DMO_PARTIAL_MEDIATYPE* pInTypes;
549 hres = read_types(hkey, szDMOInputType, &cInTypes,
550 sizeof(szValue)/sizeof(DMO_PARTIAL_MEDIATYPE),
551 (DMO_PARTIAL_MEDIATYPE*)szValue);
553 if (ERROR_SUCCESS != hres)
555 RegCloseKey(hkey);
556 continue;
559 pInTypes = (DMO_PARTIAL_MEDIATYPE*) szValue;
561 for (i = 0; i < This->cInTypes; i++)
563 for (j = 0; j < cInTypes; j++)
565 if (IsMediaTypeEqual(&pInTypes[j], &This->pInTypes[i]))
566 break;
569 if (j >= cInTypes)
570 break;
573 if (i < This->cInTypes)
575 RegCloseKey(hkey);
576 continue;
580 if (This->pOutTypes)
582 UINT i, j;
583 DWORD cOutTypes;
584 DMO_PARTIAL_MEDIATYPE* pOutTypes;
586 hres = read_types(hkey, szDMOOutputType, &cOutTypes,
587 sizeof(szValue)/sizeof(DMO_PARTIAL_MEDIATYPE),
588 (DMO_PARTIAL_MEDIATYPE*)szValue);
590 if (ERROR_SUCCESS != hres)
592 RegCloseKey(hkey);
593 continue;
596 pOutTypes = (DMO_PARTIAL_MEDIATYPE*) szValue;
598 for (i = 0; i < This->cOutTypes; i++)
600 for (j = 0; j < cOutTypes; j++)
602 if (IsMediaTypeEqual(&pOutTypes[j], &This->pOutTypes[i]))
603 break;
606 if (j >= cOutTypes)
607 break;
610 if (i < This->cOutTypes)
612 RegCloseKey(hkey);
613 continue;
617 /* Media object wasn't filtered so add it to return list */
618 Names[count] = NULL;
619 len = MAX_PATH * sizeof(WCHAR);
620 hres = RegQueryValueExW(hkey, NULL, NULL, NULL, (LPBYTE) szValue, &len);
621 if (ERROR_SUCCESS == hres)
623 Names[count] = HeapAlloc(GetProcessHeap(), 0, (strlenW(szValue) + 1) * sizeof(WCHAR));
624 if (Names[count])
625 strcpyW(Names[count], szValue);
627 wsprintfW(szGuidKey,szToGuidFmt,szNextKey);
628 CLSIDFromString(szGuidKey, &pCLSID[count]);
630 TRACE("found match %s %s\n", debugstr_w(szValue), debugstr_w(szNextKey));
631 RegCloseKey(hkey);
632 count++;
635 *pcItemsFetched = count;
636 if (*pcItemsFetched < cItemsToFetch)
637 hres = S_FALSE;
639 TRACE("<-- %i found\n",count);
640 return hres;
644 /******************************************************************************
645 * IEnumDMO_fnSkip
647 static HRESULT WINAPI IEnumDMO_fnSkip(IEnumDMO * iface, DWORD cItemsToSkip)
649 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
651 TRACE("(%p)->(%d)\n", This, cItemsToSkip);
652 This->index += cItemsToSkip;
654 return S_OK;
658 /******************************************************************************
659 * IEnumDMO_fnReset
661 static HRESULT WINAPI IEnumDMO_fnReset(IEnumDMO * iface)
663 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
665 TRACE("(%p)\n", This);
666 This->index = -1;
668 return S_OK;
672 /******************************************************************************
673 * IEnumDMO_fnClone
675 static HRESULT WINAPI IEnumDMO_fnClone(IEnumDMO *iface, IEnumDMO **ppEnum)
677 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
678 TRACE("(%p)->(%p)\n", This, ppEnum);
679 return IEnumDMO_Constructor(This->guidCategory, This->dwFlags, This->cInTypes, This->pInTypes,
680 This->cOutTypes, This->pOutTypes, ppEnum);
684 /***************************************************************
685 * DMOEnum (MSDMO.@)
687 * Enumerate DirectX Media Objects in the registry.
689 HRESULT WINAPI DMOEnum(
690 REFGUID guidCategory,
691 DWORD dwFlags,
692 DWORD cInTypes,
693 const DMO_PARTIAL_MEDIATYPE *pInTypes,
694 DWORD cOutTypes,
695 const DMO_PARTIAL_MEDIATYPE *pOutTypes,
696 IEnumDMO **ppEnum)
698 TRACE("guidCategory=%p dwFlags=0x%08x cInTypes=%d cOutTypes=%d\n",
699 guidCategory, dwFlags, cInTypes, cOutTypes);
701 return IEnumDMO_Constructor(guidCategory, dwFlags, cInTypes,
702 pInTypes, cOutTypes, pOutTypes, ppEnum);
706 static const IEnumDMOVtbl edmovt =
708 IEnumDMO_fnQueryInterface,
709 IEnumDMO_fnAddRef,
710 IEnumDMO_fnRelease,
711 IEnumDMO_fnNext,
712 IEnumDMO_fnSkip,
713 IEnumDMO_fnReset,
714 IEnumDMO_fnClone,
718 HRESULT read_types(HKEY root, LPCWSTR key, ULONG *supplied, ULONG requested, DMO_PARTIAL_MEDIATYPE* types )
720 HRESULT ret = S_OK;
721 if (MSDMO_MAJOR_VERSION > 5)
723 DWORD len;
724 len = requested * sizeof(DMO_PARTIAL_MEDIATYPE);
725 ret = RegQueryValueExW(root, key, NULL, NULL, (LPBYTE) types, &len);
726 *supplied = len / sizeof(DMO_PARTIAL_MEDIATYPE);
728 else
730 HKEY hkey;
731 WCHAR szGuidKey[64];
733 *supplied = 0;
734 if (ERROR_SUCCESS == RegOpenKeyExW(root, key, 0, KEY_READ, &hkey))
736 int index = 0;
737 WCHAR szNextKey[MAX_PATH];
738 DWORD len;
739 LONG rc = ERROR_SUCCESS;
741 while (rc == ERROR_SUCCESS)
743 len = MAX_PATH;
744 rc = RegEnumKeyExW(hkey, index, szNextKey, &len, NULL, NULL, NULL, NULL);
745 if (rc == ERROR_SUCCESS)
747 HKEY subk;
748 int sub_index = 0;
749 LONG rcs = ERROR_SUCCESS;
750 WCHAR szSubKey[MAX_PATH];
752 RegOpenKeyExW(hkey, szNextKey, 0, KEY_READ, &subk);
753 while (rcs == ERROR_SUCCESS)
755 len = MAX_PATH;
756 rcs = RegEnumKeyExW(subk, sub_index, szSubKey, &len, NULL, NULL, NULL, NULL);
757 if (rcs == ERROR_SUCCESS)
759 if (*supplied >= requested)
761 /* Bailing */
762 ret = S_FALSE;
763 rc = ERROR_MORE_DATA;
764 rcs = ERROR_MORE_DATA;
765 break;
768 wsprintfW(szGuidKey,szToGuidFmt,szNextKey);
769 CLSIDFromString(szGuidKey, &types[*supplied].type);
770 wsprintfW(szGuidKey,szToGuidFmt,szSubKey);
771 CLSIDFromString(szGuidKey, &types[*supplied].subtype);
772 TRACE("Adding type %s subtype %s at index %i\n",
773 debugstr_guid(&types[*supplied].type),
774 debugstr_guid(&types[*supplied].subtype),
775 *supplied);
776 (*supplied)++;
778 sub_index++;
780 index++;
783 RegCloseKey(hkey);
786 return ret;
789 /***************************************************************
790 * DMOGetTypes (MSDMO.@)
792 HRESULT WINAPI DMOGetTypes(REFCLSID clsidDMO,
793 ULONG ulInputTypesRequested,
794 ULONG* pulInputTypesSupplied,
795 DMO_PARTIAL_MEDIATYPE* pInputTypes,
796 ULONG ulOutputTypesRequested,
797 ULONG* pulOutputTypesSupplied,
798 DMO_PARTIAL_MEDIATYPE* pOutputTypes)
800 HKEY root,hkey;
801 HRESULT ret = S_OK;
802 WCHAR szguid[64];
804 TRACE ("(%s,%u,%p,%p,%u,%p,%p)\n", debugstr_guid(clsidDMO), ulInputTypesRequested,
805 pulInputTypesSupplied, pInputTypes, ulOutputTypesRequested, pulOutputTypesSupplied,
806 pOutputTypes);
808 if (ERROR_SUCCESS != RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0,
809 KEY_READ, &root))
810 return E_FAIL;
812 if (ERROR_SUCCESS != RegOpenKeyExW(root,GUIDToString(szguid,clsidDMO) , 0,
813 KEY_READ, &hkey))
815 RegCloseKey(root);
816 return E_FAIL;
819 if (ulInputTypesRequested > 0)
821 ret = read_types(hkey, szDMOInputType, pulInputTypesSupplied, ulInputTypesRequested, pInputTypes );
823 else
824 *pulInputTypesSupplied = 0;
826 if (ulOutputTypesRequested > 0)
828 HRESULT ret2;
829 ret2 = read_types(hkey, szDMOOutputType, pulOutputTypesSupplied, ulOutputTypesRequested, pOutputTypes );
831 if (ret == S_OK)
832 ret = ret2;
834 else
835 *pulOutputTypesSupplied = 0;
837 return ret;