Implement NtAccessCheck.
[wine/gsoc-2012-control.git] / dlls / msdmo / dmoreg.c
blobc43a2d0ab4e27ea18b39cce5396abac439781266
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #define COM_NO_WINDOWS_H
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "winerror.h"
27 #include "winreg.h"
28 #include "objbase.h"
29 #include "dmo.h"
31 #include "wine/unicode.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msdmo);
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 typedef struct
82 IEnumDMOVtbl *lpVtbl;
83 DWORD ref;
84 DWORD index;
85 const GUID* guidCategory;
86 DWORD dwFlags;
87 DWORD cInTypes;
88 DMO_PARTIAL_MEDIATYPE *pInTypes;
89 DWORD cOutTypes;
90 DMO_PARTIAL_MEDIATYPE *pOutTypes;
91 HKEY hkey;
92 } IEnumDMOImpl;
94 const GUID IID_IEnumDMO = { 0x2c3cd98a, 0x2bfa, 0x4a53,
95 { 0x9c, 0x27, 0x52, 0x49, 0xba, 0x64, 0xba, 0x0f}};
97 static struct IEnumDMOVtbl edmovt;
99 static LPWSTR GUIDToString(LPWSTR lpwstr, REFGUID lpcguid)
101 wsprintfW(lpwstr, szGUIDFmt, lpcguid->Data1, lpcguid->Data2,
102 lpcguid->Data3, lpcguid->Data4[0], lpcguid->Data4[1],
103 lpcguid->Data4[2], lpcguid->Data4[3], lpcguid->Data4[4],
104 lpcguid->Data4[5], lpcguid->Data4[6], lpcguid->Data4[7]);
106 return lpwstr;
109 static BOOL IsMediaTypeEqual(DMO_PARTIAL_MEDIATYPE* mt1, DMO_PARTIAL_MEDIATYPE* mt2)
112 return (IsEqualCLSID(&mt1->type, &mt2->type) ||
113 IsEqualCLSID(&mt2->type, &GUID_NULL) ||
114 IsEqualCLSID(&mt1->type, &GUID_NULL)) &&
115 (IsEqualCLSID(&mt1->subtype, &mt2->subtype) ||
116 IsEqualCLSID(&mt2->subtype, &GUID_NULL) ||
117 IsEqualCLSID(&mt1->subtype, &GUID_NULL));
120 /***************************************************************
121 * DMORegister
123 * Register a DirectX Media Object.
125 HRESULT WINAPI DMORegister(
126 LPCWSTR szName,
127 REFCLSID clsidDMO,
128 REFGUID guidCategory,
129 DWORD dwFlags,
130 DWORD cInTypes,
131 const DMO_PARTIAL_MEDIATYPE *pInTypes,
132 DWORD cOutTypes,
133 const DMO_PARTIAL_MEDIATYPE *pOutTypes
136 WCHAR szguid[64];
137 HRESULT hres;
138 HKEY hrkey = 0;
139 HKEY hkey = 0;
140 HKEY hckey = 0;
141 HKEY hclskey = 0;
143 TRACE("%s\n", debugstr_w(szName));
145 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, KEY_WRITE, &hrkey);
146 if (ERROR_SUCCESS != hres)
147 goto lend;
149 /* Create clsidDMO key under MediaObjects */
150 hres = RegCreateKeyExW(hrkey, GUIDToString(szguid, clsidDMO), 0, NULL,
151 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
152 if (ERROR_SUCCESS != hres)
153 goto lend;
155 /* Set default Name value */
156 hres = RegSetValueExW(hkey, NULL, 0, REG_SZ, (const BYTE*) szName,
157 (strlenW(szName) + 1)) * sizeof(WCHAR);
158 /* Set InputTypes */
159 hres = RegSetValueExW(hkey, szDMOInputType, 0, REG_BINARY,
160 (const BYTE*) pInTypes, cInTypes * sizeof(DMO_PARTIAL_MEDIATYPE));
161 /* Set OutputTypes */
162 hres = RegSetValueExW(hkey, szDMOOutputType, 0, REG_BINARY,
163 (const BYTE*) pOutTypes, cOutTypes * sizeof(DMO_PARTIAL_MEDIATYPE));
165 if (dwFlags & DMO_REGISTERF_IS_KEYED)
167 /* Create Keyed key */
168 hres = RegCreateKeyExW(hkey, szDMOKeyed, 0, NULL,
169 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hckey, NULL);
170 if (ERROR_SUCCESS != hres)
171 goto lend;
172 RegCloseKey(hckey);
175 /* Register the category */
176 hres = RegOpenKeyExW(hrkey, szDMOCategories, 0, KEY_WRITE, &hckey);
177 if (ERROR_SUCCESS != hres)
178 goto lend;
180 RegCloseKey(hkey);
182 hres = RegOpenKeyExW(hckey, GUIDToString(szguid, guidCategory), 0, KEY_WRITE, &hkey);
183 if (ERROR_SUCCESS != hres)
184 goto lend;
185 hres = RegCreateKeyExW(hkey, GUIDToString(szguid, clsidDMO), 0, NULL,
186 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hclskey, NULL);
187 if (ERROR_SUCCESS != hres)
188 goto lend;
190 lend:
191 if (hkey)
192 RegCloseKey(hkey);
193 if (hckey)
194 RegCloseKey(hckey);
195 if (hclskey)
196 RegCloseKey(hclskey);
197 if (hrkey)
198 RegCloseKey(hrkey);
200 TRACE(" hresult=0x%08lx\n", hres);
201 return hres;
205 /***************************************************************
206 * DMOUnregister
208 * Unregister a DirectX Media Object.
210 HRESULT WINAPI DMOUnregister(REFCLSID clsidDMO, REFGUID guidCategory)
212 HRESULT hres;
213 WCHAR szguid[64];
214 HKEY hrkey = 0;
215 HKEY hckey = 0;
217 GUIDToString(szguid, clsidDMO);
219 TRACE("%s %p\n", debugstr_w(szguid), guidCategory);
221 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, KEY_WRITE, &hrkey);
222 if (ERROR_SUCCESS != hres)
223 goto lend;
225 hres = RegDeleteKeyW(hrkey, szguid);
226 if (ERROR_SUCCESS != hres)
227 goto lend;
229 hres = RegOpenKeyExW(hrkey, szDMOCategories, 0, KEY_WRITE, &hckey);
230 if (ERROR_SUCCESS != hres)
231 goto lend;
233 hres = RegDeleteKeyW(hckey, szguid);
234 if (ERROR_SUCCESS != hres)
235 goto lend;
237 lend:
238 if (hckey)
239 RegCloseKey(hckey);
240 if (hrkey)
241 RegCloseKey(hrkey);
243 return hres;
247 /***************************************************************
248 * DMOGetName
250 * Get DMP Name from the registry
252 HRESULT WINAPI DMOGetName(REFCLSID clsidDMO, WCHAR* szName)
254 WCHAR szguid[64];
255 HRESULT hres;
256 HKEY hrkey = 0;
257 HKEY hkey = 0;
258 DWORD count;
260 TRACE("%s\n", debugstr_guid(clsidDMO));
262 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey,
263 0, KEY_READ, &hrkey);
264 if (ERROR_SUCCESS != hres)
265 goto lend;
267 hres = RegOpenKeyExW(hrkey, GUIDToString(szguid, clsidDMO),
268 0, KEY_READ, &hkey);
269 if (ERROR_SUCCESS != hres)
270 goto lend;
272 count = 80 * sizeof(WCHAR); /* 80 by API definition */
273 hres = RegQueryValueExW(hkey, NULL, NULL, NULL,
274 (LPBYTE) szName, &count);
276 TRACE(" szName=%s\n", debugstr_w(szName));
277 lend:
278 if (hkey)
279 RegCloseKey(hrkey);
280 if (hkey)
281 RegCloseKey(hkey);
283 return hres;
287 /**************************************************************************
288 * IEnumDMO_Destructor
290 static BOOL IEnumDMO_Destructor(IEnumDMO* iface)
292 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
294 TRACE("%p\n", This);
296 if (This->hkey)
297 RegCloseKey(This->hkey);
299 HeapFree(GetProcessHeap(), 0, This->pInTypes);
300 HeapFree(GetProcessHeap(), 0, This->pOutTypes);
302 return TRUE;
306 /**************************************************************************
307 * IEnumDMO_Constructor
309 IEnumDMO * IEnumDMO_Constructor(
310 REFGUID guidCategory,
311 DWORD dwFlags,
312 DWORD cInTypes,
313 const DMO_PARTIAL_MEDIATYPE *pInTypes,
314 DWORD cOutTypes,
315 const DMO_PARTIAL_MEDIATYPE *pOutTypes)
317 UINT size;
318 IEnumDMOImpl* lpedmo;
319 BOOL ret = FALSE;
321 lpedmo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IEnumDMOImpl));
323 if (lpedmo)
325 lpedmo->ref = 1;
326 lpedmo->lpVtbl = &edmovt;
327 lpedmo->index = -1;
328 lpedmo->guidCategory = guidCategory;
329 lpedmo->dwFlags = dwFlags;
331 size = cInTypes * sizeof(DMO_PARTIAL_MEDIATYPE);
332 lpedmo->pInTypes = HeapAlloc(GetProcessHeap(), 0, size);
333 if (!lpedmo->pInTypes)
334 goto lerr;
335 memcpy(lpedmo->pInTypes, pInTypes, size);
336 lpedmo->cInTypes = cInTypes;
338 size = cOutTypes * sizeof(DMO_PARTIAL_MEDIATYPE);
339 lpedmo->pOutTypes = HeapAlloc(GetProcessHeap(), 0, size);
340 if (!lpedmo->pOutTypes)
341 goto lerr;
342 memcpy(lpedmo->pOutTypes, pOutTypes, size);
343 lpedmo->cOutTypes = cOutTypes;
345 /* If not filtering by category enum from media objects root */
346 if (IsEqualGUID(guidCategory, &GUID_NULL))
348 if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey,
349 0, KEY_READ, &lpedmo->hkey))
350 ret = TRUE;
352 else
354 WCHAR szguid[64];
355 WCHAR szKey[MAX_PATH];
357 wsprintfW(szKey, szCat3Fmt, szDMORootKey, szDMOCategories,
358 GUIDToString(szguid, guidCategory));
359 if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey,
360 0, KEY_READ, &lpedmo->hkey))
361 ret = TRUE;
364 lerr:
365 if(!ret)
367 IEnumDMO_Destructor((IEnumDMO*)lpedmo);
368 HeapFree(GetProcessHeap(),0,lpedmo);
369 lpedmo = NULL;
373 TRACE("returning %p\n", lpedmo);
375 return (IEnumDMO*)lpedmo;
379 /******************************************************************************
380 * IEnumDMO_fnAddRef
382 static ULONG WINAPI IEnumDMO_fnAddRef(IEnumDMO * iface)
384 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
385 return InterlockedIncrement(&This->ref);
389 /**************************************************************************
390 * EnumDMO_QueryInterface
392 static HRESULT WINAPI IEnumDMO_fnQueryInterface(
393 IEnumDMO* iface,
394 REFIID riid,
395 LPVOID *ppvObj)
397 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
399 *ppvObj = NULL;
401 if(IsEqualIID(riid, &IID_IUnknown))
402 *ppvObj = This;
403 else if(IsEqualIID(riid, &IID_IEnumDMO))
404 *ppvObj = (IEnumDMO*)This;
406 if(*ppvObj)
408 IEnumDMO_fnAddRef((IEnumDMO*)*ppvObj);
409 return S_OK;
412 return E_NOINTERFACE;
416 /******************************************************************************
417 * IEnumDMO_fnRelease
419 static ULONG WINAPI IEnumDMO_fnRelease(IEnumDMO * iface)
421 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
422 ULONG refCount = InterlockedDecrement(&This->ref);
424 if (!refCount)
426 IEnumDMO_Destructor((IEnumDMO*)This);
427 HeapFree(GetProcessHeap(),0,This);
429 return refCount;
433 /******************************************************************************
434 * IEnumDMO_fnNext
436 static HRESULT WINAPI IEnumDMO_fnNext(
437 IEnumDMO * iface,
438 DWORD cItemsToFetch,
439 CLSID * pCLSID,
440 WCHAR ** Names,
441 DWORD * pcItemsFetched)
443 FILETIME ft;
444 HKEY hkey;
445 WCHAR szNextKey[MAX_PATH];
446 WCHAR szKey[MAX_PATH];
447 WCHAR szValue[MAX_PATH];
448 DWORD len;
449 UINT count = 0;
450 HRESULT hres = S_OK;
452 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
454 TRACE("%ld\n", cItemsToFetch);
456 if (!pCLSID || !Names || !pcItemsFetched)
457 return E_POINTER;
459 while (count < cItemsToFetch)
461 This->index++;
463 hres = RegEnumKeyExW(This->hkey, This->index, szNextKey, &len, NULL, NULL, NULL, &ft);
464 if (hres != ERROR_SUCCESS)
465 break;
467 TRACE("found %s\n", debugstr_w(szNextKey));
469 if (This->dwFlags & DMO_REGISTERF_IS_KEYED)
471 wsprintfW(szKey, szCat3Fmt, szDMORootKey, szNextKey, szDMOKeyed);
472 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hkey);
473 if (ERROR_SUCCESS != hres)
474 continue;
475 RegCloseKey(hkey);
478 wsprintfW(szKey, szCat2Fmt, szDMORootKey, szNextKey);
479 hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hkey);
481 if (This->pInTypes)
483 UINT i, j;
484 DWORD cInTypes;
485 DMO_PARTIAL_MEDIATYPE* pInTypes;
487 len = MAX_PATH * sizeof(WCHAR);
488 hres = RegQueryValueExW(hkey, szDMOInputType, NULL, NULL, (LPBYTE) szValue, &len);
489 if (ERROR_SUCCESS != hres)
491 RegCloseKey(hkey);
492 continue;
495 cInTypes = len / sizeof(DMO_PARTIAL_MEDIATYPE);
496 pInTypes = (DMO_PARTIAL_MEDIATYPE*) szValue;
498 for (i = 0; i < This->cInTypes; i++)
500 for (j = 0; j < cInTypes; j++)
502 if (IsMediaTypeEqual(&pInTypes[j], &This->pInTypes[i]))
503 break;
506 if (j >= cInTypes)
507 break;
510 if (i < This->cInTypes)
512 RegCloseKey(hkey);
513 continue;
517 if (This->pOutTypes)
519 UINT i, j;
520 DWORD cOutTypes;
521 DMO_PARTIAL_MEDIATYPE* pOutTypes;
523 len = MAX_PATH * sizeof(WCHAR);
524 hres = RegQueryValueExW(hkey, szDMOOutputType, NULL, NULL, (LPBYTE) szValue, &len);
525 if (ERROR_SUCCESS != hres)
527 RegCloseKey(hkey);
528 continue;
531 cOutTypes = len / sizeof(DMO_PARTIAL_MEDIATYPE);
532 pOutTypes = (DMO_PARTIAL_MEDIATYPE*) szValue;
534 for (i = 0; i < This->cOutTypes; i++)
536 for (j = 0; j < cOutTypes; j++)
538 if (IsMediaTypeEqual(&pOutTypes[j], &This->pOutTypes[i]))
539 break;
542 if (j >= cOutTypes)
543 break;
546 if (i < This->cOutTypes)
548 RegCloseKey(hkey);
549 continue;
553 /* Media object wasn't filtered so add it to return list */
554 Names[count] = NULL;
555 len = MAX_PATH * sizeof(WCHAR);
556 hres = RegQueryValueExW(hkey, NULL, NULL, NULL, (LPBYTE) szValue, &len);
557 if (ERROR_SUCCESS == hres)
559 Names[count] = HeapAlloc(GetProcessHeap(), 0, strlenW(szValue) + 1);
560 if (Names[count])
561 strcmpW(Names[count], szValue);
563 CLSIDFromString(szNextKey, &pCLSID[count]);
565 TRACE("found match %s %s\n", debugstr_w(szValue), debugstr_w(szNextKey));
566 RegCloseKey(hkey);
567 count++;
570 *pcItemsFetched = count;
571 if (*pcItemsFetched < cItemsToFetch)
572 hres = S_FALSE;
574 return hres;
578 /******************************************************************************
579 * IEnumDMO_fnSkip
581 static HRESULT WINAPI IEnumDMO_fnSkip(IEnumDMO * iface, DWORD cItemsToSkip)
583 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
585 This->index += cItemsToSkip;
587 return S_OK;
591 /******************************************************************************
592 * IEnumDMO_fnReset
594 static HRESULT WINAPI IEnumDMO_fnReset(IEnumDMO * iface)
596 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
598 This->index = -1;
600 return S_OK;
604 /******************************************************************************
605 * IEnumDMO_fnClone
607 static HRESULT WINAPI IEnumDMO_fnClone(IEnumDMO * iface, IEnumDMO **ppEnum)
609 IEnumDMOImpl *This = (IEnumDMOImpl *)iface;
611 FIXME("(%p)->() to (%p)->() E_NOTIMPL\n", This, ppEnum);
613 return E_NOTIMPL;
617 /***************************************************************
618 * DMOEnum
620 * Enumerate DirectX Media Objects in the registry.
622 HRESULT WINAPI DMOEnum(
623 REFGUID guidCategory,
624 DWORD dwFlags,
625 DWORD cInTypes,
626 const DMO_PARTIAL_MEDIATYPE *pInTypes,
627 DWORD cOutTypes,
628 const DMO_PARTIAL_MEDIATYPE *pOutTypes,
629 IEnumDMO **ppEnum)
631 HRESULT hres = E_FAIL;
633 TRACE("guidCategory=%p dwFlags=0x%08lx cInTypes=%ld cOutTypes=%ld\n",
634 guidCategory, dwFlags, cInTypes, cOutTypes);
636 *ppEnum = IEnumDMO_Constructor(guidCategory, dwFlags, cInTypes,
637 pInTypes, cOutTypes, pOutTypes);
638 if (*ppEnum)
639 hres = S_OK;
641 return hres;
645 static IEnumDMOVtbl edmovt =
647 IEnumDMO_fnQueryInterface,
648 IEnumDMO_fnAddRef,
649 IEnumDMO_fnRelease,
650 IEnumDMO_fnNext,
651 IEnumDMO_fnSkip,
652 IEnumDMO_fnReset,
653 IEnumDMO_fnClone,
657 HRESULT WINAPI DMOGetTypes(REFCLSID a, unsigned long b, unsigned long* c,
658 DMO_PARTIAL_MEDIATYPE* d, unsigned long e,
659 unsigned long* f, DMO_PARTIAL_MEDIATYPE* g)
661 FIXME("(%p,%lu,%p,%p,%lu,%p,%p),stub!\n",a,b,c,d,e,f,g);
663 return E_NOTIMPL;