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., 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 /* Unexposed IAMFilterData interface */
45 typedef struct IAMFilterData IAMFilterData
;
47 typedef struct IAMFilterDataVtbl
51 /*** IUnknown methods ***/
52 HRESULT (STDMETHODCALLTYPE
*QueryInterface
)(
57 ULONG (STDMETHODCALLTYPE
*AddRef
)(
60 ULONG (STDMETHODCALLTYPE
*Release
)(
63 /*** IAMFilterData methods ***/
64 HRESULT (STDMETHODCALLTYPE
*ParseFilterData
)(
70 HRESULT (STDMETHODCALLTYPE
*CreateFilterData
)(
73 BYTE
**pRegFilterData
,
80 const IAMFilterDataVtbl
*lpVtbl
;
82 const GUID IID_IAMFilterData
= {
83 0x97f7c4d4, 0x547b, 0x4a5f, { 0x83,0x32, 0x53,0x64,0x30,0xad,0x2e,0x4d }
87 typedef struct FilterMapper2Impl
89 const IFilterMapper2Vtbl
*lpVtbl
;
90 const IFilterMapperVtbl
*lpVtblFilterMapper
;
91 const IAMFilterDataVtbl
*lpVtblAMFilterData
;
95 static const IFilterMapper2Vtbl fm2vtbl
;
96 static const IFilterMapperVtbl fmvtbl
;
97 static const IAMFilterDataVtbl AMFilterDataVtbl
;
99 static inline FilterMapper2Impl
*impl_from_IFilterMapper( IFilterMapper
*iface
)
101 return (FilterMapper2Impl
*)((char*)iface
- FIELD_OFFSET(FilterMapper2Impl
, lpVtblFilterMapper
));
104 static inline FilterMapper2Impl
*impl_from_IAMFilterData( IAMFilterData
*iface
)
106 return (FilterMapper2Impl
*)((char*)iface
- FIELD_OFFSET(FilterMapper2Impl
, lpVtblAMFilterData
));
109 static const WCHAR wszClsidSlash
[] = {'C','L','S','I','D','\\',0};
110 static const WCHAR wszSlashInstance
[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
111 static const WCHAR wszSlash
[] = {'\\',0};
113 /* CLSID property in media category Moniker */
114 static const WCHAR wszClsidName
[] = {'C','L','S','I','D',0};
115 /* FriendlyName property in media category Moniker */
116 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
117 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
118 static const WCHAR wszMeritName
[] = {'M','e','r','i','t',0};
119 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
120 static const WCHAR wszFilterDataName
[] = {'F','i','l','t','e','r','D','a','t','a',0};
121 /* For filters registered with IFilterMapper */
122 static const WCHAR wszFilterSlash
[] = {'F','i','l','t','e','r','\\',0};
123 static const WCHAR wszFilter
[] = {'F','i','l','t','e','r',0};
124 /* For pins registered with IFilterMapper */
125 static const WCHAR wszPins
[] = {'P','i','n','s',0};
126 static const WCHAR wszAllowedMany
[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
127 static const WCHAR wszAllowedZero
[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
128 static const WCHAR wszDirection
[] = {'D','i','r','e','c','t','i','o','n',0};
129 static const WCHAR wszIsRendered
[] = {'I','s','R','e','n','d','e','r','e','d',0};
130 /* For types registered with IFilterMapper */
131 static const WCHAR wszTypes
[] = {'T','y','p','e','s',0};
134 /* registry format for REGFILTER2 */
145 BYTE signature
[4]; /* e.g. "0pi3" */
150 DWORD bCategory
; /* is there a category clsid? */
151 /* optional: dwOffsetCategoryClsid */
156 BYTE signature
[4]; /* e.g. "0ty3" */
171 int capacity
; /* in bytes */
172 int current
; /* pointer to next free byte */
175 /* returns the position it was added at */
176 static int add_data(struct Vector
* v
, const BYTE
* pData
, int size
)
178 int index
= v
->current
;
179 if (v
->current
+ size
> v
->capacity
)
181 LPBYTE pOldData
= v
->pData
;
182 v
->capacity
= (v
->capacity
+ size
) * 2;
183 v
->pData
= CoTaskMemAlloc(v
->capacity
);
184 memcpy(v
->pData
, pOldData
, v
->current
);
185 CoTaskMemFree(pOldData
);
187 memcpy(v
->pData
+ v
->current
, pData
, size
);
192 static int find_data(struct Vector
* v
, const BYTE
* pData
, int size
)
195 for (index
= 0; index
< v
->current
; index
++)
196 if (!memcmp(v
->pData
+ index
, pData
, size
))
202 static void delete_vector(struct Vector
* v
)
204 CoTaskMemFree(v
->pData
);
209 HRESULT
FilterMapper2_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
211 FilterMapper2Impl
* pFM2impl
;
213 TRACE("(%p, %p)\n", pUnkOuter
, ppObj
);
216 return CLASS_E_NOAGGREGATION
;
218 pFM2impl
= CoTaskMemAlloc(sizeof(*pFM2impl
));
220 return E_OUTOFMEMORY
;
222 pFM2impl
->lpVtbl
= &fm2vtbl
;
223 pFM2impl
->lpVtblFilterMapper
= &fmvtbl
;
224 pFM2impl
->lpVtblAMFilterData
= &AMFilterDataVtbl
;
225 pFM2impl
->refCount
= 1;
229 TRACE("-- created at %p\n", pFM2impl
);
234 HRESULT
FilterMapper_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
236 FilterMapper2Impl
*pFM2impl
;
239 TRACE("(%p, %p)\n", pUnkOuter
, ppObj
);
241 hr
= FilterMapper2_create(pUnkOuter
, (LPVOID
*)&pFM2impl
);
245 *ppObj
= &pFM2impl
->lpVtblFilterMapper
;
250 /*** IUnknown methods ***/
252 static HRESULT WINAPI
FilterMapper2_QueryInterface(IFilterMapper2
* iface
, REFIID riid
, LPVOID
*ppv
)
254 FilterMapper2Impl
*This
= (FilterMapper2Impl
*)iface
;
256 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
260 if (IsEqualIID(riid
, &IID_IUnknown
))
262 else if (IsEqualIID(riid
, &IID_IFilterMapper2
))
264 else if (IsEqualIID(riid
, &IID_IFilterMapper
))
265 *ppv
= &This
->lpVtblFilterMapper
;
266 else if (IsEqualIID(riid
, &IID_IAMFilterData
))
267 *ppv
= &This
->lpVtblAMFilterData
;
271 IUnknown_AddRef((IUnknown
*)*ppv
);
275 FIXME("No interface for %s\n", debugstr_guid(riid
));
276 return E_NOINTERFACE
;
279 static ULONG WINAPI
FilterMapper2_AddRef(IFilterMapper2
* iface
)
281 FilterMapper2Impl
*This
= (FilterMapper2Impl
*)iface
;
282 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
284 TRACE("(%p)->() AddRef from %d\n", This
, refCount
- 1);
289 static ULONG WINAPI
FilterMapper2_Release(IFilterMapper2
* iface
)
291 FilterMapper2Impl
*This
= (FilterMapper2Impl
*)iface
;
292 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
294 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
304 /*** IFilterMapper2 methods ***/
306 static HRESULT WINAPI
FilterMapper2_CreateCategory(
307 IFilterMapper2
* iface
,
308 REFCLSID clsidCategory
,
309 DWORD dwCategoryMerit
,
310 LPCWSTR szDescription
)
312 LPWSTR wClsidAMCat
= NULL
;
313 LPWSTR wClsidCategory
= NULL
;
314 WCHAR wszKeyName
[strlenW(wszClsidSlash
) + strlenW(wszSlashInstance
) + (CHARS_IN_GUID
-1) * 2 + 1];
319 TRACE("(%s, %x, %s)\n", debugstr_guid(clsidCategory
), dwCategoryMerit
, debugstr_w(szDescription
));
321 hr
= StringFromCLSID(&CLSID_ActiveMovieCategories
, &wClsidAMCat
);
325 hr
= StringFromCLSID(clsidCategory
, &wClsidCategory
);
330 strcpyW(wszKeyName
, wszClsidSlash
);
331 strcatW(wszKeyName
, wClsidAMCat
);
332 strcatW(wszKeyName
, wszSlashInstance
);
333 strcatW(wszKeyName
, wClsidCategory
);
335 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
336 hr
= HRESULT_FROM_WIN32(lRet
);
341 lRet
= RegSetValueExW(hKey
, wszFriendlyName
, 0, REG_SZ
, (const BYTE
*)szDescription
, (strlenW(szDescription
) + 1) * sizeof(WCHAR
));
342 hr
= HRESULT_FROM_WIN32(lRet
);
347 lRet
= RegSetValueExW(hKey
, wszClsidName
, 0, REG_SZ
, (LPBYTE
)wClsidCategory
, (strlenW(wClsidCategory
) + 1) * sizeof(WCHAR
));
348 hr
= HRESULT_FROM_WIN32(lRet
);
353 lRet
= RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwCategoryMerit
, sizeof(dwCategoryMerit
));
354 hr
= HRESULT_FROM_WIN32(lRet
);
358 CoTaskMemFree(wClsidCategory
);
359 CoTaskMemFree(wClsidAMCat
);
364 static HRESULT WINAPI
FilterMapper2_UnregisterFilter(
365 IFilterMapper2
* iface
,
366 const CLSID
*pclsidCategory
,
367 const OLECHAR
*szInstance
,
370 WCHAR wszKeyName
[MAX_PATH
];
371 LPWSTR wClsidCategory
= NULL
;
372 LPWSTR wFilter
= NULL
;
375 TRACE("(%p, %s, %s)\n", pclsidCategory
, debugstr_w(szInstance
), debugstr_guid(Filter
));
378 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
380 hr
= StringFromCLSID(pclsidCategory
, &wClsidCategory
);
384 strcpyW(wszKeyName
, wszClsidSlash
);
385 strcatW(wszKeyName
, wClsidCategory
);
386 strcatW(wszKeyName
, wszSlashInstance
);
388 strcatW(wszKeyName
, szInstance
);
391 hr
= StringFromCLSID(Filter
, &wFilter
);
393 strcatW(wszKeyName
, wFilter
);
399 LONG lRet
= RegDeleteKeyW(HKEY_CLASSES_ROOT
, wszKeyName
);
400 hr
= HRESULT_FROM_WIN32(lRet
);
403 CoTaskMemFree(wClsidCategory
);
404 CoTaskMemFree(wFilter
);
409 static HRESULT
FM2_WriteFriendlyName(IPropertyBag
* pPropBag
, LPCWSTR szName
)
413 V_VT(&var
) = VT_BSTR
;
414 V_UNION(&var
, bstrVal
) = (BSTR
)szName
;
416 return IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
419 static HRESULT
FM2_WriteClsid(IPropertyBag
* pPropBag
, REFCLSID clsid
)
421 LPWSTR wszClsid
= NULL
;
425 hr
= StringFromCLSID(clsid
, &wszClsid
);
429 V_VT(&var
) = VT_BSTR
;
430 V_UNION(&var
, bstrVal
) = wszClsid
;
431 hr
= IPropertyBag_Write(pPropBag
, wszClsidName
, &var
);
433 CoTaskMemFree(wszClsid
);
437 static HRESULT
FM2_WriteFilterData(const REGFILTER2
* prf2
, BYTE
**ppData
, ULONG
*pcbData
)
439 int size
= sizeof(struct REG_RF
);
441 struct Vector mainStore
= {NULL
, 0, 0};
442 struct Vector clsidStore
= {NULL
, 0, 0};
446 rrf
.dwVersion
= prf2
->dwVersion
;
447 rrf
.dwMerit
= prf2
->dwMerit
;
448 rrf
.dwPins
= prf2
->u
.s1
.cPins2
;
451 add_data(&mainStore
, (LPBYTE
)&rrf
, sizeof(rrf
));
453 for (i
= 0; i
< prf2
->u
.s1
.cPins2
; i
++)
455 size
+= sizeof(struct REG_RFP
);
456 if (prf2
->u
.s1
.rgPins2
[i
].clsPinCategory
)
457 size
+= sizeof(DWORD
);
458 size
+= prf2
->u
.s1
.rgPins2
[i
].nMediaTypes
* sizeof(struct REG_TYPE
);
459 size
+= prf2
->u
.s1
.rgPins2
[i
].nMediums
* sizeof(DWORD
);
462 for (i
= 0; i
< prf2
->u
.s1
.cPins2
; i
++)
465 REGFILTERPINS2 rgPin2
= prf2
->u
.s1
.rgPins2
[i
];
468 rrfp
.signature
[0] = '0';
469 rrfp
.signature
[1] = 'p';
470 rrfp
.signature
[2] = 'i';
471 rrfp
.signature
[3] = '3';
472 rrfp
.signature
[0] += i
;
473 rrfp
.dwFlags
= rgPin2
.dwFlags
;
474 rrfp
.dwInstances
= rgPin2
.cInstances
;
475 rrfp
.dwMediaTypes
= rgPin2
.nMediaTypes
;
476 rrfp
.dwMediums
= rgPin2
.nMediums
;
477 rrfp
.bCategory
= rgPin2
.clsPinCategory
? 1 : 0;
479 add_data(&mainStore
, (LPBYTE
)&rrfp
, sizeof(rrfp
));
482 DWORD index
= find_data(&clsidStore
, (const BYTE
*)rgPin2
.clsPinCategory
, sizeof(CLSID
));
484 index
= add_data(&clsidStore
, (const BYTE
*)rgPin2
.clsPinCategory
, sizeof(CLSID
));
487 add_data(&mainStore
, (LPBYTE
)&index
, sizeof(index
));
490 for (j
= 0; j
< rgPin2
.nMediaTypes
; j
++)
493 rt
.signature
[0] = '0';
494 rt
.signature
[1] = 't';
495 rt
.signature
[2] = 'y';
496 rt
.signature
[3] = '3';
497 rt
.signature
[0] += j
;
500 rt
.dwOffsetMajor
= find_data(&clsidStore
, (const BYTE
*)rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
501 if (rt
.dwOffsetMajor
== -1)
502 rt
.dwOffsetMajor
= add_data(&clsidStore
, (const BYTE
*)rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
503 rt
.dwOffsetMajor
+= size
;
504 rt
.dwOffsetMinor
= find_data(&clsidStore
, (const BYTE
*)rgPin2
.lpMediaType
[j
].clsMinorType
, sizeof(CLSID
));
505 if (rt
.dwOffsetMinor
== -1)
506 rt
.dwOffsetMinor
= add_data(&clsidStore
, (const BYTE
*)rgPin2
.lpMediaType
[j
].clsMinorType
, sizeof(CLSID
));
507 rt
.dwOffsetMinor
+= size
;
509 add_data(&mainStore
, (LPBYTE
)&rt
, sizeof(rt
));
512 for (j
= 0; j
< rgPin2
.nMediums
; j
++)
514 DWORD index
= find_data(&clsidStore
, (const BYTE
*)(rgPin2
.lpMedium
+ j
), sizeof(REGPINMEDIUM
));
516 index
= add_data(&clsidStore
, (const BYTE
*)(rgPin2
.lpMedium
+ j
), sizeof(REGPINMEDIUM
));
519 add_data(&mainStore
, (LPBYTE
)&index
, sizeof(index
));
525 *pcbData
= mainStore
.current
+ clsidStore
.current
;
526 *ppData
= CoTaskMemAlloc(*pcbData
);
533 memcpy(*ppData
, mainStore
.pData
, mainStore
.current
);
534 memcpy((*ppData
) + mainStore
.current
, clsidStore
.pData
, clsidStore
.current
);
537 delete_vector(&mainStore
);
538 delete_vector(&clsidStore
);
542 static HRESULT
FM2_ReadFilterData(BYTE
*pData
, REGFILTER2
* prf2
)
545 struct REG_RF
* prrf
;
548 REGFILTERPINS2
* rgPins2
;
550 prrf
= (struct REG_RF
*)pData
;
553 if (prrf
->dwVersion
!= 2)
555 FIXME("Filter registry version %d not supported\n", prrf
->dwVersion
);
556 ZeroMemory(prf2
, sizeof(*prf2
));
562 TRACE("version = %d, merit = %x, #pins = %d, unused = %x\n",
563 prrf
->dwVersion
, prrf
->dwMerit
, prrf
->dwPins
, prrf
->dwUnused
);
565 prf2
->dwVersion
= prrf
->dwVersion
;
566 prf2
->dwMerit
= prrf
->dwMerit
;
567 prf2
->u
.s1
.cPins2
= prrf
->dwPins
;
568 rgPins2
= CoTaskMemAlloc(prrf
->dwPins
* sizeof(*rgPins2
));
569 prf2
->u
.s1
.rgPins2
= rgPins2
;
570 pCurrent
+= sizeof(struct REG_RF
);
572 for (i
= 0; i
< prrf
->dwPins
; i
++)
574 struct REG_RFP
* prrfp
= (struct REG_RFP
*)pCurrent
;
575 REGPINTYPES
* lpMediaType
;
576 REGPINMEDIUM
* lpMedium
;
579 /* FIXME: check signature */
581 TRACE("\tsignature = %s\n", debugstr_an((const char*)prrfp
->signature
, 4));
583 TRACE("\tpin[%d]: flags = %x, instances = %d, media types = %d, mediums = %d\n",
584 i
, prrfp
->dwFlags
, prrfp
->dwInstances
, prrfp
->dwMediaTypes
, prrfp
->dwMediums
);
586 rgPins2
[i
].dwFlags
= prrfp
->dwFlags
;
587 rgPins2
[i
].cInstances
= prrfp
->dwInstances
;
588 rgPins2
[i
].nMediaTypes
= prrfp
->dwMediaTypes
;
589 rgPins2
[i
].nMediums
= prrfp
->dwMediums
;
590 pCurrent
+= sizeof(struct REG_RFP
);
591 if (prrfp
->bCategory
)
593 CLSID
* clsCat
= CoTaskMemAlloc(sizeof(CLSID
));
594 memcpy(clsCat
, pData
+ *(DWORD
*)(pCurrent
), sizeof(CLSID
));
595 pCurrent
+= sizeof(DWORD
);
596 rgPins2
[i
].clsPinCategory
= clsCat
;
599 rgPins2
[i
].clsPinCategory
= NULL
;
601 if (rgPins2
[i
].nMediaTypes
> 0)
602 lpMediaType
= CoTaskMemAlloc(rgPins2
[i
].nMediaTypes
* sizeof(*lpMediaType
));
606 rgPins2
[i
].lpMediaType
= lpMediaType
;
608 for (j
= 0; j
< rgPins2
[i
].nMediaTypes
; j
++)
610 struct REG_TYPE
* prt
= (struct REG_TYPE
*)pCurrent
;
611 CLSID
* clsMajor
= CoTaskMemAlloc(sizeof(CLSID
));
612 CLSID
* clsMinor
= CoTaskMemAlloc(sizeof(CLSID
));
614 /* FIXME: check signature */
615 TRACE("\t\tsignature = %s\n", debugstr_an((const char*)prt
->signature
, 4));
617 memcpy(clsMajor
, pData
+ prt
->dwOffsetMajor
, sizeof(CLSID
));
618 memcpy(clsMinor
, pData
+ prt
->dwOffsetMinor
, sizeof(CLSID
));
620 lpMediaType
[j
].clsMajorType
= clsMajor
;
621 lpMediaType
[j
].clsMinorType
= clsMinor
;
623 pCurrent
+= sizeof(*prt
);
626 if (rgPins2
[i
].nMediums
> 0)
627 lpMedium
= CoTaskMemAlloc(rgPins2
[i
].nMediums
* sizeof(*lpMedium
));
631 rgPins2
[i
].lpMedium
= lpMedium
;
633 for (j
= 0; j
< rgPins2
[i
].nMediums
; j
++)
635 DWORD dwOffset
= *(DWORD
*)pCurrent
;
637 memcpy(lpMedium
+ j
, pData
+ dwOffset
, sizeof(REGPINMEDIUM
));
639 pCurrent
+= sizeof(dwOffset
);
648 static void FM2_DeleteRegFilter(REGFILTER2
* prf2
)
651 for (i
= 0; i
< prf2
->u
.s1
.cPins2
; i
++)
654 if (prf2
->u
.s1
.rgPins2
[i
].clsPinCategory
)
655 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].clsPinCategory
);
657 for (j
= 0; j
< prf2
->u
.s1
.rgPins2
[i
].nMediaTypes
; j
++)
659 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].lpMediaType
[j
].clsMajorType
);
660 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].lpMediaType
[j
].clsMinorType
);
662 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].lpMedium
);
666 static HRESULT WINAPI
FilterMapper2_RegisterFilter(
667 IFilterMapper2
* iface
,
668 REFCLSID clsidFilter
,
670 IMoniker
**ppMoniker
,
671 const CLSID
*pclsidCategory
,
672 const OLECHAR
*szInstance
,
673 const REGFILTER2
*prf2
)
675 IParseDisplayName
* pParser
= NULL
;
676 IBindCtx
* pBindCtx
= NULL
;
677 IMoniker
* pMoniker
= NULL
;
678 IPropertyBag
* pPropBag
= NULL
;
680 LPWSTR pwszParseName
= NULL
;
682 static const WCHAR wszDevice
[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
685 LPWSTR szClsidTemp
= NULL
;
686 REGFILTER2 regfilter2
;
687 REGFILTERPINS2
* pregfp2
= NULL
;
689 TRACE("(%s, %s, %p, %s, %s, %p)\n",
690 debugstr_guid(clsidFilter
),
693 debugstr_guid(pclsidCategory
),
694 debugstr_w(szInstance
),
697 if (prf2
->dwVersion
== 2)
701 else if (prf2
->dwVersion
== 1)
705 /* REGFILTER2 structure is converted from version 1 to 2. Tested on Win2k. */
706 regfilter2
.dwVersion
= 2;
707 regfilter2
.dwMerit
= prf2
->dwMerit
;
708 regfilter2
.u
.s1
.cPins2
= prf2
->u
.s
.cPins
;
709 pregfp2
= (REGFILTERPINS2
*) CoTaskMemAlloc(prf2
->u
.s
.cPins
* sizeof(REGFILTERPINS2
));
710 regfilter2
.u
.s1
.rgPins2
= pregfp2
;
711 for (i
= 0; i
< prf2
->u
.s
.cPins
; i
++)
714 if (prf2
->u
.s
.rgPins
[i
].bRendered
)
715 flags
|= REG_PINFLAG_B_RENDERER
;
716 if (prf2
->u
.s
.rgPins
[i
].bOutput
)
717 flags
|= REG_PINFLAG_B_OUTPUT
;
718 if (prf2
->u
.s
.rgPins
[i
].bZero
)
719 flags
|= REG_PINFLAG_B_ZERO
;
720 if (prf2
->u
.s
.rgPins
[i
].bMany
)
721 flags
|= REG_PINFLAG_B_MANY
;
722 pregfp2
[i
].dwFlags
= flags
;
723 pregfp2
[i
].cInstances
= 1;
724 pregfp2
[i
].nMediaTypes
= prf2
->u
.s
.rgPins
[i
].nMediaTypes
;
725 pregfp2
[i
].lpMediaType
= prf2
->u
.s
.rgPins
[i
].lpMediaType
;
726 pregfp2
[i
].nMediums
= 0;
727 pregfp2
[i
].lpMedium
= NULL
;
728 pregfp2
[i
].clsPinCategory
= NULL
;
733 FIXME("dwVersion other that 1 or 2 not supported at the moment\n");
741 /* MSDN mentions the inexistent CLSID_ActiveMovieFilters GUID.
742 * In fact this is the CLSID_LegacyAmFilterCategory one */
743 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
745 /* sizeof... will include the null terminator and
746 * the + 1 is for the separator ('\\'). The -1 is
747 * because CHARS_IN_GUID includes the null terminator
749 nameLen
= sizeof(wszDevice
)/sizeof(wszDevice
[0]) + CHARS_IN_GUID
- 1 + 1;
752 nameLen
+= strlenW(szInstance
);
754 nameLen
+= CHARS_IN_GUID
- 1; /* CHARS_IN_GUID includes null terminator */
756 pCurrent
= pwszParseName
= CoTaskMemAlloc(nameLen
*sizeof(WCHAR
));
758 return E_OUTOFMEMORY
;
760 strcpyW(pwszParseName
, wszDevice
);
761 pCurrent
+= strlenW(wszDevice
);
763 hr
= StringFromCLSID(pclsidCategory
, &szClsidTemp
);
767 memcpy(pCurrent
, szClsidTemp
, CHARS_IN_GUID
* sizeof(WCHAR
));
768 pCurrent
+= CHARS_IN_GUID
- 1;
772 strcpyW(pCurrent
+1, szInstance
);
775 CoTaskMemFree(szClsidTemp
);
778 hr
= StringFromCLSID(clsidFilter
, &szClsidTemp
);
780 strcpyW(pCurrent
+1, szClsidTemp
);
785 hr
= CoCreateInstance(&CLSID_CDeviceMoniker
, NULL
, CLSCTX_INPROC
, &IID_IParseDisplayName
, (LPVOID
*)&pParser
);
788 hr
= CreateBindCtx(0, &pBindCtx
);
791 hr
= IParseDisplayName_ParseDisplayName(pParser
, pBindCtx
, pwszParseName
, &ulEaten
, &pMoniker
);
794 IBindCtx_Release(pBindCtx
);
796 IParseDisplayName_Release(pParser
);
799 hr
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
802 hr
= FM2_WriteFriendlyName(pPropBag
, szName
);
805 hr
= FM2_WriteClsid(pPropBag
, clsidFilter
);
812 hr
= FM2_WriteFilterData(®filter2
, &pData
, &cbData
);
817 SAFEARRAYBOUND saBound
;
820 saBound
.cElements
= cbData
;
821 psa
= SafeArrayCreate(VT_UI1
, 1, &saBound
);
824 ERR("Couldn't create SAFEARRAY\n");
831 hr
= SafeArrayAccessData(psa
, (LPVOID
*)&pbSAData
);
834 memcpy(pbSAData
, pData
, cbData
);
835 hr
= SafeArrayUnaccessData(psa
);
839 V_VT(&var
) = VT_ARRAY
| VT_UI1
;
840 V_UNION(&var
, parray
) = psa
;
843 hr
= IPropertyBag_Write(pPropBag
, wszFilterDataName
, &var
);
846 SafeArrayDestroy(psa
);
847 CoTaskMemFree(pData
);
852 IPropertyBag_Release(pPropBag
);
853 CoTaskMemFree(szClsidTemp
);
855 if (SUCCEEDED(hr
) && ppMoniker
)
856 *ppMoniker
= pMoniker
;
858 IMoniker_Release(pMoniker
);
860 CoTaskMemFree(pregfp2
);
862 TRACE("-- returning %x\n", hr
);
867 /* internal helper function */
868 static BOOL
MatchTypes(
871 const REGPINTYPES
* pPinTypes
,
873 const GUID
* pMatchTypes
)
878 if ((nMatchTypes
== 0) && (nPinTypes
> 0))
881 for (j
= 0; j
< nPinTypes
; j
++)
884 for (i
= 0; i
< nMatchTypes
*2; i
+=2)
886 if (((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMajorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMajorType
, &pMatchTypes
[i
])) &&
887 ((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMinorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
+1], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMinorType
, &pMatchTypes
[i
+1])))
897 /* internal helper function for qsort of MONIKER_MERIT array */
898 static int mm_compare(const void * left
, const void * right
)
900 const struct MONIKER_MERIT
* mmLeft
= (const struct MONIKER_MERIT
*)left
;
901 const struct MONIKER_MERIT
* mmRight
= (const struct MONIKER_MERIT
*)right
;
903 if (mmLeft
->dwMerit
== mmRight
->dwMerit
)
905 if (mmLeft
->dwMerit
> mmRight
->dwMerit
)
911 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
912 * (GUID_NULL's in input to function automatically treated as wild cards)
913 * Input/Output needed means match only on criteria if TRUE (with zero input types
914 * meaning match any input/output pin as long as one exists), otherwise match any
915 * filter that meets the rest of the requirements.
917 static HRESULT WINAPI
FilterMapper2_EnumMatchingFilters(
918 IFilterMapper2
* iface
,
919 IEnumMoniker
**ppEnum
,
925 const GUID
*pInputTypes
,
926 const REGPINMEDIUM
*pMedIn
,
927 const CLSID
*pPinCategoryIn
,
931 const GUID
*pOutputTypes
,
932 const REGPINMEDIUM
*pMedOut
,
933 const CLSID
*pPinCategoryOut
)
935 ICreateDevEnum
* pCreateDevEnum
;
936 IMoniker
* pMonikerCat
;
937 IEnumMoniker
* pEnumCat
;
939 struct Vector monikers
= {NULL
, 0, 0};
941 TRACE("(%p, %x, %s, %x, %s, %d, %p, %p, %p, %s, %s, %p, %p, %p)\n",
944 bExactMatch
? "true" : "false",
946 bInputNeeded
? "true" : "false",
951 bRender
? "true" : "false",
952 bOutputNeeded
? "true" : "false",
959 FIXME("dwFlags = %x not implemented\n", dwFlags
);
964 hr
= CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (LPVOID
*)&pCreateDevEnum
);
967 hr
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &CLSID_ActiveMovieCategories
, &pEnumCat
, 0);
969 while (IEnumMoniker_Next(pEnumCat
, 1, &pMonikerCat
, NULL
) == S_OK
)
971 IPropertyBag
* pPropBagCat
= NULL
;
973 HRESULT hrSub
; /* this is so that one buggy filter
974 doesn't make the whole lot fail */
978 hrSub
= IMoniker_BindToStorage(pMonikerCat
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
980 if (SUCCEEDED(hrSub
))
981 hrSub
= IPropertyBag_Read(pPropBagCat
, wszMeritName
, &var
, NULL
);
983 if (SUCCEEDED(hrSub
) && (V_UNION(&var
, ulVal
) >= dwMerit
))
986 IEnumMoniker
* pEnum
;
991 if (TRACE_ON(quartz
))
994 V_VT(&temp
) = VT_EMPTY
;
995 IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &temp
, NULL
);
996 TRACE("Considering category %s\n", debugstr_w(V_UNION(&temp
, bstrVal
)));
1000 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
1002 if (SUCCEEDED(hrSub
))
1003 hrSub
= CLSIDFromString(V_UNION(&var
, bstrVal
), &clsidCat
);
1005 if (SUCCEEDED(hrSub
))
1006 hrSub
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &clsidCat
, &pEnum
, 0);
1010 while (IEnumMoniker_Next(pEnum
, 1, &pMoniker
, NULL
) == S_OK
)
1012 IPropertyBag
* pPropBag
= NULL
;
1017 BOOL bInputMatch
= !bInputNeeded
;
1018 BOOL bOutputMatch
= !bOutputNeeded
;
1020 ZeroMemory(&rf2
, sizeof(rf2
));
1023 hrSub
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBag
);
1025 if (TRACE_ON(quartz
))
1028 V_VT(&temp
) = VT_EMPTY
;
1029 IPropertyBag_Read(pPropBag
, wszFriendlyName
, &temp
, NULL
);
1030 TRACE("Considering filter %s\n", debugstr_w(V_UNION(&temp
, bstrVal
)));
1031 VariantClear(&temp
);
1034 if (SUCCEEDED(hrSub
))
1036 V_VT(&var
) = VT_ARRAY
| VT_UI1
;
1037 hrSub
= IPropertyBag_Read(pPropBag
, wszFilterDataName
, &var
, NULL
);
1040 if (SUCCEEDED(hrSub
))
1041 hrSub
= SafeArrayAccessData(V_UNION(&var
, parray
), (LPVOID
*)&pData
);
1043 if (SUCCEEDED(hrSub
))
1044 hrSub
= FM2_ReadFilterData(pData
, &rf2
);
1047 SafeArrayUnaccessData(V_UNION(&var
, parray
));
1051 /* Logic used for bInputMatch expression:
1052 * There exists some pin such that bInputNeeded implies (pin is an input and
1053 * (bRender implies pin has render flag) and major/minor types members of
1055 * bOutputMatch is similar, but without the "bRender implies ..." part
1056 * and substituting variables names containing input for output
1059 /* determine whether filter meets requirements */
1060 if (SUCCEEDED(hrSub
) && (rf2
.dwMerit
>= dwMerit
))
1062 for (i
= 0; (i
< rf2
.u
.s1
.cPins2
) && (!bInputMatch
|| !bOutputMatch
); i
++)
1064 const REGFILTERPINS2
* rfp2
= rf2
.u
.s1
.rgPins2
+ i
;
1066 bInputMatch
= bInputMatch
|| (!(rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1067 (!bRender
|| (rfp2
->dwFlags
& REG_PINFLAG_B_RENDERER
)) &&
1068 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cInputTypes
, pInputTypes
));
1069 bOutputMatch
= bOutputMatch
|| ((rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1070 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cOutputTypes
, pOutputTypes
));
1073 if (bInputMatch
&& bOutputMatch
)
1075 struct MONIKER_MERIT mm
= {pMoniker
, rf2
.dwMerit
};
1076 IMoniker_AddRef(pMoniker
);
1077 add_data(&monikers
, (LPBYTE
)&mm
, sizeof(mm
));
1081 FM2_DeleteRegFilter(&rf2
);
1083 IPropertyBag_Release(pPropBag
);
1084 IMoniker_Release(pMoniker
);
1086 IEnumMoniker_Release(pEnum
);
1092 IPropertyBag_Release(pPropBagCat
);
1093 IMoniker_Release(pMonikerCat
);
1098 IMoniker
** ppMoniker
;
1100 ULONG nMonikerCount
= monikers
.current
/ sizeof(struct MONIKER_MERIT
);
1102 /* sort the monikers in descending merit order */
1103 qsort(monikers
.pData
, nMonikerCount
,
1104 sizeof(struct MONIKER_MERIT
),
1107 /* construct an IEnumMoniker interface */
1108 ppMoniker
= CoTaskMemAlloc(nMonikerCount
* sizeof(IMoniker
*));
1109 for (i
= 0; i
< nMonikerCount
; i
++)
1111 /* no need to AddRef here as already AddRef'd above */
1112 ppMoniker
[i
] = ((struct MONIKER_MERIT
*)monikers
.pData
)[i
].pMoniker
;
1114 hr
= EnumMonikerImpl_Create(ppMoniker
, nMonikerCount
, ppEnum
);
1115 CoTaskMemFree(ppMoniker
);
1118 delete_vector(&monikers
);
1119 IEnumMoniker_Release(pEnumCat
);
1120 ICreateDevEnum_Release(pCreateDevEnum
);
1125 static const IFilterMapper2Vtbl fm2vtbl
=
1128 FilterMapper2_QueryInterface
,
1129 FilterMapper2_AddRef
,
1130 FilterMapper2_Release
,
1132 FilterMapper2_CreateCategory
,
1133 FilterMapper2_UnregisterFilter
,
1134 FilterMapper2_RegisterFilter
,
1135 FilterMapper2_EnumMatchingFilters
1138 /*** IUnknown methods ***/
1140 static HRESULT WINAPI
FilterMapper_QueryInterface(IFilterMapper
* iface
, REFIID riid
, LPVOID
*ppv
)
1142 FilterMapper2Impl
*This
= impl_from_IFilterMapper(iface
);
1144 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1146 return FilterMapper2_QueryInterface((IFilterMapper2
*)&This
->lpVtbl
, riid
, ppv
);
1149 static ULONG WINAPI
FilterMapper_AddRef(IFilterMapper
* iface
)
1151 FilterMapper2Impl
*This
= impl_from_IFilterMapper(iface
);
1153 return FilterMapper2_AddRef((IFilterMapper2
*)This
);
1156 static ULONG WINAPI
FilterMapper_Release(IFilterMapper
* iface
)
1158 FilterMapper2Impl
*This
= impl_from_IFilterMapper(iface
);
1160 return FilterMapper2_Release((IFilterMapper2
*)This
);
1163 /*** IFilterMapper methods ***/
1165 static HRESULT WINAPI
FilterMapper_EnumMatchingFilters(
1166 IFilterMapper
* iface
,
1167 IEnumRegFilters
**ppEnum
,
1177 FilterMapper2Impl
*This
= impl_from_IFilterMapper(iface
);
1180 IEnumMoniker
* ppEnumMoniker
;
1183 ULONG idx
= 0, nb_mon
= 0;
1184 REGFILTER
* regfilters
;
1187 TRACE("(%p/%p)->(%p, %x, %s, %s, %s, %s, %s, %s, %s) stub!\n",
1191 bInputNeeded
? "true" : "false",
1192 debugstr_guid(&clsInMaj
),
1193 debugstr_guid(&clsInSub
),
1194 bRender
? "true" : "false",
1195 bOutputNeeded
? "true" : "false",
1196 debugstr_guid(&clsOutMaj
),
1197 debugstr_guid(&clsOutSub
));
1199 InputType
[0] = clsInMaj
;
1200 InputType
[1] = clsInSub
;
1201 OutputType
[0] = clsOutMaj
;
1202 OutputType
[1] = clsOutSub
;
1204 hr
= IFilterMapper2_EnumMatchingFilters((IFilterMapper2
*)This
,
1224 while(IEnumMoniker_Next(ppEnumMoniker
, 1, &IMon
, &nb
) == S_OK
)
1226 IMoniker_Release(IMon
);
1233 IEnumMoniker_Release(ppEnumMoniker
);
1234 return IEnumRegFiltersImpl_Construct(NULL
, 0, ppEnum
);
1237 regfilters
= CoTaskMemAlloc(nb_mon
* sizeof(REGFILTER
));
1240 IEnumMoniker_Release(ppEnumMoniker
);
1241 return E_OUTOFMEMORY
;
1244 IEnumMoniker_Reset(ppEnumMoniker
);
1245 while(IEnumMoniker_Next(ppEnumMoniker
, 1, &IMon
, &nb
) == S_OK
)
1247 IPropertyBag
* pPropBagCat
= NULL
;
1254 V_VT(&var
) = VT_BSTR
;
1256 hrSub
= IMoniker_BindToStorage(IMon
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
1258 if (SUCCEEDED(hrSub
))
1259 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
1261 if (SUCCEEDED(hrSub
))
1262 hrSub
= CLSIDFromString(V_UNION(&var
, bstrVal
), &clsid
);
1264 if (SUCCEEDED(hrSub
))
1265 hrSub
= IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &var
, NULL
);
1267 if (SUCCEEDED(hrSub
))
1269 len
= (strlenW((WCHAR
*)&V_UNION(&var
, bstrVal
))+1) * sizeof(WCHAR
);
1270 if (!(regfilters
[idx
].Name
= CoTaskMemAlloc(len
*2)))
1274 if (SUCCEEDED(hrSub
))
1276 memcpy(regfilters
[idx
].Name
, &V_UNION(&var
, bstrVal
), len
);
1277 regfilters
[idx
].Clsid
= clsid
;
1282 IPropertyBag_Release(pPropBagCat
);
1283 IMoniker_Release(IMon
);
1286 /* In case of release all resources */
1289 for (idx
= 0; idx
< nb_mon
; idx
++)
1290 CoTaskMemFree(regfilters
[idx
].Name
);
1291 CoTaskMemFree(regfilters
);
1292 IEnumMoniker_Release(ppEnumMoniker
);
1296 hr
= IEnumRegFiltersImpl_Construct(regfilters
, nb_mon
, ppEnum
);
1297 CoTaskMemFree(regfilters
);
1298 IEnumMoniker_Release(ppEnumMoniker
);
1304 static HRESULT WINAPI
FilterMapper_RegisterFilter(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, DWORD dwMerit
)
1307 LPWSTR wszClsid
= NULL
;
1310 WCHAR wszKeyName
[strlenW(wszFilterSlash
) + (CHARS_IN_GUID
-1) + 1];
1312 TRACE("(%p)->(%s, %s, %x)\n", iface
, debugstr_guid(&clsid
), debugstr_w(szName
), dwMerit
);
1314 hr
= StringFromCLSID(&clsid
, &wszClsid
);
1318 strcpyW(wszKeyName
, wszFilterSlash
);
1319 strcatW(wszKeyName
, wszClsid
);
1321 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
1322 hr
= HRESULT_FROM_WIN32(lRet
);
1327 lRet
= RegSetValueExW(hKey
, NULL
, 0, REG_SZ
, (const BYTE
*)szName
, strlenW(szName
) + 1);
1328 hr
= HRESULT_FROM_WIN32(lRet
);
1334 strcpyW(wszKeyName
, wszClsidSlash
);
1335 strcatW(wszKeyName
, wszClsid
);
1337 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
1338 hr
= HRESULT_FROM_WIN32(lRet
);
1343 lRet
= RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwMerit
, sizeof(dwMerit
));
1344 hr
= HRESULT_FROM_WIN32(lRet
);
1351 static HRESULT WINAPI
FilterMapper_RegisterFilterInstance(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, CLSID
*MRId
)
1353 TRACE("(%p)->(%s, %s, %p)\n", iface
, debugstr_guid(&clsid
), debugstr_w(szName
), MRId
);
1355 /* Not implemented in Windows (tested on Win2k) */
1360 static HRESULT WINAPI
FilterMapper_RegisterPin(
1361 IFilterMapper
* iface
,
1368 CLSID ConnectsToFilter
,
1369 LPCWSTR ConnectsToPin
)
1373 LPWSTR wszClsid
= NULL
;
1375 HKEY hPinsKey
= NULL
;
1376 WCHAR
* wszPinsKeyName
;
1377 WCHAR wszKeyName
[strlenW(wszClsidSlash
) + (CHARS_IN_GUID
-1) + 1];
1379 TRACE("(%p)->(%s, %s, %d, %d, %d, %d, %s, %s)\n", iface
, debugstr_guid(&Filter
), debugstr_w(szName
), bRendered
,
1380 bOutput
, bZero
, bMany
, debugstr_guid(&ConnectsToFilter
), debugstr_w(ConnectsToPin
));
1382 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1386 strcpyW(wszKeyName
, wszClsidSlash
);
1387 strcatW(wszKeyName
, wszClsid
);
1389 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1390 hr
= HRESULT_FROM_WIN32(lRet
);
1395 wszPinsKeyName
= CoTaskMemAlloc((strlenW(wszPins
) + 1 + strlenW(szName
) + 1) * 2);
1396 if (!wszPinsKeyName
)
1402 strcpyW(wszPinsKeyName
, wszPins
);
1403 strcatW(wszPinsKeyName
, wszSlash
);
1404 strcatW(wszPinsKeyName
, szName
);
1406 lRet
= RegCreateKeyExW(hKey
, wszPinsKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hPinsKey
, NULL
);
1407 hr
= HRESULT_FROM_WIN32(lRet
);
1408 CoTaskMemFree(wszPinsKeyName
);
1413 lRet
= RegSetValueExW(hPinsKey
, wszAllowedMany
, 0, REG_DWORD
, (LPBYTE
)&bMany
, sizeof(bMany
));
1414 hr
= HRESULT_FROM_WIN32(lRet
);
1419 lRet
= RegSetValueExW(hPinsKey
, wszAllowedZero
, 0, REG_DWORD
, (LPBYTE
)&bZero
, sizeof(bZero
));
1420 hr
= HRESULT_FROM_WIN32(lRet
);
1425 lRet
= RegSetValueExW(hPinsKey
, wszDirection
, 0, REG_DWORD
, (LPBYTE
)&bOutput
, sizeof(bOutput
));
1426 hr
= HRESULT_FROM_WIN32(lRet
);
1431 lRet
= RegSetValueExW(hPinsKey
, wszIsRendered
, 0, REG_DWORD
, (LPBYTE
)&bRendered
, sizeof(bRendered
));
1432 hr
= HRESULT_FROM_WIN32(lRet
);
1437 lRet
= RegCreateKeyExW(hPinsKey
, wszTypes
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, NULL
, NULL
);
1438 hr
= HRESULT_FROM_WIN32(lRet
);
1441 CoTaskMemFree(wszClsid
);
1445 CloseHandle(hPinsKey
);
1451 static HRESULT WINAPI
FilterMapper_RegisterPinType(
1452 IFilterMapper
* iface
,
1460 LPWSTR wszClsid
= NULL
;
1461 LPWSTR wszClsidMajorType
= NULL
;
1462 LPWSTR wszClsidSubType
= NULL
;
1464 WCHAR
* wszTypesKey
;
1465 WCHAR wszKeyName
[strlenW(wszClsidSlash
) + (CHARS_IN_GUID
-1) + 1];
1467 TRACE("(%p)->(%s, %s, %s, %s)\n", iface
, debugstr_guid(&clsFilter
), debugstr_w(szName
),
1468 debugstr_guid(&clsMajorType
), debugstr_guid(&clsSubType
));
1470 hr
= StringFromCLSID(&clsFilter
, &wszClsid
);
1474 hr
= StringFromCLSID(&clsMajorType
, &wszClsidMajorType
);
1479 hr
= StringFromCLSID(&clsSubType
, &wszClsidSubType
);
1484 wszTypesKey
= CoTaskMemAlloc((strlenW(wszClsidSlash
) + strlenW(wszClsid
) + strlenW(wszPins
) +
1485 strlenW(szName
) + strlenW(wszTypes
) + 3 + 1) * 2);
1492 strcpyW(wszTypesKey
, wszClsidSlash
);
1493 strcatW(wszTypesKey
, wszClsid
);
1494 strcatW(wszTypesKey
, wszSlash
);
1495 strcatW(wszTypesKey
, wszPins
);
1496 strcatW(wszTypesKey
, wszSlash
);
1497 strcatW(wszTypesKey
, szName
);
1498 strcatW(wszTypesKey
, wszSlash
);
1499 strcatW(wszTypesKey
, wszTypes
);
1501 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszTypesKey
, 0, KEY_WRITE
, &hKey
);
1502 hr
= HRESULT_FROM_WIN32(lRet
);
1503 CoTaskMemFree(wszTypesKey
);
1508 strcpyW(wszKeyName
, wszClsidMajorType
);
1509 strcatW(wszKeyName
, wszSlash
);
1510 strcatW(wszKeyName
, wszClsidSubType
);
1512 lRet
= RegCreateKeyExW(hKey
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, NULL
, NULL
);
1513 hr
= HRESULT_FROM_WIN32(lRet
);
1517 CoTaskMemFree(wszClsid
);
1518 CoTaskMemFree(wszClsidMajorType
);
1519 CoTaskMemFree(wszClsidSubType
);
1524 static HRESULT WINAPI
FilterMapper_UnregisterFilter(IFilterMapper
* iface
, CLSID Filter
)
1528 LPWSTR wszClsid
= NULL
;
1530 WCHAR wszKeyName
[strlenW(wszClsidSlash
) + (CHARS_IN_GUID
-1) + 1];
1532 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(&Filter
));
1534 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1538 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszFilter
, 0, KEY_WRITE
, &hKey
);
1539 hr
= HRESULT_FROM_WIN32(lRet
);
1544 lRet
= RegDeleteKeyW(hKey
, wszClsid
);
1545 hr
= HRESULT_FROM_WIN32(lRet
);
1551 strcpyW(wszKeyName
, wszClsidSlash
);
1552 strcatW(wszKeyName
, wszClsid
);
1554 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1555 hr
= HRESULT_FROM_WIN32(lRet
);
1560 lRet
= RegDeleteKeyW(hKey
, wszMeritName
);
1561 hr
= HRESULT_FROM_WIN32(lRet
);
1565 CoTaskMemFree(wszClsid
);
1570 static HRESULT WINAPI
FilterMapper_UnregisterFilterInstance(IFilterMapper
* iface
, CLSID MRId
)
1572 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(&MRId
));
1574 /* Not implemented in Windows (tested on Win2k) */
1579 static HRESULT WINAPI
FilterMapper_UnregisterPin(IFilterMapper
* iface
, CLSID Filter
, LPCWSTR Name
)
1583 LPWSTR wszClsid
= NULL
;
1585 WCHAR
* wszPinNameKey
;
1586 WCHAR wszKeyName
[strlenW(wszClsidSlash
) + (CHARS_IN_GUID
-1) + 1];
1588 TRACE("(%p)->(%s, %s)\n", iface
, debugstr_guid(&Filter
), debugstr_w(Name
));
1591 return E_INVALIDARG
;
1593 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1597 strcpyW(wszKeyName
, wszClsidSlash
);
1598 strcatW(wszKeyName
, wszClsid
);
1600 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1601 hr
= HRESULT_FROM_WIN32(lRet
);
1606 wszPinNameKey
= CoTaskMemAlloc((strlenW(wszPins
) + 1 + strlenW(Name
) + 1) * 2);
1613 strcpyW(wszPinNameKey
, wszPins
);
1614 strcatW(wszPinNameKey
, wszSlash
);
1615 strcatW(wszPinNameKey
, Name
);
1617 lRet
= RegDeleteKeyW(hKey
, wszPinNameKey
);
1618 hr
= HRESULT_FROM_WIN32(lRet
);
1619 CoTaskMemFree(wszPinNameKey
);
1622 CoTaskMemFree(wszClsid
);
1629 static const IFilterMapperVtbl fmvtbl
=
1632 FilterMapper_QueryInterface
,
1633 FilterMapper_AddRef
,
1634 FilterMapper_Release
,
1636 FilterMapper_RegisterFilter
,
1637 FilterMapper_RegisterFilterInstance
,
1638 FilterMapper_RegisterPin
,
1639 FilterMapper_RegisterPinType
,
1640 FilterMapper_UnregisterFilter
,
1641 FilterMapper_UnregisterFilterInstance
,
1642 FilterMapper_UnregisterPin
,
1643 FilterMapper_EnumMatchingFilters
1647 /*** IUnknown methods ***/
1648 static HRESULT WINAPI
AMFilterData_QueryInterface(IAMFilterData
* iface
, REFIID riid
, LPVOID
*ppv
)
1650 FilterMapper2Impl
*This
= impl_from_IAMFilterData(iface
);
1652 return FilterMapper2_QueryInterface((IFilterMapper2
*)This
, riid
, ppv
);
1655 static ULONG WINAPI
AMFilterData_AddRef(IAMFilterData
* iface
)
1657 FilterMapper2Impl
*This
= impl_from_IAMFilterData(iface
);
1659 return FilterMapper2_AddRef((IFilterMapper2
*)This
);
1662 static ULONG WINAPI
AMFilterData_Release(IAMFilterData
* iface
)
1664 FilterMapper2Impl
*This
= impl_from_IAMFilterData(iface
);
1666 return FilterMapper2_Release((IFilterMapper2
*)This
);
1669 /*** IAMFilterData methods ***/
1670 static HRESULT WINAPI
AMFilterData_ParseFilterData(IAMFilterData
* iface
,
1671 BYTE
*pData
, ULONG cb
,
1672 BYTE
**ppRegFilter2
)
1674 FilterMapper2Impl
*This
= impl_from_IAMFilterData(iface
);
1678 TRACE("(%p/%p)->(%p, %d, %p)\n", This
, iface
, pData
, cb
, ppRegFilter2
);
1680 prf2
= CoTaskMemAlloc(sizeof(*prf2
));
1682 return E_OUTOFMEMORY
;
1683 *ppRegFilter2
= (BYTE
*)&prf2
;
1685 hr
= FM2_ReadFilterData(pData
, prf2
);
1688 CoTaskMemFree(prf2
);
1689 *ppRegFilter2
= NULL
;
1695 static HRESULT WINAPI
AMFilterData_CreateFilterData(IAMFilterData
* iface
,
1697 BYTE
**pRegFilterData
,
1700 FilterMapper2Impl
*This
= impl_from_IAMFilterData(iface
);
1702 TRACE("(%p/%p)->(%p, %p, %p)\n", This
, iface
, prf2
, pRegFilterData
, pcb
);
1704 return FM2_WriteFilterData(prf2
, pRegFilterData
, pcb
);
1707 static const IAMFilterDataVtbl AMFilterDataVtbl
= {
1708 AMFilterData_QueryInterface
,
1709 AMFilterData_AddRef
,
1710 AMFilterData_Release
,
1711 AMFilterData_ParseFilterData
,
1712 AMFilterData_CreateFilterData