setupapi/tests: Trace error codes when SetupOpenLog fails.
[wine.git] / dlls / msdmo / dmoreg.c
blobdea079aa4ea6779927b252e56c4d7447d794ae88
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 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winerror.h"
28 #include "winreg.h"
29 #include "objbase.h"
30 #include "wine/unicode.h"
31 #include "wine/debug.h"
32 #include "initguid.h"
33 #include "dmo.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(msdmo);
37 #define MSDMO_MAJOR_VERSION 6
39 static const WCHAR szDMORootKey[] =
41 'D','i','r','e','c','t','S','h','o','w','\\',
42 'M','e','d','i','a','O','b','j','e','c','t','s',0
43 };
45 static const WCHAR szDMOInputType[] =
47 'I','n','p','u','t','T','y','p','e','s',0
50 static const WCHAR szDMOOutputType[] =
52 'O','u','t','p','u','t','T','y','p','e','s',0
55 static const WCHAR szDMOKeyed[] =
57 'K','e','y','e','d',0
60 static const WCHAR szDMOCategories[] =
62 'C','a','t','e','g','o','r','i','e','s',0
65 static const WCHAR szGUIDFmt[] =
67 '%','0','8','X','-','%','0','4','X','-','%','0','4','X','-','%','0',
68 '2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','%','0','2',
69 'X','%','0','2','X','%','0','2','X','%','0','2','X',0
72 static const WCHAR szCat3Fmt[] =
74 '%','s','\\','%','s','\\','%','s',0
77 static const WCHAR szCat2Fmt[] =
79 '%','s','\\','%','s',0
82 static const WCHAR szToGuidFmt[] =
84 '{','%','s','}',0
88 typedef struct
90 IEnumDMO IEnumDMO_iface;
91 LONG ref;
92 DWORD index;
93 GUID category;
94 DWORD dwFlags;
95 DWORD cInTypes;
96 DMO_PARTIAL_MEDIATYPE *pInTypes;
97 DWORD cOutTypes;
98 DMO_PARTIAL_MEDIATYPE *pOutTypes;
99 HKEY hkey;
100 } IEnumDMOImpl;
102 static inline IEnumDMOImpl *impl_from_IEnumDMO(IEnumDMO *iface)
104 return CONTAINING_RECORD(iface, IEnumDMOImpl, IEnumDMO_iface);
107 static HRESULT read_types(HKEY root, LPCWSTR key, ULONG *supplied, ULONG requested, DMO_PARTIAL_MEDIATYPE* types);
109 static const IEnumDMOVtbl edmovt;
111 static LPWSTR GUIDToString(LPWSTR lpwstr, REFGUID lpcguid)
113 wsprintfW(lpwstr, szGUIDFmt, lpcguid->Data1, lpcguid->Data2,
114 lpcguid->Data3, lpcguid->Data4[0], lpcguid->Data4[1],
115 lpcguid->Data4[2], lpcguid->Data4[3], lpcguid->Data4[4],
116 lpcguid->Data4[5], lpcguid->Data4[6], lpcguid->Data4[7]);
118 return lpwstr;
121 static BOOL IsMediaTypeEqual(const DMO_PARTIAL_MEDIATYPE* mt1, const DMO_PARTIAL_MEDIATYPE* mt2)
124 return (IsEqualCLSID(&mt1->type, &mt2->type) ||
125 IsEqualCLSID(&mt2->type, &GUID_NULL) ||
126 IsEqualCLSID(&mt1->type, &GUID_NULL)) &&
127 (IsEqualCLSID(&mt1->subtype, &mt2->subtype) ||
128 IsEqualCLSID(&mt2->subtype, &GUID_NULL) ||
129 IsEqualCLSID(&mt1->subtype, &GUID_NULL));
132 static HRESULT write_types(HKEY hkey, LPCWSTR name, const DMO_PARTIAL_MEDIATYPE* types, DWORD count)
134 LONG ret;
136 if (MSDMO_MAJOR_VERSION > 5)
138 ret = RegSetValueExW(hkey, name, 0, REG_BINARY, (const BYTE*) types,
139 count* sizeof(DMO_PARTIAL_MEDIATYPE));
141 else
143 HKEY skey1,skey2,skey3;
144 DWORD index = 0;
145 WCHAR szGuidKey[64];
147 ret = RegCreateKeyExW(hkey, name, 0, NULL, REG_OPTION_NON_VOLATILE,
148 KEY_WRITE, NULL, &skey1, NULL);
149 if (ret)
150 return HRESULT_FROM_WIN32(ret);
152 while (index < count)
154 GUIDToString(szGuidKey,&types[index].type);
155 ret = RegCreateKeyExW(skey1, szGuidKey, 0, NULL,
156 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &skey2, NULL);
157 GUIDToString(szGuidKey,&types[index].subtype);
158 ret = RegCreateKeyExW(skey2, szGuidKey, 0, NULL,
159 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &skey3, NULL);
160 RegCloseKey(skey3);
161 RegCloseKey(skey2);
162 index ++;
164 RegCloseKey(skey1);
167 return HRESULT_FROM_WIN32(ret);
170 /***************************************************************
171 * DMORegister (MSDMO.@)
173 * Register a DirectX Media Object.
175 HRESULT WINAPI DMORegister(
176 LPCWSTR szName,
177 REFCLSID clsidDMO,
178 REFGUID guidCategory,
179 DWORD dwFlags,
180 DWORD cInTypes,
181 const DMO_PARTIAL_MEDIATYPE *pInTypes,
182 DWORD cOutTypes,
183 const DMO_PARTIAL_MEDIATYPE *pOutTypes
186 WCHAR szguid[64];
187 HRESULT hres;
188 HKEY hrkey = 0;
189 HKEY hkey = 0;
190 HKEY hckey = 0;
191 HKEY hclskey = 0;
193 TRACE("%s %s %s\n", debugstr_w(szName), debugstr_guid(clsidDMO), debugstr_guid(guidCategory));
195 if (IsEqualGUID(guidCategory, &GUID_NULL))
196 return E_INVALIDARG;
198 hres = RegCreateKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, NULL,
199 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hrkey, NULL);
200 if (ERROR_SUCCESS != hres)
201 goto lend;
203 /* Create clsidDMO key under MediaObjects */
204 hres = RegCreateKeyExW(hrkey, GUIDToString(szguid, clsidDMO), 0, NULL,
205 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
206 if (ERROR_SUCCESS != hres)
207 goto lend;
209 /* Set default Name value */
210 hres = RegSetValueExW(hkey, NULL, 0, REG_SZ, (const BYTE*) szName,
211 (strlenW(szName) + 1) * sizeof(WCHAR));
213 /* Set InputTypes */
214 hres = write_types(hkey, szDMOInputType, pInTypes, cInTypes);
216 /* Set OutputTypes */
217 hres = write_types(hkey, szDMOOutputType, pOutTypes, cOutTypes);
219 if (dwFlags & DMO_REGISTERF_IS_KEYED)
221 /* Create Keyed key */
222 hres = RegCreateKeyExW(hkey, szDMOKeyed, 0, NULL,
223 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hckey, NULL);
224 if (ERROR_SUCCESS != hres)
225 goto lend;
226 RegCloseKey(hckey);
229 /* Register the category */
230 hres = RegCreateKeyExW(hrkey, szDMOCategories, 0, NULL,
231 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hckey, NULL);
232 if (ERROR_SUCCESS != hres)
233 goto lend;
235 RegCloseKey(hkey);
237 hres = RegCreateKeyExW(hckey, GUIDToString(szguid, guidCategory), 0, NULL,
238 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
239 if (ERROR_SUCCESS != hres)
240 goto lend;
241 hres = RegCreateKeyExW(hkey, GUIDToString(szguid, clsidDMO), 0, NULL,
242 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hclskey, NULL);
243 if (ERROR_SUCCESS != hres)
244 goto lend;
246 lend:
247 if (hkey)
248 RegCloseKey(hkey);
249 if (hckey)
250 RegCloseKey(hckey);
251 if (hclskey)
252 RegCloseKey(hclskey);
253 if (hrkey)
254 RegCloseKey(hrkey);
256 TRACE(" hresult=0x%08x\n", hres);
257 return hres;
260 static HRESULT unregister_dmo_from_category(const WCHAR *dmoW, const WCHAR *catW, HKEY categories)
262 HKEY catkey;
263 LONG ret;
265 ret = RegOpenKeyExW(categories, catW, 0, KEY_WRITE, &catkey);
266 if (!ret)
268 ret = RegDeleteKeyW(catkey, dmoW);
269 RegCloseKey(catkey);
272 return !ret ? S_OK : S_FALSE;
275 /***************************************************************
276 * DMOUnregister (MSDMO.@)
278 * Unregister a DirectX Media Object.
280 HRESULT WINAPI DMOUnregister(REFCLSID dmo, REFGUID category)
282 HKEY rootkey = 0, categorieskey = 0;
283 WCHAR dmoW[64], catW[64];
284 HRESULT hr = S_FALSE;
285 LONG ret;
287 TRACE("%s %s\n", debugstr_guid(dmo), debugstr_guid(category));
289 ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, KEY_WRITE, &rootkey);
290 if (ret)
291 return S_FALSE;
293 GUIDToString(dmoW, dmo);
294 RegDeleteKeyW(rootkey, dmoW);
296 /* open 'Categories' */
297 ret = RegOpenKeyExW(rootkey, szDMOCategories, 0, KEY_WRITE|KEY_ENUMERATE_SUB_KEYS, &categorieskey);
298 RegCloseKey(rootkey);
299 if (ret)
301 hr = HRESULT_FROM_WIN32(ret);
302 goto lend;
305 /* remove from all categories */
306 if (IsEqualGUID(category, &GUID_NULL))
308 DWORD index = 0, len = sizeof(catW)/sizeof(WCHAR);
310 while (!RegEnumKeyExW(categorieskey, index++, catW, &len, NULL, NULL, NULL, NULL))
311 hr = unregister_dmo_from_category(dmoW, catW, categorieskey);
313 else
315 GUIDToString(catW, category);
316 hr = unregister_dmo_from_category(dmoW, catW, categorieskey);
319 lend:
320 if (categorieskey)
321 RegCloseKey(categorieskey);
323 return hr;
327 /***************************************************************
328 * DMOGetName (MSDMO.@)
330 * Get DMO Name from the registry
332 HRESULT WINAPI DMOGetName(REFCLSID clsidDMO, WCHAR name[])
334 static const INT max_name_len = 80*sizeof(WCHAR);
335 DWORD count = max_name_len;
336 WCHAR szguid[64];
337 HKEY hrkey, hkey;
338 LONG ret;
340 TRACE("%s %p\n", debugstr_guid(clsidDMO), name);
342 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, KEY_READ, &hrkey))
343 return E_FAIL;
345 ret = RegOpenKeyExW(hrkey, GUIDToString(szguid, clsidDMO), 0, KEY_READ, &hkey);
346 RegCloseKey(hrkey);
347 if (ret)
348 return E_FAIL;
350 ret = RegQueryValueExW(hkey, NULL, NULL, NULL, (LPBYTE)name, &count);
351 RegCloseKey(hkey);
353 if (!ret && count > 1)
355 TRACE("name=%s\n", debugstr_w(name));
356 return S_OK;
359 name[0] = 0;
360 return S_FALSE;
363 static HRESULT dup_partial_mediatype(const DMO_PARTIAL_MEDIATYPE *types, DWORD count, DMO_PARTIAL_MEDIATYPE **ret)
365 *ret = NULL;
367 if (count == 0)
368 return S_OK;
370 *ret = HeapAlloc(GetProcessHeap(), 0, count*sizeof(*types));
371 if (!*ret)
372 return E_OUTOFMEMORY;
374 memcpy(*ret, types, count*sizeof(*types));
375 return S_OK;
378 /**************************************************************************
379 * IEnumDMO_Constructor
381 static HRESULT IEnumDMO_Constructor(
382 REFGUID guidCategory,
383 DWORD dwFlags,
384 DWORD cInTypes,
385 const DMO_PARTIAL_MEDIATYPE *pInTypes,
386 DWORD cOutTypes,
387 const DMO_PARTIAL_MEDIATYPE *pOutTypes,
388 IEnumDMO **obj)
390 IEnumDMOImpl* lpedmo;
391 HRESULT hr;
392 LONG ret;
394 *obj = NULL;
396 lpedmo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumDMOImpl));
397 if (!lpedmo)
398 return E_OUTOFMEMORY;
400 lpedmo->IEnumDMO_iface.lpVtbl = &edmovt;
401 lpedmo->ref = 1;
402 lpedmo->index = -1;
403 lpedmo->category = *guidCategory;
404 lpedmo->dwFlags = dwFlags;
405 lpedmo->cInTypes = cInTypes;
406 lpedmo->cOutTypes = cOutTypes;
408 hr = dup_partial_mediatype(pInTypes, cInTypes, &lpedmo->pInTypes);
409 if (FAILED(hr))
410 goto lerr;
412 hr = dup_partial_mediatype(pOutTypes, cOutTypes, &lpedmo->pOutTypes);
413 if (FAILED(hr))
414 goto lerr;
416 /* If not filtering by category enum from media objects root */
417 if (IsEqualGUID(guidCategory, &GUID_NULL))
419 if ((ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, KEY_READ, &lpedmo->hkey)))
420 hr = HRESULT_FROM_WIN32(ret);
422 else
424 WCHAR szguid[64];
425 WCHAR szKey[MAX_PATH];
427 wsprintfW(szKey, szCat3Fmt, szDMORootKey, szDMOCategories, GUIDToString(szguid, guidCategory));
428 if ((ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &lpedmo->hkey)))
429 hr = HRESULT_FROM_WIN32(ret);
432 lerr:
434 if (FAILED(hr))
435 IEnumDMO_Release(&lpedmo->IEnumDMO_iface);
436 else
438 TRACE("returning %p\n", lpedmo);
439 *obj = &lpedmo->IEnumDMO_iface;
442 return hr;
445 /******************************************************************************
446 * IEnumDMO_fnAddRef
448 static ULONG WINAPI IEnumDMO_fnAddRef(IEnumDMO * iface)
450 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
451 ULONG refCount = InterlockedIncrement(&This->ref);
452 TRACE("(%p)->(%d)\n", This, refCount);
453 return refCount;
456 /**************************************************************************
457 * EnumDMO_QueryInterface
459 static HRESULT WINAPI IEnumDMO_fnQueryInterface(IEnumDMO* iface, REFIID riid, void **ppvObj)
461 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
463 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObj);
465 *ppvObj = NULL;
467 if (IsEqualIID(riid, &IID_IEnumDMO) ||
468 IsEqualIID(riid, &IID_IUnknown))
470 *ppvObj = iface;
471 IEnumDMO_AddRef(iface);
474 return *ppvObj ? S_OK : E_NOINTERFACE;
477 /******************************************************************************
478 * IEnumDMO_fnRelease
480 static ULONG WINAPI IEnumDMO_fnRelease(IEnumDMO * iface)
482 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
483 ULONG refCount = InterlockedDecrement(&This->ref);
485 TRACE("(%p)->(%d)\n", This, refCount);
487 if (!refCount)
489 if (This->hkey)
490 RegCloseKey(This->hkey);
491 HeapFree(GetProcessHeap(), 0, This->pInTypes);
492 HeapFree(GetProcessHeap(), 0, This->pOutTypes);
493 HeapFree(GetProcessHeap(), 0, This);
495 return refCount;
499 /******************************************************************************
500 * IEnumDMO_fnNext
502 static HRESULT WINAPI IEnumDMO_fnNext(
503 IEnumDMO * iface,
504 DWORD cItemsToFetch,
505 CLSID * pCLSID,
506 WCHAR ** Names,
507 DWORD * pcItemsFetched)
509 HKEY hkey;
510 WCHAR szNextKey[MAX_PATH];
511 WCHAR szGuidKey[64];
512 WCHAR szKey[MAX_PATH];
513 WCHAR szValue[MAX_PATH];
514 DWORD len;
515 UINT count = 0;
516 HRESULT hres = S_OK;
517 LONG ret;
519 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
521 TRACE("(%p)->(%d %p %p %p)\n", This, cItemsToFetch, pCLSID, Names, pcItemsFetched);
523 if (!pCLSID || !Names || !pcItemsFetched)
524 return E_POINTER;
526 while (count < cItemsToFetch)
528 This->index++;
530 len = MAX_PATH;
531 ret = RegEnumKeyExW(This->hkey, This->index, szNextKey, &len, NULL, NULL, NULL, NULL);
532 if (ret != ERROR_SUCCESS)
534 hres = HRESULT_FROM_WIN32(ret);
535 break;
538 TRACE("found %s\n", debugstr_w(szNextKey));
540 if (!(This->dwFlags & DMO_ENUMF_INCLUDE_KEYED))
542 wsprintfW(szKey, szCat3Fmt, szDMORootKey, szNextKey, szDMOKeyed);
543 ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hkey);
544 if (ERROR_SUCCESS == ret)
546 RegCloseKey(hkey);
547 /* Skip Keyed entries */
548 continue;
552 wsprintfW(szKey, szCat2Fmt, szDMORootKey, szNextKey);
553 ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hkey);
554 TRACE("testing %s\n", debugstr_w(szKey));
556 if (This->pInTypes)
558 UINT i, j;
559 DWORD cInTypes;
560 DMO_PARTIAL_MEDIATYPE* pInTypes;
562 hres = read_types(hkey, szDMOInputType, &cInTypes,
563 sizeof(szValue)/sizeof(DMO_PARTIAL_MEDIATYPE),
564 (DMO_PARTIAL_MEDIATYPE*)szValue);
566 if (FAILED(hres))
568 RegCloseKey(hkey);
569 continue;
572 pInTypes = (DMO_PARTIAL_MEDIATYPE*) szValue;
574 TRACE("read %d intypes for %s:\n", cInTypes, debugstr_w(szKey));
575 for (i = 0; i < cInTypes; i++) {
576 TRACE("intype %d: type %s, subtype %s\n", i, debugstr_guid(&pInTypes[i].type),
577 debugstr_guid(&pInTypes[i].subtype));
580 for (i = 0; i < This->cInTypes; i++)
582 for (j = 0; j < cInTypes; j++)
584 if (IsMediaTypeEqual(&pInTypes[j], &This->pInTypes[i]))
585 break;
588 if (j >= cInTypes)
589 break;
592 if (i < This->cInTypes)
594 RegCloseKey(hkey);
595 continue;
599 if (This->pOutTypes)
601 UINT i, j;
602 DWORD cOutTypes;
603 DMO_PARTIAL_MEDIATYPE* pOutTypes;
605 hres = read_types(hkey, szDMOOutputType, &cOutTypes,
606 sizeof(szValue)/sizeof(DMO_PARTIAL_MEDIATYPE),
607 (DMO_PARTIAL_MEDIATYPE*)szValue);
609 if (FAILED(hres))
611 RegCloseKey(hkey);
612 continue;
615 pOutTypes = (DMO_PARTIAL_MEDIATYPE*) szValue;
617 TRACE("read %d outtypes for %s:\n", cOutTypes, debugstr_w(szKey));
618 for (i = 0; i < cOutTypes; i++) {
619 TRACE("outtype %d: type %s, subtype %s\n", i, debugstr_guid(&pOutTypes[i].type),
620 debugstr_guid(&pOutTypes[i].subtype));
623 for (i = 0; i < This->cOutTypes; i++)
625 for (j = 0; j < cOutTypes; j++)
627 if (IsMediaTypeEqual(&pOutTypes[j], &This->pOutTypes[i]))
628 break;
631 if (j >= cOutTypes)
632 break;
635 if (i < This->cOutTypes)
637 RegCloseKey(hkey);
638 continue;
642 /* Media object wasn't filtered so add it to return list */
643 Names[count] = NULL;
644 len = MAX_PATH * sizeof(WCHAR);
645 ret = RegQueryValueExW(hkey, NULL, NULL, NULL, (LPBYTE)szValue, &len);
646 if (ERROR_SUCCESS == ret)
648 Names[count] = CoTaskMemAlloc((strlenW(szValue) + 1) * sizeof(WCHAR));
649 if (Names[count])
650 strcpyW(Names[count], szValue);
652 wsprintfW(szGuidKey,szToGuidFmt,szNextKey);
653 CLSIDFromString(szGuidKey, &pCLSID[count]);
655 TRACE("found match %s %s\n", debugstr_w(szValue), debugstr_w(szNextKey));
656 RegCloseKey(hkey);
657 count++;
660 *pcItemsFetched = count;
661 if (*pcItemsFetched < cItemsToFetch)
662 hres = S_FALSE;
664 TRACE("<-- %i found\n",count);
665 return hres;
669 /******************************************************************************
670 * IEnumDMO_fnSkip
672 static HRESULT WINAPI IEnumDMO_fnSkip(IEnumDMO * iface, DWORD cItemsToSkip)
674 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
676 TRACE("(%p)->(%d)\n", This, cItemsToSkip);
677 This->index += cItemsToSkip;
679 return S_OK;
683 /******************************************************************************
684 * IEnumDMO_fnReset
686 static HRESULT WINAPI IEnumDMO_fnReset(IEnumDMO * iface)
688 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
690 TRACE("(%p)\n", This);
691 This->index = -1;
693 return S_OK;
697 /******************************************************************************
698 * IEnumDMO_fnClone
700 static HRESULT WINAPI IEnumDMO_fnClone(IEnumDMO *iface, IEnumDMO **ppEnum)
702 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
703 TRACE("(%p)->(%p)\n", This, ppEnum);
704 return IEnumDMO_Constructor(&This->category, This->dwFlags, This->cInTypes, This->pInTypes,
705 This->cOutTypes, This->pOutTypes, ppEnum);
709 /***************************************************************
710 * DMOEnum (MSDMO.@)
712 * Enumerate DirectX Media Objects in the registry.
714 HRESULT WINAPI DMOEnum(
715 REFGUID category,
716 DWORD flags,
717 DWORD cInTypes,
718 const DMO_PARTIAL_MEDIATYPE *pInTypes,
719 DWORD cOutTypes,
720 const DMO_PARTIAL_MEDIATYPE *pOutTypes,
721 IEnumDMO **ppEnum)
723 TRACE("%s 0x%08x %d %p %d %p %p\n", debugstr_guid(category), flags, cInTypes, pInTypes,
724 cOutTypes, pOutTypes, ppEnum);
726 if (TRACE_ON(msdmo))
728 DWORD i;
729 if (cInTypes)
731 for (i = 0; i < cInTypes; i++)
732 TRACE("intype %d - type %s, subtype %s\n", i, debugstr_guid(&pInTypes[i].type),
733 debugstr_guid(&pInTypes[i].subtype));
736 if (cOutTypes) {
737 for (i = 0; i < cOutTypes; i++)
738 TRACE("outtype %d - type %s, subtype %s\n", i, debugstr_guid(&pOutTypes[i].type),
739 debugstr_guid(&pOutTypes[i].subtype));
743 return IEnumDMO_Constructor(category, flags, cInTypes,
744 pInTypes, cOutTypes, pOutTypes, ppEnum);
748 static const IEnumDMOVtbl edmovt =
750 IEnumDMO_fnQueryInterface,
751 IEnumDMO_fnAddRef,
752 IEnumDMO_fnRelease,
753 IEnumDMO_fnNext,
754 IEnumDMO_fnSkip,
755 IEnumDMO_fnReset,
756 IEnumDMO_fnClone,
760 HRESULT read_types(HKEY root, LPCWSTR key, ULONG *supplied, ULONG requested, DMO_PARTIAL_MEDIATYPE* types )
762 HRESULT ret = S_OK;
764 if (MSDMO_MAJOR_VERSION > 5)
766 DWORD len;
767 LONG rc;
769 len = requested * sizeof(DMO_PARTIAL_MEDIATYPE);
770 rc = RegQueryValueExW(root, key, NULL, NULL, (LPBYTE) types, &len);
771 ret = HRESULT_FROM_WIN32(rc);
773 *supplied = len / sizeof(DMO_PARTIAL_MEDIATYPE);
775 else
777 HKEY hkey;
778 WCHAR szGuidKey[64];
780 *supplied = 0;
781 if (ERROR_SUCCESS == RegOpenKeyExW(root, key, 0, KEY_READ, &hkey))
783 int index = 0;
784 WCHAR szNextKey[MAX_PATH];
785 DWORD len;
786 LONG rc = ERROR_SUCCESS;
788 while (rc == ERROR_SUCCESS)
790 len = MAX_PATH;
791 rc = RegEnumKeyExW(hkey, index, szNextKey, &len, NULL, NULL, NULL, NULL);
792 if (rc == ERROR_SUCCESS)
794 HKEY subk;
795 int sub_index = 0;
796 LONG rcs = ERROR_SUCCESS;
797 WCHAR szSubKey[MAX_PATH];
799 RegOpenKeyExW(hkey, szNextKey, 0, KEY_READ, &subk);
800 while (rcs == ERROR_SUCCESS)
802 len = MAX_PATH;
803 rcs = RegEnumKeyExW(subk, sub_index, szSubKey, &len, NULL, NULL, NULL, NULL);
804 if (rcs == ERROR_SUCCESS)
806 if (*supplied >= requested)
808 /* Bailing */
809 ret = S_FALSE;
810 rc = ERROR_MORE_DATA;
811 rcs = ERROR_MORE_DATA;
812 break;
815 wsprintfW(szGuidKey,szToGuidFmt,szNextKey);
816 CLSIDFromString(szGuidKey, &types[*supplied].type);
817 wsprintfW(szGuidKey,szToGuidFmt,szSubKey);
818 CLSIDFromString(szGuidKey, &types[*supplied].subtype);
819 TRACE("Adding type %s subtype %s at index %i\n",
820 debugstr_guid(&types[*supplied].type),
821 debugstr_guid(&types[*supplied].subtype),
822 *supplied);
823 (*supplied)++;
825 sub_index++;
827 index++;
830 RegCloseKey(hkey);
833 return ret;
836 /***************************************************************
837 * DMOGetTypes (MSDMO.@)
839 HRESULT WINAPI DMOGetTypes(REFCLSID clsidDMO,
840 ULONG ulInputTypesRequested,
841 ULONG* pulInputTypesSupplied,
842 DMO_PARTIAL_MEDIATYPE* pInputTypes,
843 ULONG ulOutputTypesRequested,
844 ULONG* pulOutputTypesSupplied,
845 DMO_PARTIAL_MEDIATYPE* pOutputTypes)
847 HKEY root,hkey;
848 HRESULT ret = S_OK;
849 WCHAR szguid[64];
851 TRACE ("(%s,%u,%p,%p,%u,%p,%p)\n", debugstr_guid(clsidDMO), ulInputTypesRequested,
852 pulInputTypesSupplied, pInputTypes, ulOutputTypesRequested, pulOutputTypesSupplied,
853 pOutputTypes);
855 if (ERROR_SUCCESS != RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0,
856 KEY_READ, &root))
857 return E_FAIL;
859 if (ERROR_SUCCESS != RegOpenKeyExW(root,GUIDToString(szguid,clsidDMO) , 0,
860 KEY_READ, &hkey))
862 RegCloseKey(root);
863 return E_FAIL;
866 if (ulInputTypesRequested > 0)
868 ret = read_types(hkey, szDMOInputType, pulInputTypesSupplied, ulInputTypesRequested, pInputTypes );
870 else
871 *pulInputTypesSupplied = 0;
873 if (ulOutputTypesRequested > 0)
875 HRESULT ret2;
876 ret2 = read_types(hkey, szDMOOutputType, pulOutputTypesSupplied, ulOutputTypesRequested, pOutputTypes );
878 if (ret == S_OK)
879 ret = ret2;
881 else
882 *pulOutputTypesSupplied = 0;
884 return ret;