Report win2k service pack 4 instead of 3.
[wine/multimedia.git] / dlls / quartz / filtermapper.c
bloba102b863b18262a9898830e5d486d2af4d5e8d56
1 /*
2 * IFilterMapper & IFilterMapper2 Implementations
4 * Copyright 2003 Robert Shearman
5 * Copyright 2004 Christian Costa
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "winerror.h"
32 #include "quartz_private.h"
34 #define COM_NO_WINDOWS_H
35 #include "ole2.h"
36 #include "olectl.h"
37 #include "strmif.h"
38 #include "wine/unicode.h"
39 #include "uuids.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
45 typedef struct FilterMapper2Impl
47 ICOM_VFIELD(IFilterMapper2);
48 ICOM_VTABLE(IFilterMapper) * lpVtblFilterMapper;
49 ULONG refCount;
50 } FilterMapper2Impl;
52 static struct ICOM_VTABLE(IFilterMapper2) fm2vtbl;
53 static struct ICOM_VTABLE(IFilterMapper) fmvtbl;
55 #define _IFilterMapper_Offset ((int)(&(((FilterMapper2Impl*)0)->lpVtblFilterMapper)))
56 #define ICOM_THIS_From_IFilterMapper(impl, iface) impl* This = (impl*)(((char*)iface)-_IFilterMapper_Offset)
58 static const WCHAR wszClsidSlash[] = {'C','L','S','I','D','\\',0};
59 static const WCHAR wszSlashInstance[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
60 static const WCHAR wszSlash[] = {'\\',0};
62 /* CLSID property in media category Moniker */
63 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
64 /* FriendlyName property in media category Moniker */
65 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
66 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
67 static const WCHAR wszMeritName[] = {'M','e','r','i','t',0};
68 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
69 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
70 /* For filters registered with IFilterMapper */
71 static const WCHAR wszFilterSlash[] = {'F','i','l','t','e','r','\\',0};
72 static const WCHAR wszFilter[] = {'F','i','l','t','e','r',0};
73 /* For pins registered with IFilterMapper */
74 static const WCHAR wszPins[] = {'P','i','n','s',0};
75 static const WCHAR wszAllowedMany[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
76 static const WCHAR wszAllowedZero[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
77 static const WCHAR wszDirection[] = {'D','i','r','e','c','t','i','o','n',0};
78 static const WCHAR wszIsRendered[] = {'I','s','R','e','n','d','e','r','e','d',0};
79 /* For types registered with IFilterMapper */
80 static const WCHAR wszTypes[] = {'T','y','p','e','s',0};
83 /* registry format for REGFILTER2 */
84 struct REG_RF
86 DWORD dwVersion;
87 DWORD dwMerit;
88 DWORD dwPins;
89 DWORD dwUnused;
92 struct REG_RFP
94 BYTE signature[4]; /* e.g. "0pi3" */
95 DWORD dwFlags;
96 DWORD dwInstances;
97 DWORD dwMediaTypes;
98 DWORD dwMediums;
99 DWORD bCategory; /* is there a category clsid? */
100 /* optional: dwOffsetCategoryClsid */
103 struct REG_TYPE
105 BYTE signature[4]; /* e.g. "0ty3" */
106 DWORD dwUnused;
107 DWORD dwOffsetMajor;
108 DWORD dwOffsetMinor;
111 struct MONIKER_MERIT
113 IMoniker * pMoniker;
114 DWORD dwMerit;
117 struct Vector
119 LPBYTE pData;
120 int capacity; /* in bytes */
121 int current; /* pointer to next free byte */
124 /* returns the position it was added at */
125 static int add_data(struct Vector * v, const BYTE * pData, int size)
127 int index = v->current;
128 if (v->current + size > v->capacity)
130 LPBYTE pOldData = v->pData;
131 v->capacity = (v->capacity + size) * 2;
132 v->pData = CoTaskMemAlloc(v->capacity);
133 memcpy(v->pData, pOldData, v->current);
134 CoTaskMemFree(pOldData);
136 memcpy(v->pData + v->current, pData, size);
137 v->current += size;
138 return index;
141 static int find_data(struct Vector * v, const BYTE * pData, int size)
143 int index;
144 for (index = 0; index < v->current; index++)
145 if (!memcmp(v->pData + index, pData, size))
146 return index;
147 /* not found */
148 return -1;
151 static void delete_vector(struct Vector * v)
153 if (v->pData)
154 CoTaskMemFree(v->pData);
155 v->current = 0;
156 v->capacity = 0;
159 HRESULT FilterMapper2_create(IUnknown *pUnkOuter, LPVOID *ppObj)
161 FilterMapper2Impl * pFM2impl;
163 TRACE("(%p, %p)\n", pUnkOuter, ppObj);
165 if (pUnkOuter)
166 return CLASS_E_NOAGGREGATION;
168 pFM2impl = CoTaskMemAlloc(sizeof(*pFM2impl));
169 if (!pFM2impl)
170 return E_OUTOFMEMORY;
172 pFM2impl->lpVtbl = &fm2vtbl;
173 pFM2impl->lpVtblFilterMapper = &fmvtbl;
174 pFM2impl->refCount = 1;
176 *ppObj = pFM2impl;
178 TRACE("-- created at %p\n", pFM2impl);
180 return S_OK;
183 /*** IUnknown methods ***/
185 static HRESULT WINAPI FilterMapper2_QueryInterface(IFilterMapper2 * iface, REFIID riid, LPVOID *ppv)
187 ICOM_THIS(FilterMapper2Impl, iface);
189 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
191 *ppv = NULL;
193 if (IsEqualIID(riid, &IID_IUnknown))
194 *ppv = iface;
195 else if (IsEqualIID(riid, &IID_IFilterMapper2))
196 *ppv = iface;
197 else if (IsEqualIID(riid, &IID_IFilterMapper))
198 *ppv = &This->lpVtblFilterMapper;
200 if (*ppv != NULL)
202 IUnknown_AddRef((IUnknown *)*ppv);
203 return S_OK;
206 FIXME("No interface for %s\n", debugstr_guid(riid));
207 return E_NOINTERFACE;
210 static ULONG WINAPI FilterMapper2_AddRef(IFilterMapper2 * iface)
212 ICOM_THIS(FilterMapper2Impl, iface);
214 TRACE("(%p)->()\n", iface);
216 return InterlockedIncrement(&This->refCount);
219 static ULONG WINAPI FilterMapper2_Release(IFilterMapper2 * iface)
221 ICOM_THIS(FilterMapper2Impl, iface);
223 TRACE("(%p)->()\n", iface);
225 if (InterlockedDecrement(&This->refCount) == 0)
227 CoTaskMemFree(This);
228 return 0;
230 return This->refCount;
233 /*** IFilterMapper2 methods ***/
235 static HRESULT WINAPI FilterMapper2_CreateCategory(
236 IFilterMapper2 * iface,
237 REFCLSID clsidCategory,
238 DWORD dwCategoryMerit,
239 LPCWSTR szDescription)
241 LPWSTR wClsidAMCat = NULL;
242 LPWSTR wClsidCategory = NULL;
243 WCHAR wszKeyName[strlenW(wszClsidSlash) + strlenW(wszSlashInstance) + (CHARS_IN_GUID-1) * 2 + 1];
244 HKEY hKey = NULL;
245 HRESULT hr;
247 TRACE("(%s, %lx, %s)\n", debugstr_guid(clsidCategory), dwCategoryMerit, debugstr_w(szDescription));
249 hr = StringFromCLSID(&CLSID_ActiveMovieCategories, &wClsidAMCat);
251 if (SUCCEEDED(hr))
253 hr = StringFromCLSID(clsidCategory, &wClsidCategory);
256 if (SUCCEEDED(hr))
258 strcpyW(wszKeyName, wszClsidSlash);
259 strcatW(wszKeyName, wClsidAMCat);
260 strcatW(wszKeyName, wszSlashInstance);
261 strcatW(wszKeyName, wClsidCategory);
263 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL));
266 if (SUCCEEDED(hr))
268 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, wszFriendlyName, 0, REG_SZ, (LPBYTE)szDescription, strlenW(szDescription) + 1));
271 if (SUCCEEDED(hr))
273 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, wszClsidName, 0, REG_SZ, (LPBYTE)wClsidCategory, strlenW(wClsidCategory) + 1));
276 if (SUCCEEDED(hr))
278 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwCategoryMerit, sizeof(dwCategoryMerit)));
281 CloseHandle(hKey);
283 if (wClsidCategory)
284 CoTaskMemFree(wClsidCategory);
285 if (wClsidAMCat)
286 CoTaskMemFree(wClsidAMCat);
288 return hr;
291 static HRESULT WINAPI FilterMapper2_UnregisterFilter(
292 IFilterMapper2 * iface,
293 const CLSID *pclsidCategory,
294 const OLECHAR *szInstance,
295 REFCLSID Filter)
297 WCHAR wszKeyName[MAX_PATH];
298 LPWSTR wClsidCategory = NULL;
299 LPWSTR wFilter = NULL;
300 HRESULT hr;
302 TRACE("(%p, %s, %s)\n", pclsidCategory, debugstr_w(szInstance), debugstr_guid(Filter));
304 if (!pclsidCategory)
305 pclsidCategory = &CLSID_LegacyAmFilterCategory;
307 hr = StringFromCLSID(pclsidCategory, &wClsidCategory);
309 if (SUCCEEDED(hr))
311 strcpyW(wszKeyName, wszClsidSlash);
312 strcatW(wszKeyName, wClsidCategory);
313 strcatW(wszKeyName, wszSlashInstance);
314 if (szInstance)
315 strcatW(wszKeyName, szInstance);
316 else
318 hr = StringFromCLSID(Filter, &wFilter);
319 if (SUCCEEDED(hr))
320 strcatW(wszKeyName, wFilter);
324 if (SUCCEEDED(hr))
326 hr = HRESULT_FROM_WIN32(RegDeleteKeyW(HKEY_CLASSES_ROOT, wszKeyName));
329 if (wClsidCategory)
330 CoTaskMemFree(wClsidCategory);
331 if (wFilter)
332 CoTaskMemFree(wFilter);
334 return hr;
337 static HRESULT FM2_WriteFriendlyName(IPropertyBag * pPropBag, LPCWSTR szName)
339 VARIANT var;
341 V_VT(&var) = VT_BSTR;
342 V_UNION(&var, bstrVal) = (BSTR)szName;
344 return IPropertyBag_Write(pPropBag, wszFriendlyName, &var);
347 static HRESULT FM2_WriteClsid(IPropertyBag * pPropBag, REFCLSID clsid)
349 LPWSTR wszClsid = NULL;
350 VARIANT var;
351 HRESULT hr;
353 hr = StringFromCLSID(clsid, &wszClsid);
355 if (SUCCEEDED(hr))
357 V_VT(&var) = VT_BSTR;
358 V_UNION(&var, bstrVal) = wszClsid;
359 hr = IPropertyBag_Write(pPropBag, wszClsidName, &var);
361 if (wszClsid)
362 CoTaskMemFree(wszClsid);
363 return hr;
366 static HRESULT FM2_WriteFilterData(IPropertyBag * pPropBag, const REGFILTER2 * prf2)
368 VARIANT var;
369 int size = sizeof(struct REG_RF);
370 int i;
371 struct Vector mainStore = {NULL, 0, 0};
372 struct Vector clsidStore = {NULL, 0, 0};
373 struct REG_RF rrf;
374 SAFEARRAY * psa;
375 SAFEARRAYBOUND saBound;
376 HRESULT hr = S_OK;
378 rrf.dwVersion = prf2->dwVersion;
379 rrf.dwMerit = prf2->dwMerit;
380 rrf.dwPins = prf2->u.s1.cPins2;
381 rrf.dwUnused = 0;
383 add_data(&mainStore, (LPBYTE)&rrf, sizeof(rrf));
385 for (i = 0; i < prf2->u.s1.cPins2; i++)
387 size += sizeof(struct REG_RFP);
388 if (prf2->u.s1.rgPins2[i].clsPinCategory)
389 size += sizeof(DWORD);
390 size += prf2->u.s1.rgPins2[i].nMediaTypes * sizeof(struct REG_TYPE);
391 size += prf2->u.s1.rgPins2[i].nMediums * sizeof(DWORD);
394 for (i = 0; i < prf2->u.s1.cPins2; i++)
396 struct REG_RFP rrfp;
397 REGFILTERPINS2 rgPin2 = prf2->u.s1.rgPins2[i];
398 int j;
400 rrfp.signature[0] = '0';
401 rrfp.signature[1] = 'p';
402 rrfp.signature[2] = 'i';
403 rrfp.signature[3] = '3';
404 rrfp.signature[0] += i;
405 rrfp.dwFlags = rgPin2.dwFlags;
406 rrfp.dwInstances = rgPin2.cInstances;
407 rrfp.dwMediaTypes = rgPin2.nMediaTypes;
408 rrfp.dwMediums = rgPin2.nMediums;
409 rrfp.bCategory = rgPin2.clsPinCategory ? 1 : 0;
411 add_data(&mainStore, (LPBYTE)&rrfp, sizeof(rrfp));
412 if (rrfp.bCategory)
414 DWORD index = find_data(&clsidStore, (LPBYTE)rgPin2.clsPinCategory, sizeof(CLSID));
415 if (index == -1)
416 index = add_data(&clsidStore, (LPBYTE)rgPin2.clsPinCategory, sizeof(CLSID));
417 index += size;
419 add_data(&mainStore, (LPBYTE)&index, sizeof(index));
422 for (j = 0; j < rgPin2.nMediaTypes; j++)
424 struct REG_TYPE rt;
425 rt.signature[0] = '0';
426 rt.signature[1] = 't';
427 rt.signature[2] = 'y';
428 rt.signature[3] = '3';
429 rt.signature[0] += j;
431 rt.dwUnused = 0;
432 rt.dwOffsetMajor = find_data(&clsidStore, (LPBYTE)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
433 if (rt.dwOffsetMajor == -1)
434 rt.dwOffsetMajor = add_data(&clsidStore, (LPBYTE)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
435 rt.dwOffsetMajor += size;
436 rt.dwOffsetMinor = find_data(&clsidStore, (LPBYTE)rgPin2.lpMediaType[j].clsMinorType, sizeof(CLSID));
437 if (rt.dwOffsetMinor == -1)
438 rt.dwOffsetMinor = add_data(&clsidStore, (LPBYTE)rgPin2.lpMediaType[j].clsMinorType, sizeof(CLSID));
439 rt.dwOffsetMinor += size;
441 add_data(&mainStore, (LPBYTE)&rt, sizeof(rt));
444 for (j = 0; j < rgPin2.nMediums; j++)
446 DWORD index = find_data(&clsidStore, (LPBYTE)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
447 if (index == -1)
448 index = add_data(&clsidStore, (LPBYTE)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
449 index += size;
451 add_data(&mainStore, (LPBYTE)&index, sizeof(index));
455 saBound.lLbound = 0;
456 saBound.cElements = mainStore.current + clsidStore.current;
457 psa = SafeArrayCreate(VT_UI1, 1, &saBound);
458 if (!psa)
460 ERR("Couldn't create SAFEARRAY\n");
461 hr = E_FAIL;
464 if (SUCCEEDED(hr))
466 LPBYTE pbSAData;
467 hr = SafeArrayAccessData(psa, (LPVOID *)&pbSAData);
468 if (SUCCEEDED(hr))
470 memcpy(pbSAData, mainStore.pData, mainStore.current);
471 memcpy(pbSAData + mainStore.current, clsidStore.pData, clsidStore.current);
472 hr = SafeArrayUnaccessData(psa);
476 V_VT(&var) = VT_ARRAY | VT_UI1;
477 V_UNION(&var, parray) = psa;
479 if (SUCCEEDED(hr))
480 hr = IPropertyBag_Write(pPropBag, wszFilterDataName, &var);
482 if (psa)
483 SafeArrayDestroy(psa);
485 delete_vector(&mainStore);
486 delete_vector(&clsidStore);
487 return hr;
490 static HRESULT FM2_ReadFilterData(IPropertyBag * pPropBag, REGFILTER2 * prf2)
492 VARIANT var;
493 HRESULT hr;
494 LPBYTE pData = NULL;
495 struct REG_RF * prrf;
496 LPBYTE pCurrent;
497 DWORD i;
498 REGFILTERPINS2 * rgPins2;
500 VariantInit(&var);
501 V_VT(&var) = VT_ARRAY | VT_UI1;
503 hr = IPropertyBag_Read(pPropBag, wszFilterDataName, &var, NULL);
505 if (SUCCEEDED(hr))
506 hr = SafeArrayAccessData(V_UNION(&var, parray), (LPVOID*)&pData);
508 if (SUCCEEDED(hr))
510 prrf = (struct REG_RF *)pData;
511 pCurrent = pData;
513 if (prrf->dwVersion != 2)
515 FIXME("Filter registry version %ld not supported\n", prrf->dwVersion);
516 ZeroMemory(prf2, sizeof(*prf2));
517 hr = E_FAIL;
521 if (SUCCEEDED(hr))
523 TRACE("version = %ld, merit = %lx, #pins = %ld, unused = %lx\n",
524 prrf->dwVersion, prrf->dwMerit, prrf->dwPins, prrf->dwUnused);
526 prf2->dwVersion = prrf->dwVersion;
527 prf2->dwMerit = prrf->dwMerit;
528 prf2->u.s1.cPins2 = prrf->dwPins;
529 rgPins2 = CoTaskMemAlloc(prrf->dwPins * sizeof(*rgPins2));
530 prf2->u.s1.rgPins2 = rgPins2;
531 pCurrent += sizeof(struct REG_RF);
533 for (i = 0; i < prrf->dwPins; i++)
535 struct REG_RFP * prrfp = (struct REG_RFP *)pCurrent;
536 REGPINTYPES * lpMediaType;
537 REGPINMEDIUM * lpMedium;
538 UINT j;
540 /* FIXME: check signature */
542 TRACE("\tsignature = %s\n", debugstr_an(prrfp->signature, 4));
544 TRACE("\tpin[%ld]: flags = %lx, instances = %ld, media types = %ld, mediums = %ld\n",
545 i, prrfp->dwFlags, prrfp->dwInstances, prrfp->dwMediaTypes, prrfp->dwMediums);
547 rgPins2[i].dwFlags = prrfp->dwFlags;
548 rgPins2[i].cInstances = prrfp->dwInstances;
549 rgPins2[i].nMediaTypes = prrfp->dwMediaTypes;
550 rgPins2[i].nMediums = prrfp->dwMediums;
551 pCurrent += sizeof(struct REG_RFP);
552 if (prrfp->bCategory)
554 CLSID * clsCat = CoTaskMemAlloc(sizeof(CLSID));
555 memcpy(clsCat, pData + *(DWORD*)(pCurrent), sizeof(CLSID));
556 pCurrent += sizeof(DWORD);
557 rgPins2[i].clsPinCategory = clsCat;
559 else
560 rgPins2[i].clsPinCategory = NULL;
562 if (rgPins2[i].nMediaTypes > 0)
563 lpMediaType = CoTaskMemAlloc(rgPins2[i].nMediaTypes * sizeof(*lpMediaType));
564 else
565 lpMediaType = NULL;
567 rgPins2[i].lpMediaType = lpMediaType;
569 for (j = 0; j < rgPins2[i].nMediaTypes; j++)
571 struct REG_TYPE * prt = (struct REG_TYPE *)pCurrent;
572 CLSID * clsMajor = CoTaskMemAlloc(sizeof(CLSID));
573 CLSID * clsMinor = CoTaskMemAlloc(sizeof(CLSID));
575 /* FIXME: check signature */
576 TRACE("\t\tsignature = %s\n", debugstr_an(prt->signature, 4));
578 memcpy(clsMajor, pData + prt->dwOffsetMajor, sizeof(CLSID));
579 memcpy(clsMinor, pData + prt->dwOffsetMinor, sizeof(CLSID));
581 lpMediaType[j].clsMajorType = clsMajor;
582 lpMediaType[j].clsMinorType = clsMinor;
584 pCurrent += sizeof(*prt);
587 if (rgPins2[i].nMediums > 0)
588 lpMedium = CoTaskMemAlloc(rgPins2[i].nMediums * sizeof(*lpMedium));
589 else
590 lpMedium = NULL;
592 rgPins2[i].lpMedium = lpMedium;
594 for (j = 0; j < rgPins2[i].nMediums; j++)
596 DWORD dwOffset = *(DWORD *)pCurrent;
598 memcpy(lpMedium + j, pData + dwOffset, sizeof(REGPINMEDIUM));
600 pCurrent += sizeof(dwOffset);
606 if (pData)
607 SafeArrayUnaccessData(V_UNION(&var, parray));
609 VariantClear(&var);
611 return hr;
614 static void FM2_DeleteRegFilter(REGFILTER2 * prf2)
616 UINT i;
617 for (i = 0; i < prf2->u.s1.cPins2; i++)
619 UINT j;
620 if (prf2->u.s1.rgPins2[i].clsPinCategory)
621 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].clsPinCategory);
623 for (j = 0; j < prf2->u.s1.rgPins2[i].nMediaTypes; j++)
625 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMajorType);
626 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMinorType);
628 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMedium);
632 static HRESULT WINAPI FilterMapper2_RegisterFilter(
633 IFilterMapper2 * iface,
634 REFCLSID clsidFilter,
635 LPCWSTR szName,
636 IMoniker **ppMoniker,
637 const CLSID *pclsidCategory,
638 const OLECHAR *szInstance,
639 const REGFILTER2 *prf2)
641 IParseDisplayName * pParser = NULL;
642 IBindCtx * pBindCtx = NULL;
643 IMoniker * pMoniker = NULL;
644 IPropertyBag * pPropBag = NULL;
645 HRESULT hr;
646 LPWSTR pwszParseName = NULL;
647 LPWSTR pCurrent;
648 static const WCHAR wszDevice[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
649 int nameLen;
650 ULONG ulEaten;
651 LPWSTR szClsidTemp = NULL;
653 TRACE("(%s, %s, %p, %s, %s, %p)\n",
654 debugstr_guid(clsidFilter),
655 debugstr_w(szName),
656 ppMoniker,
657 debugstr_guid(pclsidCategory),
658 debugstr_w(szInstance),
659 prf2);
661 if (prf2->dwVersion != 2)
663 FIXME("dwVersion != 2 not supported at the moment\n");
664 return E_NOTIMPL;
667 if (ppMoniker)
668 *ppMoniker = NULL;
670 if (!pclsidCategory)
671 pclsidCategory = &CLSID_ActiveMovieCategories;
673 /* sizeof... will include null terminator and
674 * the + 1 is for the separator ('\\'). The -1 is
675 * because CHARS_IN_GUID includes the null terminator
677 nameLen = sizeof(wszDevice)/sizeof(wszDevice[0]) + CHARS_IN_GUID - 1 + 1;
679 if (szInstance)
680 nameLen += strlenW(szInstance);
681 else
682 nameLen += CHARS_IN_GUID - 1; /* CHARS_IN_GUID includes null terminator */
684 pCurrent = pwszParseName = CoTaskMemAlloc(nameLen*sizeof(WCHAR));
685 if (!pwszParseName)
686 return E_OUTOFMEMORY;
688 strcpyW(pwszParseName, wszDevice);
689 pCurrent += strlenW(wszDevice);
691 hr = StringFromCLSID(pclsidCategory, &szClsidTemp);
693 if (SUCCEEDED(hr))
695 strncpyW(pCurrent, szClsidTemp, CHARS_IN_GUID);
696 pCurrent += CHARS_IN_GUID - 1;
697 pCurrent[0] = '\\';
699 if (szInstance)
700 strcpyW(pCurrent+1, szInstance);
701 else
703 if (szClsidTemp)
705 CoTaskMemFree(szClsidTemp);
706 szClsidTemp = NULL;
708 hr = StringFromCLSID(clsidFilter, &szClsidTemp);
709 if (SUCCEEDED(hr))
710 strcpyW(pCurrent+1, szClsidTemp);
714 if (SUCCEEDED(hr))
715 hr = CoCreateInstance(&CLSID_CDeviceMoniker, NULL, CLSCTX_INPROC, &IID_IParseDisplayName, (LPVOID *)&pParser);
717 if (SUCCEEDED(hr))
718 hr = CreateBindCtx(0, &pBindCtx);
720 if (SUCCEEDED(hr))
721 hr = IParseDisplayName_ParseDisplayName(pParser, pBindCtx, pwszParseName, &ulEaten, &pMoniker);
723 if (pBindCtx)
724 IBindCtx_Release(pBindCtx); pBindCtx = NULL;
725 if (pParser)
726 IParseDisplayName_Release(pParser); pParser = NULL;
728 if (SUCCEEDED(hr))
729 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID)&pPropBag);
731 if (SUCCEEDED(hr))
732 hr = FM2_WriteFriendlyName(pPropBag, szName);
734 if (SUCCEEDED(hr))
735 hr = FM2_WriteClsid(pPropBag, clsidFilter);
737 if (SUCCEEDED(hr))
738 hr = FM2_WriteFilterData(pPropBag, prf2);
740 if (pPropBag)
741 IPropertyBag_Release(pPropBag); pPropBag = NULL;
742 if (szClsidTemp)
743 CoTaskMemFree(szClsidTemp);
745 if (SUCCEEDED(hr) && ppMoniker)
746 *ppMoniker = pMoniker;
747 else if (pMoniker)
748 IMoniker_Release(pMoniker); pMoniker = NULL;
750 TRACE("-- returning %lx\n", hr);
752 return hr;
755 /* internal helper function */
756 static BOOL MatchTypes(
757 BOOL bExactMatch,
758 DWORD nPinTypes,
759 const REGPINTYPES * pPinTypes,
760 DWORD nMatchTypes,
761 const GUID * pMatchTypes)
763 BOOL bMatch = FALSE;
764 DWORD j;
766 if ((nMatchTypes == 0) && (nPinTypes > 0))
767 bMatch = TRUE;
769 for (j = 0; j < nPinTypes; j++)
771 DWORD i;
772 for (i = 0; i < nMatchTypes*2; i+=2)
774 if (((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMajorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMajorType, &pMatchTypes[i])) &&
775 ((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMinorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i+1], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMinorType, &pMatchTypes[i+1])))
777 bMatch = TRUE;
778 break;
782 return bMatch;
785 /* internal helper function for qsort of MONIKER_MERIT array */
786 static int mm_compare(const void * left, const void * right)
788 const struct MONIKER_MERIT * mmLeft = (struct MONIKER_MERIT *)left;
789 const struct MONIKER_MERIT * mmRight = (struct MONIKER_MERIT *)right;
791 if (mmLeft->dwMerit == mmRight->dwMerit)
792 return 0;
793 if (mmLeft->dwMerit > mmRight->dwMerit)
794 return -1;
795 return 1;
798 /* NOTES:
799 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
800 * (GUID_NULL's in input to function automatically treated as wild cards)
801 * Input/Output needed means match only on criteria if TRUE (with zero input types
802 * meaning match any input/output pin as long as one exists), otherwise match any
803 * filter that meets the rest of the requirements.
805 static HRESULT WINAPI FilterMapper2_EnumMatchingFilters(
806 IFilterMapper2 * iface,
807 IEnumMoniker **ppEnum,
808 DWORD dwFlags,
809 BOOL bExactMatch,
810 DWORD dwMerit,
811 BOOL bInputNeeded,
812 DWORD cInputTypes,
813 const GUID *pInputTypes,
814 const REGPINMEDIUM *pMedIn,
815 const CLSID *pPinCategoryIn,
816 BOOL bRender,
817 BOOL bOutputNeeded,
818 DWORD cOutputTypes,
819 const GUID *pOutputTypes,
820 const REGPINMEDIUM *pMedOut,
821 const CLSID *pPinCategoryOut)
823 ICreateDevEnum * pCreateDevEnum;
824 IMoniker * pMonikerCat;
825 IEnumMoniker * pEnumCat;
826 HRESULT hr;
827 struct Vector monikers = {NULL, 0, 0};
829 TRACE("(%p, %lx, %s, %lx, %s, %ld, %p, %p, %p, %s, %s, %p, %p, %p)\n",
830 ppEnum,
831 dwFlags,
832 bExactMatch ? "true" : "false",
833 dwMerit,
834 bInputNeeded ? "true" : "false",
835 cInputTypes,
836 pInputTypes,
837 pMedIn,
838 pPinCategoryIn,
839 bRender ? "true" : "false",
840 bOutputNeeded ? "true" : "false",
841 pOutputTypes,
842 pMedOut,
843 pPinCategoryOut);
845 if (dwFlags != 0)
847 FIXME("dwFlags = %lx not implemented\n", dwFlags);
850 *ppEnum = NULL;
852 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, &IID_ICreateDevEnum, (LPVOID*)&pCreateDevEnum);
854 if (SUCCEEDED(hr))
855 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEnumCat, 0);
857 while (IEnumMoniker_Next(pEnumCat, 1, &pMonikerCat, NULL) == S_OK)
859 IPropertyBag * pPropBagCat = NULL;
860 VARIANT var;
861 HRESULT hrSub; /* this is so that one buggy filter
862 doesn't make the whole lot fail */
864 VariantInit(&var);
866 hrSub = IMoniker_BindToStorage(pMonikerCat, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
868 if (SUCCEEDED(hrSub))
869 hrSub = IPropertyBag_Read(pPropBagCat, wszMeritName, &var, NULL);
871 if (SUCCEEDED(hrSub) && (V_UNION(&var, ulVal) >= dwMerit))
873 CLSID clsidCat;
874 IEnumMoniker * pEnum;
875 IMoniker * pMoniker;
877 VariantClear(&var);
879 if (TRACE_ON(quartz))
881 VARIANT temp;
882 V_VT(&temp) = VT_EMPTY;
883 IPropertyBag_Read(pPropBagCat, wszFriendlyName, &temp, NULL);
884 TRACE("Considering category %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
885 VariantClear(&temp);
888 hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
890 if (SUCCEEDED(hrSub))
891 hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsidCat);
893 if (SUCCEEDED(hrSub))
894 hrSub = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
896 if (hrSub == S_OK)
898 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
900 IPropertyBag * pPropBag = NULL;
901 REGFILTER2 rf2;
902 DWORD i;
903 BOOL bInputMatch = !bInputNeeded;
904 BOOL bOutputMatch = !bOutputNeeded;
906 ZeroMemory(&rf2, sizeof(rf2));
908 hrSub = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBag);
910 if (SUCCEEDED(hrSub))
911 hrSub = FM2_ReadFilterData(pPropBag, &rf2);
913 /* Logic used for bInputMatch expression:
914 * There exists some pin such that bInputNeeded implies (pin is an input and
915 * (bRender implies pin has render flag) and major/minor types members of
916 * pInputTypes )
917 * bOutputMatch is similar, but without the "bRender implies ..." part
918 * and substituting variables names containing input for output
921 /* determine whether filter meets requirements */
922 if (SUCCEEDED(hrSub) && (rf2.dwMerit >= dwMerit))
924 for (i = 0; (i < rf2.u.s1.cPins2) && (!bInputMatch || !bOutputMatch); i++)
926 const REGFILTERPINS2 * rfp2 = rf2.u.s1.rgPins2 + i;
928 bInputMatch = bInputMatch || (!(rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
929 (!bRender || (rfp2->dwFlags & REG_PINFLAG_B_RENDERER)) &&
930 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cInputTypes, pInputTypes));
931 bOutputMatch = bOutputMatch || ((rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
932 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cOutputTypes, pOutputTypes));
935 if (bInputMatch && bOutputMatch)
937 struct MONIKER_MERIT mm = {pMoniker, rf2.dwMerit};
938 IMoniker_AddRef(pMoniker);
939 add_data(&monikers, (LPBYTE)&mm, sizeof(mm));
943 FM2_DeleteRegFilter(&rf2);
944 if (pPropBag)
945 IPropertyBag_Release(pPropBag);
946 IMoniker_Release(pMoniker);
948 IEnumMoniker_Release(pEnum);
952 VariantClear(&var);
953 if (pPropBagCat)
954 IPropertyBag_Release(pPropBagCat);
955 IMoniker_Release(pMonikerCat);
958 if (SUCCEEDED(hr))
960 IMoniker ** ppMoniker;
961 int i;
962 ULONG nMonikerCount = monikers.current / sizeof(struct MONIKER_MERIT);
964 /* sort the monikers in descending merit order */
965 qsort(monikers.pData, nMonikerCount,
966 sizeof(struct MONIKER_MERIT),
967 mm_compare);
969 /* construct an IEnumMoniker interface */
970 ppMoniker = CoTaskMemAlloc(nMonikerCount * sizeof(IMoniker *));
971 for (i = 0; i < nMonikerCount; i++)
973 /* no need to AddRef here as already AddRef'd above */
974 ppMoniker[i] = ((struct MONIKER_MERIT *)monikers.pData)[i].pMoniker;
976 hr = EnumMonikerImpl_Create(ppMoniker, nMonikerCount, ppEnum);
977 CoTaskMemFree(ppMoniker);
980 delete_vector(&monikers);
981 IEnumMoniker_Release(pEnumCat);
982 ICreateDevEnum_Release(pCreateDevEnum);
984 return hr;
987 static ICOM_VTABLE(IFilterMapper2) fm2vtbl =
989 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
991 FilterMapper2_QueryInterface,
992 FilterMapper2_AddRef,
993 FilterMapper2_Release,
995 FilterMapper2_CreateCategory,
996 FilterMapper2_UnregisterFilter,
997 FilterMapper2_RegisterFilter,
998 FilterMapper2_EnumMatchingFilters
1001 /*** IUnknown methods ***/
1003 static HRESULT WINAPI FilterMapper_QueryInterface(IFilterMapper * iface, REFIID riid, LPVOID *ppv)
1005 ICOM_THIS_From_IFilterMapper(FilterMapper2Impl, iface);
1007 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
1009 return FilterMapper2_QueryInterface((IFilterMapper2*)&This->lpVtbl, riid, ppv);
1012 static ULONG WINAPI FilterMapper_AddRef(IFilterMapper * iface)
1014 ICOM_THIS_From_IFilterMapper(FilterMapper2Impl, iface);
1016 return FilterMapper2_AddRef((IFilterMapper2*)This);
1019 static ULONG WINAPI FilterMapper_Release(IFilterMapper * iface)
1021 ICOM_THIS_From_IFilterMapper(FilterMapper2Impl, iface);
1023 return FilterMapper2_Release((IFilterMapper2*)This);
1026 /*** IFilterMapper methods ***/
1028 static HRESULT WINAPI FilterMapper_EnumMatchingFilters(
1029 IFilterMapper * iface,
1030 IEnumRegFilters **ppEnum,
1031 DWORD dwMerit,
1032 BOOL bInputNeeded,
1033 CLSID clsInMaj,
1034 CLSID clsInSub,
1035 BOOL bRender,
1036 BOOL bOutputNeeded,
1037 CLSID clsOutMaj,
1038 CLSID clsOutSub)
1040 ICOM_THIS_From_IFilterMapper(FilterMapper2Impl, iface);
1041 GUID InputType[2];
1042 GUID OutputType[2];
1043 IEnumMoniker* ppEnumMoniker;
1044 IMoniker* IMon;
1045 ULONG nb;
1046 ULONG idx = 0, nb_mon = 0;
1047 REGFILTER* regfilters;
1048 HRESULT hr;
1050 TRACE("(%p/%p)->(%p, %lx, %s, %s, %s, %s, %s, %s, %s) stub!\n",
1051 iface,This,
1052 ppEnum,
1053 dwMerit,
1054 bInputNeeded ? "true" : "false",
1055 debugstr_guid(&clsInMaj),
1056 debugstr_guid(&clsInSub),
1057 bRender ? "true" : "false",
1058 bOutputNeeded ? "true" : "false",
1059 debugstr_guid(&clsOutMaj),
1060 debugstr_guid(&clsOutSub));
1062 InputType[0] = clsInMaj;
1063 InputType[1] = clsInSub;
1064 OutputType[0] = clsOutMaj;
1065 OutputType[1] = clsOutSub;
1067 hr = IFilterMapper2_EnumMatchingFilters((IFilterMapper2*)This,
1068 &ppEnumMoniker,
1070 TRUE,
1071 dwMerit,
1072 bInputNeeded,
1074 InputType,
1075 NULL,
1076 &GUID_NULL,
1077 bRender,
1078 bOutputNeeded,
1080 OutputType,
1081 NULL,
1082 &GUID_NULL);
1084 if (!SUCCEEDED(hr))
1085 return hr;
1087 while(IEnumMoniker_Next(ppEnumMoniker, 1, &IMon, &nb) == S_OK)
1089 IMoniker_Release(IMon);
1090 nb_mon++;
1093 *ppEnum = NULL;
1094 if (!nb_mon)
1096 IEnumMoniker_Release(ppEnumMoniker);
1097 return IEnumRegFiltersImpl_Construct(NULL, 0, ppEnum);
1100 regfilters = CoTaskMemAlloc(nb_mon * sizeof(REGFILTER));
1101 if (!regfilters)
1103 IEnumMoniker_Release(ppEnumMoniker);
1104 return E_OUTOFMEMORY;
1107 IEnumMoniker_Reset(ppEnumMoniker);
1108 while(IEnumMoniker_Next(ppEnumMoniker, 1, &IMon, &nb) == S_OK)
1110 IPropertyBag * pPropBagCat = NULL;
1111 VARIANT var;
1112 HRESULT hrSub;
1113 GUID clsid;
1114 int len;
1116 VariantInit(&var);
1117 V_VT(&var) = VT_BSTR;
1119 hrSub = IMoniker_BindToStorage(IMon, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
1121 if (SUCCEEDED(hrSub))
1122 hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
1124 if (SUCCEEDED(hrSub))
1125 hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsid);
1127 if (SUCCEEDED(hrSub))
1128 hrSub = IPropertyBag_Read(pPropBagCat, wszFriendlyName, &var, NULL);
1130 if (SUCCEEDED(hrSub))
1132 len = (strlenW((WCHAR*)&V_UNION(&var, bstrVal))+1) * sizeof(WCHAR);
1133 if (!(regfilters[idx].Name = CoTaskMemAlloc(len*2)))
1134 hr = E_OUTOFMEMORY;
1137 if (SUCCEEDED(hrSub))
1139 memcpy(regfilters[idx].Name, &V_UNION(&var, bstrVal), len);
1140 regfilters[idx].Clsid = clsid;
1141 idx++;
1144 if (pPropBagCat)
1145 IPropertyBag_Release(pPropBagCat);
1146 IMoniker_Release(IMon);
1149 /* In case of release all resources */
1150 if (!SUCCEEDED(hr))
1152 for (idx = 0; idx < nb_mon; idx++)
1153 CoTaskMemFree(regfilters[idx].Name);
1154 CoTaskMemFree(regfilters);
1155 IEnumMoniker_Release(ppEnumMoniker);
1156 return hr;
1159 hr = IEnumRegFiltersImpl_Construct(regfilters, nb_mon, ppEnum);
1160 CoTaskMemFree(regfilters);
1161 IEnumMoniker_Release(ppEnumMoniker);
1163 return hr;
1167 static HRESULT WINAPI FilterMapper_RegisterFilter(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, DWORD dwMerit)
1169 HRESULT hr;
1170 LPWSTR wszClsid = NULL;
1171 HKEY hKey;
1172 WCHAR wszKeyName[strlenW(wszFilterSlash) + (CHARS_IN_GUID-1) + 1];
1174 TRACE("(%p)->(%s, %s, %lx)\n", iface, debugstr_guid(&clsid), debugstr_w(szName), dwMerit);
1176 hr = StringFromCLSID(&clsid, &wszClsid);
1178 if (SUCCEEDED(hr))
1180 strcpyW(wszKeyName, wszFilterSlash);
1181 strcatW(wszKeyName, wszClsid);
1183 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL));
1186 if (SUCCEEDED(hr))
1188 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, NULL, 0, REG_SZ, (LPBYTE)szName, strlenW(szName) + 1));
1189 CloseHandle(hKey);
1192 if (SUCCEEDED(hr))
1194 strcpyW(wszKeyName, wszClsidSlash);
1195 strcatW(wszKeyName, wszClsid);
1197 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL));
1200 if (SUCCEEDED(hr))
1202 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwMerit, sizeof(dwMerit)));
1203 CloseHandle(hKey);
1206 return hr;
1209 static HRESULT WINAPI FilterMapper_RegisterFilterInstance(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, CLSID *MRId)
1211 TRACE("(%p)->(%s, %s, %p)\n", iface, debugstr_guid(&clsid), debugstr_w(szName), MRId);
1213 /* Not implemented in Windows (tested on Win2k) */
1215 return E_NOTIMPL;
1218 static HRESULT WINAPI FilterMapper_RegisterPin(
1219 IFilterMapper * iface,
1220 CLSID Filter,
1221 LPCWSTR szName,
1222 BOOL bRendered,
1223 BOOL bOutput,
1224 BOOL bZero,
1225 BOOL bMany,
1226 CLSID ConnectsToFilter,
1227 LPCWSTR ConnectsToPin)
1229 HRESULT hr;
1230 LPWSTR wszClsid = NULL;
1231 HKEY hKey = NULL;
1232 HKEY hPinsKey = NULL;
1233 WCHAR * wszPinsKeyName;
1234 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1236 TRACE("(%p)->(%s, %s, %d, %d, %d, %d, %s, %s)\n", iface, debugstr_guid(&Filter), debugstr_w(szName), bRendered,
1237 bOutput, bZero, bMany, debugstr_guid(&ConnectsToFilter), debugstr_w(ConnectsToPin));
1239 hr = StringFromCLSID(&Filter, &wszClsid);
1241 if (SUCCEEDED(hr))
1243 strcpyW(wszKeyName, wszClsidSlash);
1244 strcatW(wszKeyName, wszClsid);
1246 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey));
1249 if (SUCCEEDED(hr))
1251 wszPinsKeyName = CoTaskMemAlloc((strlenW(wszPins) + 1 + strlenW(szName) + 1) * 2);
1252 if (!wszPinsKeyName)
1253 hr = E_OUTOFMEMORY;
1256 if (SUCCEEDED(hr))
1258 strcpyW(wszPinsKeyName, wszPins);
1259 strcatW(wszPinsKeyName, wszSlash);
1260 strcatW(wszPinsKeyName, szName);
1262 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(hKey, wszPinsKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hPinsKey, NULL));
1263 CoTaskMemFree(wszPinsKeyName);
1266 if (SUCCEEDED(hr))
1268 hr = HRESULT_FROM_WIN32(RegSetValueExW(hPinsKey, wszAllowedMany, 0, REG_DWORD, (LPBYTE)&bMany, sizeof(bMany)));
1271 if (SUCCEEDED(hr))
1273 hr = HRESULT_FROM_WIN32(RegSetValueExW(hPinsKey, wszAllowedZero, 0, REG_DWORD, (LPBYTE)&bZero, sizeof(bZero)));
1276 if (SUCCEEDED(hr))
1278 hr = HRESULT_FROM_WIN32(RegSetValueExW(hPinsKey, wszDirection, 0, REG_DWORD, (LPBYTE)&bOutput, sizeof(bOutput)));
1281 if (SUCCEEDED(hr))
1283 hr = HRESULT_FROM_WIN32(RegSetValueExW(hPinsKey, wszIsRendered, 0, REG_DWORD, (LPBYTE)&bRendered, sizeof(bRendered)));
1286 if (SUCCEEDED(hr))
1288 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(hPinsKey, wszTypes, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL, NULL));
1291 if (wszClsid)
1292 CoTaskMemFree(wszClsid);
1293 if (hKey)
1294 CloseHandle(hKey);
1295 if (hPinsKey)
1296 CloseHandle(hPinsKey);
1298 return hr;
1302 static HRESULT WINAPI FilterMapper_RegisterPinType(
1303 IFilterMapper * iface,
1304 CLSID clsFilter,
1305 LPCWSTR szName,
1306 CLSID clsMajorType,
1307 CLSID clsSubType)
1309 HRESULT hr;
1310 LPWSTR wszClsid = NULL;
1311 LPWSTR wszClsidMajorType = NULL;
1312 LPWSTR wszClsidSubType = NULL;
1313 HKEY hKey = NULL;
1314 WCHAR * wszTypesKey;
1315 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1317 TRACE("(%p)->(%s, %s, %s, %s)\n", iface, debugstr_guid(&clsFilter), debugstr_w(szName),
1318 debugstr_guid(&clsMajorType), debugstr_guid(&clsSubType));
1320 hr = StringFromCLSID(&clsFilter, &wszClsid);
1322 if (SUCCEEDED(hr))
1324 hr = StringFromCLSID(&clsMajorType, &wszClsidMajorType);
1327 if (SUCCEEDED(hr))
1329 hr = StringFromCLSID(&clsSubType, &wszClsidSubType);
1332 if (SUCCEEDED(hr))
1334 wszTypesKey = CoTaskMemAlloc((strlenW(wszClsidSlash) + strlenW(wszClsid) + strlenW(wszPins) +
1335 strlenW(szName) + strlenW(wszTypes) + 3 + 1) * 2);
1336 if (!wszTypesKey)
1337 hr = E_OUTOFMEMORY;
1340 if (SUCCEEDED(hr))
1342 strcpyW(wszTypesKey, wszClsidSlash);
1343 strcatW(wszTypesKey, wszClsid);
1344 strcatW(wszTypesKey, wszSlash);
1345 strcatW(wszTypesKey, wszPins);
1346 strcatW(wszTypesKey, wszSlash);
1347 strcatW(wszTypesKey, szName);
1348 strcatW(wszTypesKey, wszSlash);
1349 strcatW(wszTypesKey, wszTypes);
1351 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_CLASSES_ROOT, wszTypesKey, 0, KEY_WRITE, &hKey));
1352 CoTaskMemFree(wszTypesKey);
1355 if (SUCCEEDED(hr))
1357 strcpyW(wszKeyName, wszClsidMajorType);
1358 strcatW(wszKeyName, wszSlash);
1359 strcatW(wszKeyName, wszClsidSubType);
1361 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(hKey, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL, NULL));
1362 CloseHandle(hKey);
1365 if (wszClsid)
1366 CoTaskMemFree(wszClsid);
1367 if (wszClsidMajorType)
1368 CoTaskMemFree(wszClsidMajorType);
1369 if (wszClsidSubType)
1370 CoTaskMemFree(wszClsidSubType);
1372 return hr;
1375 static HRESULT WINAPI FilterMapper_UnregisterFilter(IFilterMapper * iface, CLSID Filter)
1377 HRESULT hr;
1378 LPWSTR wszClsid = NULL;
1379 HKEY hKey;
1380 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1382 TRACE("(%p)->(%s)\n", iface, debugstr_guid(&Filter));
1384 hr = StringFromCLSID(&Filter, &wszClsid);
1386 if (SUCCEEDED(hr))
1388 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_CLASSES_ROOT, wszFilter, 0, KEY_WRITE, &hKey));
1391 if (SUCCEEDED(hr))
1393 hr = HRESULT_FROM_WIN32(RegDeleteKeyW(hKey, wszClsid));
1394 CloseHandle(hKey);
1397 if (SUCCEEDED(hr))
1399 strcpyW(wszKeyName, wszClsidSlash);
1400 strcatW(wszKeyName, wszClsid);
1402 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey));
1405 if (SUCCEEDED(hr))
1407 hr = HRESULT_FROM_WIN32(RegDeleteKeyW(hKey, wszMeritName));
1408 CloseHandle(hKey);
1411 if (wszClsid)
1412 CoTaskMemFree(wszClsid);
1414 return hr;
1417 static HRESULT WINAPI FilterMapper_UnregisterFilterInstance(IFilterMapper * iface, CLSID MRId)
1419 TRACE("(%p)->(%s)\n", iface, debugstr_guid(&MRId));
1421 /* Not implemented in Windows (tested on Win2k) */
1423 return E_NOTIMPL;
1426 static HRESULT WINAPI FilterMapper_UnregisterPin(IFilterMapper * iface, CLSID Filter, LPCWSTR Name)
1428 HRESULT hr;
1429 LPWSTR wszClsid = NULL;
1430 HKEY hKey = NULL;
1431 WCHAR * wszPinNameKey;
1432 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1434 TRACE("(%p)->(%s, %s)\n", iface, debugstr_guid(&Filter), debugstr_w(Name));
1436 if (!Name)
1437 return E_INVALIDARG;
1439 hr = StringFromCLSID(&Filter, &wszClsid);
1441 if (SUCCEEDED(hr))
1443 strcpyW(wszKeyName, wszClsidSlash);
1444 strcatW(wszKeyName, wszClsid);
1446 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey));
1449 if (SUCCEEDED(hr))
1451 wszPinNameKey = CoTaskMemAlloc((strlenW(wszPins) + 1 + strlenW(Name) + 1) * 2);
1452 if (!wszPinNameKey)
1453 hr = E_OUTOFMEMORY;
1456 if (SUCCEEDED(hr))
1458 strcpyW(wszPinNameKey, wszPins);
1459 strcatW(wszPinNameKey, wszSlash);
1460 strcatW(wszPinNameKey, Name);
1462 hr = HRESULT_FROM_WIN32(RegDeleteKeyW(hKey, wszPinNameKey));
1463 CoTaskMemFree(wszPinNameKey);
1466 if (wszClsid)
1467 CoTaskMemFree(wszClsid);
1468 if (hKey)
1469 CloseHandle(hKey);
1471 return hr;
1474 static ICOM_VTABLE(IFilterMapper) fmvtbl =
1476 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1478 FilterMapper_QueryInterface,
1479 FilterMapper_AddRef,
1480 FilterMapper_Release,
1482 FilterMapper_RegisterFilter,
1483 FilterMapper_RegisterFilterInstance,
1484 FilterMapper_RegisterPin,
1485 FilterMapper_RegisterPinType,
1486 FilterMapper_UnregisterFilter,
1487 FilterMapper_UnregisterFilterInstance,
1488 FilterMapper_UnregisterPin,
1489 FilterMapper_EnumMatchingFilters