2 * IFilterMapper & IFilterMapper3 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
32 #include "quartz_private.h"
37 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
44 #define ARRAYSIZE(array) (sizeof(array)/sizeof((array)[0]))
46 /* Unexposed IAMFilterData interface */
47 typedef struct IAMFilterData IAMFilterData;
49 typedef struct IAMFilterDataVtbl
53 /*** IUnknown methods ***/
54 HRESULT (STDMETHODCALLTYPE *QueryInterface)(
59 ULONG (STDMETHODCALLTYPE *AddRef)(
62 ULONG (STDMETHODCALLTYPE *Release)(
65 /*** IAMFilterData methods ***/
66 HRESULT (STDMETHODCALLTYPE *ParseFilterData)(
72 HRESULT (STDMETHODCALLTYPE *CreateFilterData)(
75 BYTE **pRegFilterData,
82 const IAMFilterDataVtbl *lpVtbl;
84 static const GUID IID_IAMFilterData = {
85 0x97f7c4d4, 0x547b, 0x4a5f, { 0x83,0x32, 0x53,0x64,0x30,0xad,0x2e,0x4d }
89 typedef struct FilterMapper3Impl
91 IFilterMapper3 IFilterMapper3_iface;
92 IFilterMapper IFilterMapper_iface;
93 IAMFilterData IAMFilterData_iface;
94 const IUnknownVtbl *IInner_vtbl;
101 static const IUnknownVtbl IInner_VTable;
102 static const IFilterMapper3Vtbl fm3vtbl;
103 static const IFilterMapperVtbl fmvtbl;
104 static const IAMFilterDataVtbl AMFilterDataVtbl;
106 static inline FilterMapper3Impl *impl_from_IFilterMapper3( IFilterMapper3 *iface )
108 return CONTAINING_RECORD(iface, FilterMapper3Impl, IFilterMapper3_iface);
111 static inline FilterMapper3Impl *impl_from_IFilterMapper( IFilterMapper *iface )
113 return CONTAINING_RECORD(iface, FilterMapper3Impl, IFilterMapper_iface);
116 static inline FilterMapper3Impl *impl_from_IAMFilterData( IAMFilterData *iface )
118 return CONTAINING_RECORD(iface, FilterMapper3Impl, IAMFilterData_iface);
121 static inline FilterMapper3Impl *impl_from_inner_IUnknown( IUnknown *iface )
123 return (FilterMapper3Impl *)((char*)iface - FIELD_OFFSET(FilterMapper3Impl, IInner_vtbl));
126 static const WCHAR wszClsidSlash[] = {'C','L','S','I','D','\\',0};
127 static const WCHAR wszSlashInstance[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
128 static const WCHAR wszSlash[] = {'\\',0};
130 /* CLSID property in media category Moniker */
131 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
132 /* FriendlyName property in media category Moniker */
133 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
134 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
135 static const WCHAR wszMeritName[] = {'M','e','r','i','t',0};
136 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
137 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
138 /* For filters registered with IFilterMapper */
139 static const WCHAR wszFilterSlash[] = {'F','i','l','t','e','r','\\',0};
140 static const WCHAR wszFilter[] = {'F','i','l','t','e','r',0};
141 /* For pins registered with IFilterMapper */
142 static const WCHAR wszPins[] = {'P','i','n','s',0};
143 static const WCHAR wszAllowedMany[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
144 static const WCHAR wszAllowedZero[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
145 static const WCHAR wszDirection[] = {'D','i','r','e','c','t','i','o','n',0};
146 static const WCHAR wszIsRendered[] = {'I','s','R','e','n','d','e','r','e','d',0};
147 /* For types registered with IFilterMapper */
148 static const WCHAR wszTypes[] = {'T','y','p','e','s',0};
151 /* registry format for REGFILTER2 */
162 BYTE signature[4]; /* e.g. "0pi3" */
167 DWORD bCategory; /* is there a category clsid? */
168 /* optional: dwOffsetCategoryClsid */
173 BYTE signature[4]; /* e.g. "0ty3" */
188 int capacity; /* in bytes */
189 int current; /* pointer to next free byte */
192 /* returns the position it was added at */
193 static int add_data(struct Vector * v, const BYTE * pData, int size)
195 int index = v->current;
196 if (v->current + size > v->capacity)
198 LPBYTE pOldData = v->pData;
199 v->capacity = (v->capacity + size) * 2;
200 v->pData = CoTaskMemAlloc(v->capacity);
201 memcpy(v->pData, pOldData, v->current);
202 CoTaskMemFree(pOldData);
204 memcpy(v->pData + v->current, pData, size);
209 static int find_data(const struct Vector * v, const BYTE * pData, int size)
212 for (index = 0; index < v->current; index++)
213 if (!memcmp(v->pData + index, pData, size))
219 static void delete_vector(struct Vector * v)
221 CoTaskMemFree(v->pData);
226 HRESULT FilterMapper2_create(IUnknown *pUnkOuter, LPVOID *ppObj)
228 FilterMapper3Impl * pFM2impl;
230 TRACE("(%p, %p)\n", pUnkOuter, ppObj);
232 pFM2impl = CoTaskMemAlloc(sizeof(*pFM2impl));
234 return E_OUTOFMEMORY;
236 pFM2impl->pUnkOuter = pUnkOuter;
237 pFM2impl->bUnkOuterValid = FALSE;
238 pFM2impl->bAggregatable = FALSE;
239 pFM2impl->IInner_vtbl = &IInner_VTable;
240 pFM2impl->IFilterMapper3_iface.lpVtbl = &fm3vtbl;
241 pFM2impl->IFilterMapper_iface.lpVtbl = &fmvtbl;
242 pFM2impl->IAMFilterData_iface.lpVtbl = &AMFilterDataVtbl;
243 pFM2impl->refCount = 1;
247 TRACE("-- created at %p\n", pFM2impl);
252 HRESULT FilterMapper_create(IUnknown *pUnkOuter, LPVOID *ppObj)
254 FilterMapper3Impl *pFM2impl;
257 TRACE("(%p, %p)\n", pUnkOuter, ppObj);
259 hr = FilterMapper2_create(pUnkOuter, (LPVOID*)&pFM2impl);
263 *ppObj = &pFM2impl->IFilterMapper_iface;
268 /*** IUnknown (inner) methods ***/
270 static HRESULT WINAPI Inner_QueryInterface(IUnknown * iface, REFIID riid, LPVOID * ppv)
272 FilterMapper3Impl *This = impl_from_inner_IUnknown(iface);
273 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
275 if (This->bAggregatable)
276 This->bUnkOuterValid = TRUE;
280 if (IsEqualIID(riid, &IID_IUnknown))
281 *ppv = &This->IInner_vtbl;
282 else if (IsEqualIID(riid, &IID_IFilterMapper2) ||
283 IsEqualIID(riid, &IID_IFilterMapper3))
285 else if (IsEqualIID(riid, &IID_IFilterMapper))
286 *ppv = &This->IFilterMapper_iface;
287 else if (IsEqualIID(riid, &IID_IAMFilterData))
288 *ppv = &This->IAMFilterData_iface;
292 IUnknown_AddRef((IUnknown *)*ppv);
296 FIXME("No interface for %s\n", debugstr_guid(riid));
297 return E_NOINTERFACE;
300 static ULONG WINAPI Inner_AddRef(IUnknown * iface)
302 FilterMapper3Impl *This = impl_from_inner_IUnknown(iface);
303 ULONG refCount = InterlockedIncrement(&This->refCount);
305 TRACE("(%p)->() AddRef from %d\n", This, refCount - 1);
310 static ULONG WINAPI Inner_Release(IUnknown * iface)
312 FilterMapper3Impl *This = impl_from_inner_IUnknown(iface);
313 ULONG refCount = InterlockedDecrement(&This->refCount);
315 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
325 static const IUnknownVtbl IInner_VTable =
327 Inner_QueryInterface,
332 static HRESULT WINAPI FilterMapper3_QueryInterface(IFilterMapper3 * iface, REFIID riid, LPVOID *ppv)
334 FilterMapper3Impl *This = impl_from_IFilterMapper3(iface);
336 if (This->bAggregatable)
337 This->bUnkOuterValid = TRUE;
341 if (This->bAggregatable)
342 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
344 if (IsEqualIID(riid, &IID_IUnknown))
348 IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
349 hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
350 IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
351 This->bAggregatable = TRUE;
356 return E_NOINTERFACE;
359 return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
362 static ULONG WINAPI FilterMapper3_AddRef(IFilterMapper3 * iface)
364 FilterMapper3Impl *This = impl_from_IFilterMapper3(iface);
366 if (This->pUnkOuter && This->bUnkOuterValid)
367 return IUnknown_AddRef(This->pUnkOuter);
368 return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
371 static ULONG WINAPI FilterMapper3_Release(IFilterMapper3 * iface)
373 FilterMapper3Impl *This = impl_from_IFilterMapper3(iface);
375 if (This->pUnkOuter && This->bUnkOuterValid)
376 return IUnknown_Release(This->pUnkOuter);
377 return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
380 /*** IFilterMapper3 methods ***/
382 static HRESULT WINAPI FilterMapper3_CreateCategory(
383 IFilterMapper3 * iface,
384 REFCLSID clsidCategory,
385 DWORD dwCategoryMerit,
386 LPCWSTR szDescription)
388 LPWSTR wClsidAMCat = NULL;
389 LPWSTR wClsidCategory = NULL;
390 WCHAR wszKeyName[ARRAYSIZE(wszClsidSlash)-1 + ARRAYSIZE(wszSlashInstance)-1 + (CHARS_IN_GUID-1) * 2 + 1];
395 TRACE("(%s, %x, %s)\n", debugstr_guid(clsidCategory), dwCategoryMerit, debugstr_w(szDescription));
397 hr = StringFromCLSID(&CLSID_ActiveMovieCategories, &wClsidAMCat);
401 hr = StringFromCLSID(clsidCategory, &wClsidCategory);
406 strcpyW(wszKeyName, wszClsidSlash);
407 strcatW(wszKeyName, wClsidAMCat);
408 strcatW(wszKeyName, wszSlashInstance);
409 strcatW(wszKeyName, wClsidCategory);
411 lRet = RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
412 hr = HRESULT_FROM_WIN32(lRet);
417 lRet = RegSetValueExW(hKey, wszFriendlyName, 0, REG_SZ, (const BYTE*)szDescription, (strlenW(szDescription) + 1) * sizeof(WCHAR));
418 hr = HRESULT_FROM_WIN32(lRet);
423 lRet = RegSetValueExW(hKey, wszClsidName, 0, REG_SZ, (LPBYTE)wClsidCategory, (strlenW(wClsidCategory) + 1) * sizeof(WCHAR));
424 hr = HRESULT_FROM_WIN32(lRet);
429 lRet = RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwCategoryMerit, sizeof(dwCategoryMerit));
430 hr = HRESULT_FROM_WIN32(lRet);
434 CoTaskMemFree(wClsidCategory);
435 CoTaskMemFree(wClsidAMCat);
440 static HRESULT WINAPI FilterMapper3_UnregisterFilter(
441 IFilterMapper3 * iface,
442 const CLSID *pclsidCategory,
443 const OLECHAR *szInstance,
446 WCHAR wszKeyName[MAX_PATH];
447 LPWSTR wClsidCategory = NULL;
448 LPWSTR wFilter = NULL;
451 TRACE("(%p, %s, %s)\n", pclsidCategory, debugstr_w(szInstance), debugstr_guid(Filter));
454 pclsidCategory = &CLSID_LegacyAmFilterCategory;
456 hr = StringFromCLSID(pclsidCategory, &wClsidCategory);
460 strcpyW(wszKeyName, wszClsidSlash);
461 strcatW(wszKeyName, wClsidCategory);
462 strcatW(wszKeyName, wszSlashInstance);
464 strcatW(wszKeyName, szInstance);
467 hr = StringFromCLSID(Filter, &wFilter);
469 strcatW(wszKeyName, wFilter);
475 LONG lRet = RegDeleteKeyW(HKEY_CLASSES_ROOT, wszKeyName);
476 hr = HRESULT_FROM_WIN32(lRet);
479 CoTaskMemFree(wClsidCategory);
480 CoTaskMemFree(wFilter);
485 static HRESULT FM2_WriteFriendlyName(IPropertyBag * pPropBag, LPCWSTR szName)
491 V_VT(&var) = VT_BSTR;
492 V_UNION(&var, bstrVal) = value = SysAllocString(szName);
494 ret = IPropertyBag_Write(pPropBag, wszFriendlyName, &var);
495 SysFreeString(value);
500 static HRESULT FM2_WriteClsid(IPropertyBag * pPropBag, REFCLSID clsid)
502 LPWSTR wszClsid = NULL;
506 hr = StringFromCLSID(clsid, &wszClsid);
510 V_VT(&var) = VT_BSTR;
511 V_UNION(&var, bstrVal) = wszClsid;
512 hr = IPropertyBag_Write(pPropBag, wszClsidName, &var);
514 CoTaskMemFree(wszClsid);
518 static HRESULT FM2_WriteFilterData(const REGFILTER2 * prf2, BYTE **ppData, ULONG *pcbData)
520 int size = sizeof(struct REG_RF);
522 struct Vector mainStore = {NULL, 0, 0};
523 struct Vector clsidStore = {NULL, 0, 0};
527 rrf.dwVersion = prf2->dwVersion;
528 rrf.dwMerit = prf2->dwMerit;
529 rrf.dwPins = prf2->u.s1.cPins2;
532 add_data(&mainStore, (LPBYTE)&rrf, sizeof(rrf));
534 for (i = 0; i < prf2->u.s1.cPins2; i++)
536 size += sizeof(struct REG_RFP);
537 if (prf2->u.s1.rgPins2[i].clsPinCategory)
538 size += sizeof(DWORD);
539 size += prf2->u.s1.rgPins2[i].nMediaTypes * sizeof(struct REG_TYPE);
540 size += prf2->u.s1.rgPins2[i].nMediums * sizeof(DWORD);
543 for (i = 0; i < prf2->u.s1.cPins2; i++)
546 REGFILTERPINS2 rgPin2 = prf2->u.s1.rgPins2[i];
549 rrfp.signature[0] = '0';
550 rrfp.signature[1] = 'p';
551 rrfp.signature[2] = 'i';
552 rrfp.signature[3] = '3';
553 rrfp.signature[0] += i;
554 rrfp.dwFlags = rgPin2.dwFlags;
555 rrfp.dwInstances = rgPin2.cInstances;
556 rrfp.dwMediaTypes = rgPin2.nMediaTypes;
557 rrfp.dwMediums = rgPin2.nMediums;
558 rrfp.bCategory = rgPin2.clsPinCategory ? 1 : 0;
560 add_data(&mainStore, (LPBYTE)&rrfp, sizeof(rrfp));
563 DWORD index = find_data(&clsidStore, (const BYTE*)rgPin2.clsPinCategory, sizeof(CLSID));
565 index = add_data(&clsidStore, (const BYTE*)rgPin2.clsPinCategory, sizeof(CLSID));
568 add_data(&mainStore, (LPBYTE)&index, sizeof(index));
571 for (j = 0; j < rgPin2.nMediaTypes; j++)
574 const CLSID * clsMinorType = rgPin2.lpMediaType[j].clsMinorType ? rgPin2.lpMediaType[j].clsMinorType : &MEDIASUBTYPE_NULL;
575 rt.signature[0] = '0';
576 rt.signature[1] = 't';
577 rt.signature[2] = 'y';
578 rt.signature[3] = '3';
579 rt.signature[0] += j;
581 rt.dwOffsetMajor = find_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
582 if (rt.dwOffsetMajor == -1)
583 rt.dwOffsetMajor = add_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
584 rt.dwOffsetMajor += size;
585 rt.dwOffsetMinor = find_data(&clsidStore, (const BYTE*)clsMinorType, sizeof(CLSID));
586 if (rt.dwOffsetMinor == -1)
587 rt.dwOffsetMinor = add_data(&clsidStore, (const BYTE*)clsMinorType, sizeof(CLSID));
588 rt.dwOffsetMinor += size;
590 add_data(&mainStore, (LPBYTE)&rt, sizeof(rt));
593 for (j = 0; j < rgPin2.nMediums; j++)
595 DWORD index = find_data(&clsidStore, (const BYTE*)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
597 index = add_data(&clsidStore, (const BYTE*)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
600 add_data(&mainStore, (LPBYTE)&index, sizeof(index));
606 *pcbData = mainStore.current + clsidStore.current;
607 *ppData = CoTaskMemAlloc(*pcbData);
614 memcpy(*ppData, mainStore.pData, mainStore.current);
615 memcpy((*ppData) + mainStore.current, clsidStore.pData, clsidStore.current);
618 delete_vector(&mainStore);
619 delete_vector(&clsidStore);
623 static HRESULT FM2_ReadFilterData(BYTE *pData, REGFILTER2 * prf2)
626 struct REG_RF * prrf;
629 REGFILTERPINS2 * rgPins2;
631 prrf = (struct REG_RF *)pData;
634 if (prrf->dwVersion != 2)
636 FIXME("Filter registry version %d not supported\n", prrf->dwVersion);
637 ZeroMemory(prf2, sizeof(*prf2));
643 TRACE("version = %d, merit = %x, #pins = %d, unused = %x\n",
644 prrf->dwVersion, prrf->dwMerit, prrf->dwPins, prrf->dwUnused);
646 prf2->dwVersion = prrf->dwVersion;
647 prf2->dwMerit = prrf->dwMerit;
648 prf2->u.s1.cPins2 = prrf->dwPins;
649 rgPins2 = CoTaskMemAlloc(prrf->dwPins * sizeof(*rgPins2));
650 prf2->u.s1.rgPins2 = rgPins2;
651 pCurrent += sizeof(struct REG_RF);
653 for (i = 0; i < prrf->dwPins; i++)
655 struct REG_RFP * prrfp = (struct REG_RFP *)pCurrent;
656 REGPINTYPES * lpMediaType;
657 REGPINMEDIUM * lpMedium;
660 /* FIXME: check signature */
662 TRACE("\tsignature = %s\n", debugstr_an((const char*)prrfp->signature, 4));
664 TRACE("\tpin[%d]: flags = %x, instances = %d, media types = %d, mediums = %d\n",
665 i, prrfp->dwFlags, prrfp->dwInstances, prrfp->dwMediaTypes, prrfp->dwMediums);
667 rgPins2[i].dwFlags = prrfp->dwFlags;
668 rgPins2[i].cInstances = prrfp->dwInstances;
669 rgPins2[i].nMediaTypes = prrfp->dwMediaTypes;
670 rgPins2[i].nMediums = prrfp->dwMediums;
671 pCurrent += sizeof(struct REG_RFP);
672 if (prrfp->bCategory)
674 CLSID * clsCat = CoTaskMemAlloc(sizeof(CLSID));
675 memcpy(clsCat, pData + *(DWORD*)(pCurrent), sizeof(CLSID));
676 pCurrent += sizeof(DWORD);
677 rgPins2[i].clsPinCategory = clsCat;
680 rgPins2[i].clsPinCategory = NULL;
682 if (rgPins2[i].nMediaTypes > 0)
683 lpMediaType = CoTaskMemAlloc(rgPins2[i].nMediaTypes * sizeof(*lpMediaType));
687 rgPins2[i].lpMediaType = lpMediaType;
689 for (j = 0; j < rgPins2[i].nMediaTypes; j++)
691 struct REG_TYPE * prt = (struct REG_TYPE *)pCurrent;
692 CLSID * clsMajor = CoTaskMemAlloc(sizeof(CLSID));
693 CLSID * clsMinor = CoTaskMemAlloc(sizeof(CLSID));
695 /* FIXME: check signature */
696 TRACE("\t\tsignature = %s\n", debugstr_an((const char*)prt->signature, 4));
698 memcpy(clsMajor, pData + prt->dwOffsetMajor, sizeof(CLSID));
699 memcpy(clsMinor, pData + prt->dwOffsetMinor, sizeof(CLSID));
701 lpMediaType[j].clsMajorType = clsMajor;
702 lpMediaType[j].clsMinorType = clsMinor;
704 pCurrent += sizeof(*prt);
707 if (rgPins2[i].nMediums > 0)
708 lpMedium = CoTaskMemAlloc(rgPins2[i].nMediums * sizeof(*lpMedium));
712 rgPins2[i].lpMedium = lpMedium;
714 for (j = 0; j < rgPins2[i].nMediums; j++)
716 DWORD dwOffset = *(DWORD *)pCurrent;
718 memcpy(lpMedium + j, pData + dwOffset, sizeof(REGPINMEDIUM));
720 pCurrent += sizeof(dwOffset);
729 static void FM2_DeleteRegFilter(REGFILTER2 * prf2)
732 for (i = 0; i < prf2->u.s1.cPins2; i++)
735 if (prf2->u.s1.rgPins2[i].clsPinCategory)
736 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].clsPinCategory);
738 for (j = 0; j < prf2->u.s1.rgPins2[i].nMediaTypes; j++)
740 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMajorType);
741 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMinorType);
743 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType);
744 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMedium);
746 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2);
749 static HRESULT WINAPI FilterMapper3_RegisterFilter(
750 IFilterMapper3 * iface,
751 REFCLSID clsidFilter,
753 IMoniker **ppMoniker,
754 const CLSID *pclsidCategory,
755 const OLECHAR *szInstance,
756 const REGFILTER2 *prf2)
758 IParseDisplayName * pParser = NULL;
759 IBindCtx * pBindCtx = NULL;
760 IMoniker * pMoniker = NULL;
761 IPropertyBag * pPropBag = NULL;
763 LPWSTR pwszParseName = NULL;
765 static const WCHAR wszDevice[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
768 LPWSTR szClsidTemp = NULL;
769 REGFILTER2 regfilter2;
770 REGFILTERPINS2* pregfp2 = NULL;
772 TRACE("(%s, %s, %p, %s, %s, %p)\n",
773 debugstr_guid(clsidFilter),
776 debugstr_guid(pclsidCategory),
777 debugstr_w(szInstance),
780 if (prf2->dwVersion == 2)
784 else if (prf2->dwVersion == 1)
788 /* REGFILTER2 structure is converted from version 1 to 2. Tested on Win2k. */
789 regfilter2.dwVersion = 2;
790 regfilter2.dwMerit = prf2->dwMerit;
791 regfilter2.u.s1.cPins2 = prf2->u.s.cPins;
792 pregfp2 = CoTaskMemAlloc(prf2->u.s.cPins * sizeof(REGFILTERPINS2));
793 regfilter2.u.s1.rgPins2 = pregfp2;
794 for (i = 0; i < prf2->u.s.cPins; i++)
797 if (prf2->u.s.rgPins[i].bRendered)
798 flags |= REG_PINFLAG_B_RENDERER;
799 if (prf2->u.s.rgPins[i].bOutput)
800 flags |= REG_PINFLAG_B_OUTPUT;
801 if (prf2->u.s.rgPins[i].bZero)
802 flags |= REG_PINFLAG_B_ZERO;
803 if (prf2->u.s.rgPins[i].bMany)
804 flags |= REG_PINFLAG_B_MANY;
805 pregfp2[i].dwFlags = flags;
806 pregfp2[i].cInstances = 1;
807 pregfp2[i].nMediaTypes = prf2->u.s.rgPins[i].nMediaTypes;
808 pregfp2[i].lpMediaType = prf2->u.s.rgPins[i].lpMediaType;
809 pregfp2[i].nMediums = 0;
810 pregfp2[i].lpMedium = NULL;
811 pregfp2[i].clsPinCategory = NULL;
816 FIXME("dwVersion other that 1 or 2 not supported at the moment\n");
824 /* MSDN mentions the inexistent CLSID_ActiveMovieFilters GUID.
825 * In fact this is the CLSID_LegacyAmFilterCategory one */
826 pclsidCategory = &CLSID_LegacyAmFilterCategory;
828 /* sizeof... will include the null terminator and
829 * the + 1 is for the separator ('\\'). The -1 is
830 * because CHARS_IN_GUID includes the null terminator
832 nameLen = sizeof(wszDevice)/sizeof(wszDevice[0]) + CHARS_IN_GUID - 1 + 1;
835 nameLen += strlenW(szInstance);
837 nameLen += CHARS_IN_GUID - 1; /* CHARS_IN_GUID includes null terminator */
839 pCurrent = pwszParseName = CoTaskMemAlloc(nameLen*sizeof(WCHAR));
841 return E_OUTOFMEMORY;
843 strcpyW(pwszParseName, wszDevice);
844 pCurrent += strlenW(wszDevice);
846 hr = StringFromCLSID(pclsidCategory, &szClsidTemp);
850 memcpy(pCurrent, szClsidTemp, CHARS_IN_GUID * sizeof(WCHAR));
851 pCurrent += CHARS_IN_GUID - 1;
855 strcpyW(pCurrent+1, szInstance);
858 CoTaskMemFree(szClsidTemp);
861 hr = StringFromCLSID(clsidFilter, &szClsidTemp);
863 strcpyW(pCurrent+1, szClsidTemp);
868 hr = CoCreateInstance(&CLSID_CDeviceMoniker, NULL, CLSCTX_INPROC, &IID_IParseDisplayName, (LPVOID *)&pParser);
871 hr = CreateBindCtx(0, &pBindCtx);
874 hr = IParseDisplayName_ParseDisplayName(pParser, pBindCtx, pwszParseName, &ulEaten, &pMoniker);
877 IBindCtx_Release(pBindCtx);
879 IParseDisplayName_Release(pParser);
882 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID)&pPropBag);
885 hr = FM2_WriteFriendlyName(pPropBag, szName);
888 hr = FM2_WriteClsid(pPropBag, clsidFilter);
895 hr = FM2_WriteFilterData(®filter2, &pData, &cbData);
900 SAFEARRAYBOUND saBound;
903 saBound.cElements = cbData;
904 psa = SafeArrayCreate(VT_UI1, 1, &saBound);
907 ERR("Couldn't create SAFEARRAY\n");
914 hr = SafeArrayAccessData(psa, (LPVOID *)&pbSAData);
917 memcpy(pbSAData, pData, cbData);
918 hr = SafeArrayUnaccessData(psa);
922 V_VT(&var) = VT_ARRAY | VT_UI1;
923 V_UNION(&var, parray) = psa;
926 hr = IPropertyBag_Write(pPropBag, wszFilterDataName, &var);
929 SafeArrayDestroy(psa);
930 CoTaskMemFree(pData);
935 IPropertyBag_Release(pPropBag);
936 CoTaskMemFree(szClsidTemp);
937 CoTaskMemFree(pwszParseName);
939 if (SUCCEEDED(hr) && ppMoniker)
940 *ppMoniker = pMoniker;
942 IMoniker_Release(pMoniker);
944 CoTaskMemFree(pregfp2);
946 TRACE("-- returning %x\n", hr);
951 /* internal helper function */
952 static BOOL MatchTypes(
955 const REGPINTYPES * pPinTypes,
957 const GUID * pMatchTypes)
962 if ((nMatchTypes == 0) && (nPinTypes > 0))
965 for (j = 0; j < nPinTypes; j++)
968 for (i = 0; i < nMatchTypes*2; i+=2)
970 if (((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMajorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMajorType, &pMatchTypes[i])) &&
971 ((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMinorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i+1], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMinorType, &pMatchTypes[i+1])))
981 /* internal helper function for qsort of MONIKER_MERIT array */
982 static int mm_compare(const void * left, const void * right)
984 const struct MONIKER_MERIT * mmLeft = left;
985 const struct MONIKER_MERIT * mmRight = right;
987 if (mmLeft->dwMerit == mmRight->dwMerit)
989 if (mmLeft->dwMerit > mmRight->dwMerit)
995 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
996 * (GUID_NULL's in input to function automatically treated as wild cards)
997 * Input/Output needed means match only on criteria if TRUE (with zero input types
998 * meaning match any input/output pin as long as one exists), otherwise match any
999 * filter that meets the rest of the requirements.
1001 static HRESULT WINAPI FilterMapper3_EnumMatchingFilters(
1002 IFilterMapper3 * iface,
1003 IEnumMoniker **ppEnum,
1009 const GUID *pInputTypes,
1010 const REGPINMEDIUM *pMedIn,
1011 const CLSID *pPinCategoryIn,
1015 const GUID *pOutputTypes,
1016 const REGPINMEDIUM *pMedOut,
1017 const CLSID *pPinCategoryOut)
1019 ICreateDevEnum * pCreateDevEnum;
1020 IMoniker * pMonikerCat;
1021 IEnumMoniker * pEnumCat;
1023 struct Vector monikers = {NULL, 0, 0};
1025 TRACE("(%p, %x, %s, %x, %s, %d, %p, %p, %p, %s, %s, %p, %p, %p)\n",
1028 bExactMatch ? "true" : "false",
1030 bInputNeeded ? "true" : "false",
1035 bRender ? "true" : "false",
1036 bOutputNeeded ? "true" : "false",
1043 FIXME("dwFlags = %x not implemented\n", dwFlags);
1048 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, &IID_ICreateDevEnum, (LPVOID*)&pCreateDevEnum);
1052 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEnumCat, 0);
1054 ICreateDevEnum_Release(pCreateDevEnum);
1058 while (IEnumMoniker_Next(pEnumCat, 1, &pMonikerCat, NULL) == S_OK)
1060 IPropertyBag * pPropBagCat = NULL;
1062 HRESULT hrSub; /* this is so that one buggy filter
1063 doesn't make the whole lot fail */
1067 hrSub = IMoniker_BindToStorage(pMonikerCat, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
1069 if (SUCCEEDED(hrSub))
1070 hrSub = IPropertyBag_Read(pPropBagCat, wszMeritName, &var, NULL);
1072 if (SUCCEEDED(hrSub) && (V_UNION(&var, ulVal) >= dwMerit))
1075 IEnumMoniker * pEnum;
1076 IMoniker * pMoniker;
1080 if (TRACE_ON(quartz))
1083 V_VT(&temp) = VT_EMPTY;
1084 IPropertyBag_Read(pPropBagCat, wszFriendlyName, &temp, NULL);
1085 TRACE("Considering category %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
1086 VariantClear(&temp);
1089 hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
1091 if (SUCCEEDED(hrSub))
1092 hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsidCat);
1094 if (SUCCEEDED(hrSub))
1095 hrSub = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
1099 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
1101 IPropertyBag * pPropBag = NULL;
1106 BOOL bInputMatch = !bInputNeeded;
1107 BOOL bOutputMatch = !bOutputNeeded;
1109 ZeroMemory(&rf2, sizeof(rf2));
1112 hrSub = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBag);
1114 if (TRACE_ON(quartz))
1117 V_VT(&temp) = VT_EMPTY;
1118 IPropertyBag_Read(pPropBag, wszFriendlyName, &temp, NULL);
1119 TRACE("Considering filter %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
1120 VariantClear(&temp);
1123 if (SUCCEEDED(hrSub))
1125 hrSub = IPropertyBag_Read(pPropBag, wszFilterDataName, &var, NULL);
1128 if (SUCCEEDED(hrSub))
1129 hrSub = SafeArrayAccessData(V_UNION(&var, parray), (LPVOID*)&pData);
1131 if (SUCCEEDED(hrSub))
1132 hrSub = FM2_ReadFilterData(pData, &rf2);
1135 SafeArrayUnaccessData(V_UNION(&var, parray));
1139 /* Logic used for bInputMatch expression:
1140 * There exists some pin such that bInputNeeded implies (pin is an input and
1141 * (bRender implies pin has render flag) and major/minor types members of
1143 * bOutputMatch is similar, but without the "bRender implies ..." part
1144 * and substituting variables names containing input for output
1147 /* determine whether filter meets requirements */
1148 if (SUCCEEDED(hrSub) && (rf2.dwMerit >= dwMerit))
1150 for (i = 0; (i < rf2.u.s1.cPins2) && (!bInputMatch || !bOutputMatch); i++)
1152 const REGFILTERPINS2 * rfp2 = rf2.u.s1.rgPins2 + i;
1154 bInputMatch = bInputMatch || (!(rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
1155 (!bRender || (rfp2->dwFlags & REG_PINFLAG_B_RENDERER)) &&
1156 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cInputTypes, pInputTypes));
1157 bOutputMatch = bOutputMatch || ((rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
1158 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cOutputTypes, pOutputTypes));
1161 if (bInputMatch && bOutputMatch)
1163 struct MONIKER_MERIT mm = {pMoniker, rf2.dwMerit};
1164 IMoniker_AddRef(pMoniker);
1165 add_data(&monikers, (LPBYTE)&mm, sizeof(mm));
1169 FM2_DeleteRegFilter(&rf2);
1171 IPropertyBag_Release(pPropBag);
1172 IMoniker_Release(pMoniker);
1174 IEnumMoniker_Release(pEnum);
1180 IPropertyBag_Release(pPropBagCat);
1181 IMoniker_Release(pMonikerCat);
1186 IMoniker ** ppMoniker;
1188 ULONG nMonikerCount = monikers.current / sizeof(struct MONIKER_MERIT);
1190 /* sort the monikers in descending merit order */
1191 qsort(monikers.pData, nMonikerCount,
1192 sizeof(struct MONIKER_MERIT),
1195 /* construct an IEnumMoniker interface */
1196 ppMoniker = CoTaskMemAlloc(nMonikerCount * sizeof(IMoniker *));
1197 for (i = 0; i < nMonikerCount; i++)
1199 /* no need to AddRef here as already AddRef'd above */
1200 ppMoniker[i] = ((struct MONIKER_MERIT *)monikers.pData)[i].pMoniker;
1202 hr = EnumMonikerImpl_Create(ppMoniker, nMonikerCount, ppEnum);
1203 CoTaskMemFree(ppMoniker);
1206 delete_vector(&monikers);
1207 IEnumMoniker_Release(pEnumCat);
1208 ICreateDevEnum_Release(pCreateDevEnum);
1213 static HRESULT WINAPI FilterMapper3_GetICreateDevEnum(IFilterMapper3 *iface, ICreateDevEnum **ppEnum)
1215 TRACE("(%p, %p)\n", iface, ppEnum);
1218 return CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, &IID_ICreateDevEnum, (void**)ppEnum);
1221 static const IFilterMapper3Vtbl fm3vtbl =
1224 FilterMapper3_QueryInterface,
1225 FilterMapper3_AddRef,
1226 FilterMapper3_Release,
1228 FilterMapper3_CreateCategory,
1229 FilterMapper3_UnregisterFilter,
1230 FilterMapper3_RegisterFilter,
1231 FilterMapper3_EnumMatchingFilters,
1232 FilterMapper3_GetICreateDevEnum
1235 /*** IUnknown methods ***/
1237 static HRESULT WINAPI FilterMapper_QueryInterface(IFilterMapper * iface, REFIID riid, LPVOID *ppv)
1239 FilterMapper3Impl *This = impl_from_IFilterMapper(iface);
1241 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
1243 return FilterMapper3_QueryInterface(&This->IFilterMapper3_iface, riid, ppv);
1246 static ULONG WINAPI FilterMapper_AddRef(IFilterMapper * iface)
1248 FilterMapper3Impl *This = impl_from_IFilterMapper(iface);
1250 return FilterMapper3_AddRef(&This->IFilterMapper3_iface);
1253 static ULONG WINAPI FilterMapper_Release(IFilterMapper * iface)
1255 FilterMapper3Impl *This = impl_from_IFilterMapper(iface);
1257 return FilterMapper3_Release(&This->IFilterMapper3_iface);
1260 /*** IFilterMapper methods ***/
1262 static HRESULT WINAPI FilterMapper_EnumMatchingFilters(
1263 IFilterMapper * iface,
1264 IEnumRegFilters **ppEnum,
1274 FilterMapper3Impl *This = impl_from_IFilterMapper(iface);
1277 IEnumMoniker* ppEnumMoniker;
1280 ULONG idx = 0, nb_mon = 0;
1281 REGFILTER* regfilters;
1284 TRACE("(%p/%p)->(%p, %x, %s, %s, %s, %s, %s, %s, %s) stub!\n",
1288 bInputNeeded ? "true" : "false",
1289 debugstr_guid(&clsInMaj),
1290 debugstr_guid(&clsInSub),
1291 bRender ? "true" : "false",
1292 bOutputNeeded ? "true" : "false",
1293 debugstr_guid(&clsOutMaj),
1294 debugstr_guid(&clsOutSub));
1296 InputType[0] = clsInMaj;
1297 InputType[1] = clsInSub;
1298 OutputType[0] = clsOutMaj;
1299 OutputType[1] = clsOutSub;
1303 hr = IFilterMapper3_EnumMatchingFilters(&This->IFilterMapper3_iface, &ppEnumMoniker, 0, TRUE,
1304 dwMerit, bInputNeeded, 1, InputType, NULL, &GUID_NULL, bRender, bOutputNeeded, 1,
1305 OutputType, NULL, &GUID_NULL);
1310 while(IEnumMoniker_Next(ppEnumMoniker, 1, &IMon, &nb) == S_OK)
1312 IMoniker_Release(IMon);
1318 IEnumMoniker_Release(ppEnumMoniker);
1319 return IEnumRegFiltersImpl_Construct(NULL, 0, ppEnum);
1322 regfilters = CoTaskMemAlloc(nb_mon * sizeof(REGFILTER));
1325 IEnumMoniker_Release(ppEnumMoniker);
1326 return E_OUTOFMEMORY;
1328 ZeroMemory(regfilters, nb_mon * sizeof(REGFILTER)); /* will prevent bad free of Name in case of error. */
1330 IEnumMoniker_Reset(ppEnumMoniker);
1331 while(IEnumMoniker_Next(ppEnumMoniker, 1, &IMon, &nb) == S_OK)
1333 IPropertyBag * pPropBagCat = NULL;
1341 hrSub = IMoniker_BindToStorage(IMon, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
1343 if (SUCCEEDED(hrSub))
1344 hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
1346 if (SUCCEEDED(hrSub))
1347 hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsid);
1351 if (SUCCEEDED(hrSub))
1352 hrSub = IPropertyBag_Read(pPropBagCat, wszFriendlyName, &var, NULL);
1354 if (SUCCEEDED(hrSub))
1356 len = (strlenW(V_UNION(&var, bstrVal))+1) * sizeof(WCHAR);
1357 if (!(regfilters[idx].Name = CoTaskMemAlloc(len*2)))
1361 if (SUCCEEDED(hrSub) && regfilters[idx].Name)
1363 memcpy(regfilters[idx].Name, V_UNION(&var, bstrVal), len);
1364 regfilters[idx].Clsid = clsid;
1369 IPropertyBag_Release(pPropBagCat);
1370 IMoniker_Release(IMon);
1376 hr = IEnumRegFiltersImpl_Construct(regfilters, nb_mon, ppEnum);
1379 for (idx = 0; idx < nb_mon; idx++)
1380 CoTaskMemFree(regfilters[idx].Name);
1381 CoTaskMemFree(regfilters);
1382 IEnumMoniker_Release(ppEnumMoniker);
1388 static HRESULT WINAPI FilterMapper_RegisterFilter(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, DWORD dwMerit)
1391 LPWSTR wszClsid = NULL;
1394 WCHAR wszKeyName[ARRAYSIZE(wszFilterSlash)-1 + (CHARS_IN_GUID-1) + 1];
1396 TRACE("(%p)->(%s, %s, %x)\n", iface, debugstr_guid(&clsid), debugstr_w(szName), dwMerit);
1398 hr = StringFromCLSID(&clsid, &wszClsid);
1402 strcpyW(wszKeyName, wszFilterSlash);
1403 strcatW(wszKeyName, wszClsid);
1405 lRet = RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
1406 hr = HRESULT_FROM_WIN32(lRet);
1411 lRet = RegSetValueExW(hKey, NULL, 0, REG_SZ, (const BYTE*)szName, (strlenW(szName) + 1) * sizeof(WCHAR));
1412 hr = HRESULT_FROM_WIN32(lRet);
1418 strcpyW(wszKeyName, wszClsidSlash);
1419 strcatW(wszKeyName, wszClsid);
1421 lRet = RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
1422 hr = HRESULT_FROM_WIN32(lRet);
1427 lRet = RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwMerit, sizeof(dwMerit));
1428 hr = HRESULT_FROM_WIN32(lRet);
1432 CoTaskMemFree(wszClsid);
1437 static HRESULT WINAPI FilterMapper_RegisterFilterInstance(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, CLSID *MRId)
1439 TRACE("(%p)->(%s, %s, %p)\n", iface, debugstr_guid(&clsid), debugstr_w(szName), MRId);
1441 /* Not implemented in Windows (tested on Win2k) */
1446 static HRESULT WINAPI FilterMapper_RegisterPin(
1447 IFilterMapper * iface,
1454 CLSID ConnectsToFilter,
1455 LPCWSTR ConnectsToPin)
1459 LPWSTR wszClsid = NULL;
1461 HKEY hPinsKey = NULL;
1462 WCHAR * wszPinsKeyName;
1463 WCHAR wszKeyName[ARRAYSIZE(wszClsidSlash)-1 + (CHARS_IN_GUID-1) + 1];
1465 TRACE("(%p)->(%s, %s, %d, %d, %d, %d, %s, %s)\n", iface, debugstr_guid(&Filter), debugstr_w(szName), bRendered,
1466 bOutput, bZero, bMany, debugstr_guid(&ConnectsToFilter), debugstr_w(ConnectsToPin));
1468 hr = StringFromCLSID(&Filter, &wszClsid);
1472 strcpyW(wszKeyName, wszClsidSlash);
1473 strcatW(wszKeyName, wszClsid);
1475 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1476 hr = HRESULT_FROM_WIN32(lRet);
1481 wszPinsKeyName = CoTaskMemAlloc((strlenW(wszPins) + 1 + strlenW(szName) + 1) * 2);
1482 if (!wszPinsKeyName)
1488 strcpyW(wszPinsKeyName, wszPins);
1489 strcatW(wszPinsKeyName, wszSlash);
1490 strcatW(wszPinsKeyName, szName);
1492 lRet = RegCreateKeyExW(hKey, wszPinsKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hPinsKey, NULL);
1493 hr = HRESULT_FROM_WIN32(lRet);
1494 CoTaskMemFree(wszPinsKeyName);
1499 lRet = RegSetValueExW(hPinsKey, wszAllowedMany, 0, REG_DWORD, (LPBYTE)&bMany, sizeof(bMany));
1500 hr = HRESULT_FROM_WIN32(lRet);
1505 lRet = RegSetValueExW(hPinsKey, wszAllowedZero, 0, REG_DWORD, (LPBYTE)&bZero, sizeof(bZero));
1506 hr = HRESULT_FROM_WIN32(lRet);
1511 lRet = RegSetValueExW(hPinsKey, wszDirection, 0, REG_DWORD, (LPBYTE)&bOutput, sizeof(bOutput));
1512 hr = HRESULT_FROM_WIN32(lRet);
1517 lRet = RegSetValueExW(hPinsKey, wszIsRendered, 0, REG_DWORD, (LPBYTE)&bRendered, sizeof(bRendered));
1518 hr = HRESULT_FROM_WIN32(lRet);
1523 HKEY hkeyDummy = NULL;
1525 lRet = RegCreateKeyExW(hPinsKey, wszTypes, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkeyDummy, NULL);
1526 hr = HRESULT_FROM_WIN32(lRet);
1528 if (hkeyDummy) RegCloseKey(hkeyDummy);
1531 CoTaskMemFree(wszClsid);
1535 CloseHandle(hPinsKey);
1541 static HRESULT WINAPI FilterMapper_RegisterPinType(
1542 IFilterMapper * iface,
1550 LPWSTR wszClsid = NULL;
1551 LPWSTR wszClsidMajorType = NULL;
1552 LPWSTR wszClsidSubType = NULL;
1554 WCHAR * wszTypesKey;
1555 WCHAR wszKeyName[MAX_PATH];
1557 TRACE("(%p)->(%s, %s, %s, %s)\n", iface, debugstr_guid(&clsFilter), debugstr_w(szName),
1558 debugstr_guid(&clsMajorType), debugstr_guid(&clsSubType));
1560 hr = StringFromCLSID(&clsFilter, &wszClsid);
1564 hr = StringFromCLSID(&clsMajorType, &wszClsidMajorType);
1569 hr = StringFromCLSID(&clsSubType, &wszClsidSubType);
1574 wszTypesKey = CoTaskMemAlloc((strlenW(wszClsidSlash) + strlenW(wszClsid) + strlenW(wszPins) +
1575 strlenW(szName) + strlenW(wszTypes) + 3 + 1) * 2);
1582 strcpyW(wszTypesKey, wszClsidSlash);
1583 strcatW(wszTypesKey, wszClsid);
1584 strcatW(wszTypesKey, wszSlash);
1585 strcatW(wszTypesKey, wszPins);
1586 strcatW(wszTypesKey, wszSlash);
1587 strcatW(wszTypesKey, szName);
1588 strcatW(wszTypesKey, wszSlash);
1589 strcatW(wszTypesKey, wszTypes);
1591 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszTypesKey, 0, KEY_WRITE, &hKey);
1592 hr = HRESULT_FROM_WIN32(lRet);
1593 CoTaskMemFree(wszTypesKey);
1598 HKEY hkeyDummy = NULL;
1600 strcpyW(wszKeyName, wszClsidMajorType);
1601 strcatW(wszKeyName, wszSlash);
1602 strcatW(wszKeyName, wszClsidSubType);
1604 lRet = RegCreateKeyExW(hKey, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkeyDummy, NULL);
1605 hr = HRESULT_FROM_WIN32(lRet);
1608 if (hkeyDummy) RegCloseKey(hkeyDummy);
1611 CoTaskMemFree(wszClsid);
1612 CoTaskMemFree(wszClsidMajorType);
1613 CoTaskMemFree(wszClsidSubType);
1618 static HRESULT WINAPI FilterMapper_UnregisterFilter(IFilterMapper * iface, CLSID Filter)
1622 LPWSTR wszClsid = NULL;
1624 WCHAR wszKeyName[ARRAYSIZE(wszClsidSlash)-1 + (CHARS_IN_GUID-1) + 1];
1626 TRACE("(%p)->(%s)\n", iface, debugstr_guid(&Filter));
1628 hr = StringFromCLSID(&Filter, &wszClsid);
1632 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszFilter, 0, KEY_WRITE, &hKey);
1633 hr = HRESULT_FROM_WIN32(lRet);
1638 lRet = RegDeleteKeyW(hKey, wszClsid);
1639 hr = HRESULT_FROM_WIN32(lRet);
1645 strcpyW(wszKeyName, wszClsidSlash);
1646 strcatW(wszKeyName, wszClsid);
1648 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1649 hr = HRESULT_FROM_WIN32(lRet);
1654 lRet = RegDeleteValueW(hKey, wszMeritName);
1655 if (lRet != ERROR_SUCCESS)
1656 hr = HRESULT_FROM_WIN32(lRet);
1658 lRet = RegDeleteTreeW(hKey, wszPins);
1659 if (lRet != ERROR_SUCCESS)
1660 hr = HRESULT_FROM_WIN32(lRet);
1665 CoTaskMemFree(wszClsid);
1670 static HRESULT WINAPI FilterMapper_UnregisterFilterInstance(IFilterMapper * iface, CLSID MRId)
1672 TRACE("(%p)->(%s)\n", iface, debugstr_guid(&MRId));
1674 /* Not implemented in Windows (tested on Win2k) */
1679 static HRESULT WINAPI FilterMapper_UnregisterPin(IFilterMapper * iface, CLSID Filter, LPCWSTR Name)
1683 LPWSTR wszClsid = NULL;
1685 WCHAR * wszPinNameKey;
1686 WCHAR wszKeyName[ARRAYSIZE(wszClsidSlash)-1 + (CHARS_IN_GUID-1) + 1];
1688 TRACE("(%p)->(%s, %s)\n", iface, debugstr_guid(&Filter), debugstr_w(Name));
1691 return E_INVALIDARG;
1693 hr = StringFromCLSID(&Filter, &wszClsid);
1697 strcpyW(wszKeyName, wszClsidSlash);
1698 strcatW(wszKeyName, wszClsid);
1700 lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1701 hr = HRESULT_FROM_WIN32(lRet);
1706 wszPinNameKey = CoTaskMemAlloc((strlenW(wszPins) + 1 + strlenW(Name) + 1) * 2);
1713 strcpyW(wszPinNameKey, wszPins);
1714 strcatW(wszPinNameKey, wszSlash);
1715 strcatW(wszPinNameKey, Name);
1717 lRet = RegDeleteTreeW(hKey, wszPinNameKey);
1718 hr = HRESULT_FROM_WIN32(lRet);
1719 CoTaskMemFree(wszPinNameKey);
1722 CoTaskMemFree(wszClsid);
1729 static const IFilterMapperVtbl fmvtbl =
1732 FilterMapper_QueryInterface,
1733 FilterMapper_AddRef,
1734 FilterMapper_Release,
1736 FilterMapper_RegisterFilter,
1737 FilterMapper_RegisterFilterInstance,
1738 FilterMapper_RegisterPin,
1739 FilterMapper_RegisterPinType,
1740 FilterMapper_UnregisterFilter,
1741 FilterMapper_UnregisterFilterInstance,
1742 FilterMapper_UnregisterPin,
1743 FilterMapper_EnumMatchingFilters
1747 /*** IUnknown methods ***/
1748 static HRESULT WINAPI AMFilterData_QueryInterface(IAMFilterData * iface, REFIID riid, LPVOID *ppv)
1750 FilterMapper3Impl *This = impl_from_IAMFilterData(iface);
1752 return FilterMapper3_QueryInterface(&This->IFilterMapper3_iface, riid, ppv);
1755 static ULONG WINAPI AMFilterData_AddRef(IAMFilterData * iface)
1757 FilterMapper3Impl *This = impl_from_IAMFilterData(iface);
1759 return FilterMapper3_AddRef(&This->IFilterMapper3_iface);
1762 static ULONG WINAPI AMFilterData_Release(IAMFilterData * iface)
1764 FilterMapper3Impl *This = impl_from_IAMFilterData(iface);
1766 return FilterMapper3_Release(&This->IFilterMapper3_iface);
1769 /*** IAMFilterData methods ***/
1770 static HRESULT WINAPI AMFilterData_ParseFilterData(IAMFilterData* iface,
1771 BYTE *pData, ULONG cb,
1772 BYTE **ppRegFilter2)
1774 FilterMapper3Impl *This = impl_from_IAMFilterData(iface);
1778 TRACE("(%p/%p)->(%p, %d, %p)\n", This, iface, pData, cb, ppRegFilter2);
1780 prf2 = CoTaskMemAlloc(sizeof(*prf2));
1782 return E_OUTOFMEMORY;
1783 *ppRegFilter2 = (BYTE *)prf2;
1785 hr = FM2_ReadFilterData(pData, prf2);
1788 CoTaskMemFree(prf2);
1789 *ppRegFilter2 = NULL;
1795 static HRESULT WINAPI AMFilterData_CreateFilterData(IAMFilterData* iface,
1797 BYTE **pRegFilterData,
1800 FilterMapper3Impl *This = impl_from_IAMFilterData(iface);
1802 TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, prf2, pRegFilterData, pcb);
1804 return FM2_WriteFilterData(prf2, pRegFilterData, pcb);
1807 static const IAMFilterDataVtbl AMFilterDataVtbl = {
1808 AMFilterData_QueryInterface,
1809 AMFilterData_AddRef,
1810 AMFilterData_Release,
1811 AMFilterData_ParseFilterData,
1812 AMFilterData_CreateFilterData