ntoskrnl.exe/tests: Add some IOCTL_HID_WRITE_REPORT tests.
[wine.git] / dlls / msdmo / dmoreg.c
blob33caa6d0dc5ce2bab30fafc68c709b7c72b6a328
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/debug.h"
31 #include "dmo.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(msdmo);
35 BOOL array_reserve(void **elements, unsigned int *capacity, unsigned int count, unsigned int size)
37 unsigned int max_capacity, new_capacity;
38 void *new_elements;
40 if (count <= *capacity)
41 return TRUE;
43 max_capacity = ~0u / size;
44 if (count > max_capacity)
45 return FALSE;
47 new_capacity = max(8, *capacity);
48 while (new_capacity < count && new_capacity <= max_capacity / 2)
49 new_capacity *= 2;
50 if (new_capacity < count)
51 new_capacity = count;
53 if (!(new_elements = realloc(*elements, new_capacity * size)))
55 ERR("Failed to allocate memory.\n");
56 return FALSE;
59 *elements = new_elements;
60 *capacity = new_capacity;
61 return TRUE;
64 typedef struct
66 IEnumDMO IEnumDMO_iface;
67 LONG ref;
68 DWORD index;
69 GUID category;
70 DWORD dwFlags;
71 DWORD cInTypes;
72 DMO_PARTIAL_MEDIATYPE *pInTypes;
73 DWORD cOutTypes;
74 DMO_PARTIAL_MEDIATYPE *pOutTypes;
75 HKEY hkey;
76 } IEnumDMOImpl;
78 static inline IEnumDMOImpl *impl_from_IEnumDMO(IEnumDMO *iface)
80 return CONTAINING_RECORD(iface, IEnumDMOImpl, IEnumDMO_iface);
83 static const IEnumDMOVtbl edmovt;
85 static const WCHAR *GUIDToString(WCHAR *string, const GUID *guid)
87 swprintf(string, 37, L"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
88 guid->Data1, guid->Data2, guid->Data3,
89 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
90 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
91 return string;
94 static HRESULT string_to_guid(const WCHAR *string, GUID *guid)
96 WCHAR buffer[39];
97 buffer[0] = '{';
98 wcscpy(buffer + 1, string);
99 buffer[37] = '}';
100 buffer[38] = 0;
101 return CLSIDFromString(buffer, guid);
104 static BOOL IsMediaTypeEqual(const DMO_PARTIAL_MEDIATYPE* mt1, const DMO_PARTIAL_MEDIATYPE* mt2)
107 return (IsEqualCLSID(&mt1->type, &mt2->type) ||
108 IsEqualCLSID(&mt2->type, &GUID_NULL) ||
109 IsEqualCLSID(&mt1->type, &GUID_NULL)) &&
110 (IsEqualCLSID(&mt1->subtype, &mt2->subtype) ||
111 IsEqualCLSID(&mt2->subtype, &GUID_NULL) ||
112 IsEqualCLSID(&mt1->subtype, &GUID_NULL));
115 static HRESULT write_types(HKEY hkey, LPCWSTR name, const DMO_PARTIAL_MEDIATYPE* types, DWORD count)
117 return HRESULT_FROM_WIN32(RegSetValueExW(hkey, name, 0, REG_BINARY,
118 (const BYTE *)types, count * sizeof(DMO_PARTIAL_MEDIATYPE)));
121 /***************************************************************
122 * DMORegister (MSDMO.@)
124 * Register a DirectX Media Object.
126 HRESULT WINAPI DMORegister(
127 LPCWSTR szName,
128 REFCLSID clsidDMO,
129 REFGUID guidCategory,
130 DWORD dwFlags,
131 DWORD cInTypes,
132 const DMO_PARTIAL_MEDIATYPE *pInTypes,
133 DWORD cOutTypes,
134 const DMO_PARTIAL_MEDIATYPE *pOutTypes
137 WCHAR szguid[64];
138 HRESULT hres;
139 HKEY hrkey = 0;
140 HKEY hkey = 0;
141 HKEY hckey = 0;
142 HKEY hclskey = 0;
143 LONG ret;
145 TRACE("%s %s %s\n", debugstr_w(szName), debugstr_guid(clsidDMO), debugstr_guid(guidCategory));
147 if (IsEqualGUID(guidCategory, &GUID_NULL))
148 return E_INVALIDARG;
150 ret = RegCreateKeyExW(HKEY_CLASSES_ROOT, L"DirectShow\\MediaObjects", 0,
151 NULL, 0, KEY_WRITE, NULL, &hrkey, NULL);
152 if (ret)
153 return E_FAIL;
155 /* Create clsidDMO key under MediaObjects */
156 ret = RegCreateKeyExW(hrkey, GUIDToString(szguid, clsidDMO), 0, NULL,
157 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
158 if (ret)
159 goto lend;
161 /* Set default Name value */
162 ret = RegSetValueExW(hkey, NULL, 0, REG_SZ, (const BYTE*) szName,
163 (wcslen(szName) + 1) * sizeof(WCHAR));
165 /* Set InputTypes */
166 hres = write_types(hkey, L"InputTypes", pInTypes, cInTypes);
168 /* Set OutputTypes */
169 hres = write_types(hkey, L"OutputTypes", pOutTypes, cOutTypes);
171 if (dwFlags & DMO_REGISTERF_IS_KEYED)
173 /* Create Keyed key */
174 ret = RegCreateKeyExW(hkey, L"Keyed", 0, NULL, 0, KEY_WRITE, NULL, &hckey, NULL);
175 if (ret)
176 goto lend;
177 RegCloseKey(hckey);
180 /* Register the category */
181 ret = RegCreateKeyExW(hrkey, L"Categories", 0, NULL, 0, KEY_WRITE, NULL, &hckey, NULL);
182 if (ret)
183 goto lend;
185 RegCloseKey(hkey);
187 ret = RegCreateKeyExW(hckey, GUIDToString(szguid, guidCategory), 0, NULL,
188 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
189 if (ret)
190 goto lend;
191 ret = RegCreateKeyExW(hkey, GUIDToString(szguid, clsidDMO), 0, NULL,
192 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hclskey, NULL);
193 if (ret)
194 goto lend;
196 lend:
197 if (hkey)
198 RegCloseKey(hkey);
199 if (hckey)
200 RegCloseKey(hckey);
201 if (hclskey)
202 RegCloseKey(hclskey);
203 if (hrkey)
204 RegCloseKey(hrkey);
206 hres = HRESULT_FROM_WIN32(ret);
207 TRACE(" hresult=0x%08x\n", hres);
208 return hres;
211 static HRESULT unregister_dmo_from_category(const WCHAR *dmoW, const WCHAR *catW, HKEY categories)
213 HKEY catkey;
214 LONG ret;
216 ret = RegOpenKeyExW(categories, catW, 0, KEY_WRITE, &catkey);
217 if (!ret)
219 ret = RegDeleteKeyW(catkey, dmoW);
220 RegCloseKey(catkey);
223 return !ret ? S_OK : S_FALSE;
226 /***************************************************************
227 * DMOUnregister (MSDMO.@)
229 * Unregister a DirectX Media Object.
231 HRESULT WINAPI DMOUnregister(REFCLSID dmo, REFGUID category)
233 HKEY rootkey = 0, categorieskey = 0;
234 WCHAR dmoW[64], catW[64];
235 HRESULT hr = S_FALSE;
236 LONG ret;
238 TRACE("%s %s\n", debugstr_guid(dmo), debugstr_guid(category));
240 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"DirectShow\\MediaObjects", 0, KEY_WRITE, &rootkey))
241 return S_FALSE;
243 GUIDToString(dmoW, dmo);
244 RegDeleteKeyW(rootkey, dmoW);
246 /* open 'Categories' */
247 ret = RegOpenKeyExW(rootkey, L"Categories", 0, KEY_WRITE|KEY_ENUMERATE_SUB_KEYS, &categorieskey);
248 RegCloseKey(rootkey);
249 if (ret)
251 hr = HRESULT_FROM_WIN32(ret);
252 goto lend;
255 /* remove from all categories */
256 if (IsEqualGUID(category, &GUID_NULL))
258 DWORD index = 0, len = ARRAY_SIZE(catW);
260 while (!RegEnumKeyExW(categorieskey, index++, catW, &len, NULL, NULL, NULL, NULL))
261 hr = unregister_dmo_from_category(dmoW, catW, categorieskey);
263 else
265 GUIDToString(catW, category);
266 hr = unregister_dmo_from_category(dmoW, catW, categorieskey);
269 lend:
270 if (categorieskey)
271 RegCloseKey(categorieskey);
273 return hr;
277 /***************************************************************
278 * DMOGetName (MSDMO.@)
280 * Get DMO Name from the registry
282 HRESULT WINAPI DMOGetName(REFCLSID clsidDMO, WCHAR name[])
284 static const INT max_name_len = 80*sizeof(WCHAR);
285 DWORD count = max_name_len;
286 WCHAR szguid[64];
287 HKEY hrkey, hkey;
288 LONG ret;
290 TRACE("%s %p\n", debugstr_guid(clsidDMO), name);
292 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"DirectShow\\MediaObjects", 0, KEY_READ, &hrkey))
293 return E_FAIL;
295 ret = RegOpenKeyExW(hrkey, GUIDToString(szguid, clsidDMO), 0, KEY_READ, &hkey);
296 RegCloseKey(hrkey);
297 if (ret)
298 return E_FAIL;
300 ret = RegQueryValueExW(hkey, NULL, NULL, NULL, (LPBYTE)name, &count);
301 RegCloseKey(hkey);
303 if (!ret && count > 1)
305 TRACE("name=%s\n", debugstr_w(name));
306 return S_OK;
309 name[0] = 0;
310 return S_FALSE;
313 static HRESULT dup_partial_mediatype(const DMO_PARTIAL_MEDIATYPE *types, DWORD count, DMO_PARTIAL_MEDIATYPE **ret)
315 *ret = NULL;
317 if (count == 0)
318 return S_OK;
320 *ret = HeapAlloc(GetProcessHeap(), 0, count*sizeof(*types));
321 if (!*ret)
322 return E_OUTOFMEMORY;
324 memcpy(*ret, types, count*sizeof(*types));
325 return S_OK;
328 /**************************************************************************
329 * IEnumDMO_Constructor
331 static HRESULT IEnumDMO_Constructor(
332 REFGUID guidCategory,
333 DWORD dwFlags,
334 DWORD cInTypes,
335 const DMO_PARTIAL_MEDIATYPE *pInTypes,
336 DWORD cOutTypes,
337 const DMO_PARTIAL_MEDIATYPE *pOutTypes,
338 IEnumDMO **obj)
340 IEnumDMOImpl* lpedmo;
341 HRESULT hr;
343 *obj = NULL;
345 lpedmo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumDMOImpl));
346 if (!lpedmo)
347 return E_OUTOFMEMORY;
349 lpedmo->IEnumDMO_iface.lpVtbl = &edmovt;
350 lpedmo->ref = 1;
351 lpedmo->index = -1;
352 lpedmo->category = *guidCategory;
353 lpedmo->dwFlags = dwFlags;
354 lpedmo->cInTypes = cInTypes;
355 lpedmo->cOutTypes = cOutTypes;
356 lpedmo->hkey = NULL;
358 hr = dup_partial_mediatype(pInTypes, cInTypes, &lpedmo->pInTypes);
359 if (FAILED(hr))
360 goto lerr;
362 hr = dup_partial_mediatype(pOutTypes, cOutTypes, &lpedmo->pOutTypes);
363 if (FAILED(hr))
364 goto lerr;
366 /* If not filtering by category enum from media objects root */
367 if (IsEqualGUID(guidCategory, &GUID_NULL))
369 RegOpenKeyExW(HKEY_CLASSES_ROOT, L"DirectShow\\MediaObjects", 0, KEY_READ, &lpedmo->hkey);
371 else
373 WCHAR szguid[64];
374 WCHAR szKey[MAX_PATH];
376 swprintf(szKey, ARRAY_SIZE(szKey), L"DirectShow\\MediaObjects\\Categories\\%s",
377 GUIDToString(szguid, guidCategory));
378 RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &lpedmo->hkey);
381 lerr:
383 if (FAILED(hr))
384 IEnumDMO_Release(&lpedmo->IEnumDMO_iface);
385 else
387 TRACE("returning %p\n", lpedmo);
388 *obj = &lpedmo->IEnumDMO_iface;
391 return hr;
394 /******************************************************************************
395 * IEnumDMO_fnAddRef
397 static ULONG WINAPI IEnumDMO_fnAddRef(IEnumDMO * iface)
399 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
400 ULONG refCount = InterlockedIncrement(&This->ref);
401 TRACE("(%p)->(%d)\n", This, refCount);
402 return refCount;
405 /**************************************************************************
406 * EnumDMO_QueryInterface
408 static HRESULT WINAPI IEnumDMO_fnQueryInterface(IEnumDMO* iface, REFIID riid, void **ppvObj)
410 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
412 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObj);
414 *ppvObj = NULL;
416 if (IsEqualIID(riid, &IID_IEnumDMO) ||
417 IsEqualIID(riid, &IID_IUnknown))
419 *ppvObj = iface;
420 IEnumDMO_AddRef(iface);
423 return *ppvObj ? S_OK : E_NOINTERFACE;
426 /******************************************************************************
427 * IEnumDMO_fnRelease
429 static ULONG WINAPI IEnumDMO_fnRelease(IEnumDMO * iface)
431 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
432 ULONG refCount = InterlockedDecrement(&This->ref);
434 TRACE("(%p)->(%d)\n", This, refCount);
436 if (!refCount)
438 if (This->hkey)
439 RegCloseKey(This->hkey);
440 HeapFree(GetProcessHeap(), 0, This->pInTypes);
441 HeapFree(GetProcessHeap(), 0, This->pOutTypes);
442 HeapFree(GetProcessHeap(), 0, This);
444 return refCount;
447 static BOOL any_types_match(const DMO_PARTIAL_MEDIATYPE *a, unsigned int a_count,
448 const DMO_PARTIAL_MEDIATYPE *b, unsigned int b_count)
450 unsigned int i, j;
452 for (i = 0; i < a_count; ++i)
454 for (j = 0; j < b_count; ++j)
456 if (IsMediaTypeEqual(&a[i], &b[j]))
457 return TRUE;
460 return FALSE;
463 /******************************************************************************
464 * IEnumDMO_fnNext
466 static HRESULT WINAPI IEnumDMO_fnNext(
467 IEnumDMO * iface,
468 DWORD cItemsToFetch,
469 CLSID * pCLSID,
470 WCHAR ** Names,
471 DWORD * pcItemsFetched)
473 DMO_PARTIAL_MEDIATYPE *types = NULL;
474 unsigned int types_size = 0;
475 HKEY hkey;
476 WCHAR szNextKey[MAX_PATH];
477 WCHAR path[MAX_PATH];
478 WCHAR szValue[MAX_PATH];
479 DWORD len;
480 UINT count = 0;
481 HRESULT hres = S_OK;
482 LONG ret;
484 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
486 TRACE("(%p)->(%d %p %p %p)\n", This, cItemsToFetch, pCLSID, Names, pcItemsFetched);
488 if (!pCLSID)
489 return E_POINTER;
491 if (!pcItemsFetched && cItemsToFetch > 1)
492 return E_INVALIDARG;
494 while (count < cItemsToFetch)
496 This->index++;
498 len = MAX_PATH;
499 ret = RegEnumKeyExW(This->hkey, This->index, szNextKey, &len, NULL, NULL, NULL, NULL);
500 if (ret != ERROR_SUCCESS)
502 hres = HRESULT_FROM_WIN32(ret);
503 break;
506 if (string_to_guid(szNextKey, &pCLSID[count]) != S_OK)
507 continue;
509 TRACE("found %s\n", debugstr_w(szNextKey));
511 if (!(This->dwFlags & DMO_ENUMF_INCLUDE_KEYED))
513 swprintf(path, ARRAY_SIZE(path), L"DirectShow\\MediaObjects\\%s\\Keyed", szNextKey);
514 ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, path, 0, KEY_READ, &hkey);
515 if (ERROR_SUCCESS == ret)
517 RegCloseKey(hkey);
518 /* Skip Keyed entries */
519 continue;
523 swprintf(path, ARRAY_SIZE(path), L"DirectShow\\MediaObjects\\%s", szNextKey);
524 ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, path, 0, KEY_READ, &hkey);
525 TRACE("Testing %s.\n", debugstr_w(path));
527 if (This->pInTypes)
529 DWORD size, i;
531 for (;;)
533 size = types_size;
534 ret = RegQueryValueExW(hkey, L"InputTypes", NULL, NULL, (BYTE *)types, &size);
535 if (ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA)
536 break;
537 if (size <= types_size)
538 break;
539 if (!array_reserve((void **)&types, &types_size, size, 1))
541 RegCloseKey(hkey);
542 free(types);
543 return E_OUTOFMEMORY;
546 if (ret)
548 RegCloseKey(hkey);
549 continue;
552 for (i = 0; i < size / sizeof(DMO_PARTIAL_MEDIATYPE); ++i)
553 TRACE("intype %d: type %s, subtype %s\n", i, debugstr_guid(&types[i].type),
554 debugstr_guid(&types[i].subtype));
556 if (!any_types_match(types, size / sizeof(DMO_PARTIAL_MEDIATYPE), This->pInTypes, This->cInTypes))
558 RegCloseKey(hkey);
559 continue;
563 if (This->pOutTypes)
565 DWORD size = types_size, i;
567 for (;;)
569 size = types_size;
570 ret = RegQueryValueExW(hkey, L"OutputTypes", NULL, NULL, (BYTE *)types, &size);
571 if (ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA)
572 break;
573 if (size <= types_size)
574 break;
575 if (!array_reserve((void **)&types, &types_size, size, 1))
577 RegCloseKey(hkey);
578 free(types);
579 return E_OUTOFMEMORY;
582 if (ret)
584 RegCloseKey(hkey);
585 continue;
588 for (i = 0; i < size / sizeof(DMO_PARTIAL_MEDIATYPE); ++i)
589 TRACE("outtype %d: type %s, subtype %s\n", i, debugstr_guid(&types[i].type),
590 debugstr_guid(&types[i].subtype));
592 if (!any_types_match(types, size / sizeof(DMO_PARTIAL_MEDIATYPE), This->pOutTypes, This->cOutTypes))
594 RegCloseKey(hkey);
595 continue;
599 /* Media object wasn't filtered so add it to return list */
600 len = MAX_PATH * sizeof(WCHAR);
601 ret = RegQueryValueExW(hkey, NULL, NULL, NULL, (LPBYTE)szValue, &len);
602 if (Names)
604 Names[count] = NULL;
605 if (ret == ERROR_SUCCESS)
607 Names[count] = CoTaskMemAlloc((wcslen(szValue) + 1) * sizeof(WCHAR));
608 if (Names[count])
609 wcscpy(Names[count], szValue);
613 TRACE("found match %s %s\n", debugstr_w(szValue), debugstr_w(szNextKey));
614 RegCloseKey(hkey);
615 count++;
618 free(types);
620 if (pcItemsFetched) *pcItemsFetched = count;
621 if (count < cItemsToFetch)
622 hres = S_FALSE;
624 TRACE("<-- %i found\n",count);
625 return hres;
629 /******************************************************************************
630 * IEnumDMO_fnSkip
632 static HRESULT WINAPI IEnumDMO_fnSkip(IEnumDMO * iface, DWORD cItemsToSkip)
634 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
636 TRACE("(%p)->(%d)\n", This, cItemsToSkip);
637 This->index += cItemsToSkip;
639 return S_OK;
643 /******************************************************************************
644 * IEnumDMO_fnReset
646 static HRESULT WINAPI IEnumDMO_fnReset(IEnumDMO * iface)
648 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
650 TRACE("(%p)\n", This);
651 This->index = -1;
653 return S_OK;
657 /******************************************************************************
658 * IEnumDMO_fnClone
660 static HRESULT WINAPI IEnumDMO_fnClone(IEnumDMO *iface, IEnumDMO **ppEnum)
662 IEnumDMOImpl *This = impl_from_IEnumDMO(iface);
663 TRACE("(%p)->(%p)\n", This, ppEnum);
664 return IEnumDMO_Constructor(&This->category, This->dwFlags, This->cInTypes, This->pInTypes,
665 This->cOutTypes, This->pOutTypes, ppEnum);
669 /***************************************************************
670 * DMOEnum (MSDMO.@)
672 * Enumerate DirectX Media Objects in the registry.
674 HRESULT WINAPI DMOEnum(
675 REFGUID category,
676 DWORD flags,
677 DWORD cInTypes,
678 const DMO_PARTIAL_MEDIATYPE *pInTypes,
679 DWORD cOutTypes,
680 const DMO_PARTIAL_MEDIATYPE *pOutTypes,
681 IEnumDMO **ppEnum)
683 TRACE("%s 0x%08x %d %p %d %p %p\n", debugstr_guid(category), flags, cInTypes, pInTypes,
684 cOutTypes, pOutTypes, ppEnum);
686 if (TRACE_ON(msdmo))
688 DWORD i;
689 if (cInTypes)
691 for (i = 0; i < cInTypes; i++)
692 TRACE("intype %d - type %s, subtype %s\n", i, debugstr_guid(&pInTypes[i].type),
693 debugstr_guid(&pInTypes[i].subtype));
696 if (cOutTypes) {
697 for (i = 0; i < cOutTypes; i++)
698 TRACE("outtype %d - type %s, subtype %s\n", i, debugstr_guid(&pOutTypes[i].type),
699 debugstr_guid(&pOutTypes[i].subtype));
703 return IEnumDMO_Constructor(category, flags, cInTypes,
704 pInTypes, cOutTypes, pOutTypes, ppEnum);
708 static const IEnumDMOVtbl edmovt =
710 IEnumDMO_fnQueryInterface,
711 IEnumDMO_fnAddRef,
712 IEnumDMO_fnRelease,
713 IEnumDMO_fnNext,
714 IEnumDMO_fnSkip,
715 IEnumDMO_fnReset,
716 IEnumDMO_fnClone,
719 /***************************************************************
720 * DMOGetTypes (MSDMO.@)
722 HRESULT WINAPI DMOGetTypes(REFCLSID clsid, ULONG input_count, ULONG *ret_input_count, DMO_PARTIAL_MEDIATYPE *input,
723 ULONG output_count, ULONG *ret_output_count, DMO_PARTIAL_MEDIATYPE *output)
725 WCHAR guidstr[64];
726 HKEY root, key;
727 LSTATUS ret;
728 DWORD size;
730 TRACE("clsid %s, input_count %u, ret_input_count %p, input %p, output_count %u, ret_output_count %p, output %p.\n",
731 debugstr_guid(clsid), input_count, ret_input_count, input, output_count, ret_output_count, output);
733 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, L"DirectShow\\MediaObjects", 0, KEY_READ, &root))
734 return E_FAIL;
736 if (RegOpenKeyExW(root, GUIDToString(guidstr, clsid), 0, KEY_READ, &key))
738 RegCloseKey(root);
739 return E_FAIL;
742 *ret_input_count = 0;
743 size = input_count * sizeof(DMO_PARTIAL_MEDIATYPE);
744 ret = RegQueryValueExW(key, L"InputTypes", NULL, NULL, (BYTE *)input, &size);
745 if (!ret || ret == ERROR_MORE_DATA)
746 *ret_input_count = min(input_count, size / sizeof(DMO_PARTIAL_MEDIATYPE));
748 *ret_output_count = 0;
749 size = output_count * sizeof(DMO_PARTIAL_MEDIATYPE);
750 ret = RegQueryValueExW(key, L"OutputTypes", NULL, NULL, (BYTE *)output, &size);
751 if (!ret || ret == ERROR_MORE_DATA)
752 *ret_output_count = min(output_count, size / sizeof(DMO_PARTIAL_MEDIATYPE));
754 RegCloseKey(key);
755 RegCloseKey(root);
756 return S_OK;