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 const IFilterMapper3Vtbl
*lpVtbl
;
92 const IFilterMapperVtbl
*lpVtblFilterMapper
;
93 const IAMFilterDataVtbl
*lpVtblAMFilterData
;
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_IFilterMapper( IFilterMapper
*iface
)
108 return (FilterMapper3Impl
*)((char*)iface
- FIELD_OFFSET(FilterMapper3Impl
, lpVtblFilterMapper
));
111 static inline FilterMapper3Impl
*impl_from_IAMFilterData( IAMFilterData
*iface
)
113 return (FilterMapper3Impl
*)((char*)iface
- FIELD_OFFSET(FilterMapper3Impl
, lpVtblAMFilterData
));
116 static inline FilterMapper3Impl
*impl_from_inner_IUnknown( IUnknown
*iface
)
118 return (FilterMapper3Impl
*)((char*)iface
- FIELD_OFFSET(FilterMapper3Impl
, IInner_vtbl
));
121 static const WCHAR wszClsidSlash
[] = {'C','L','S','I','D','\\',0};
122 static const WCHAR wszSlashInstance
[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
123 static const WCHAR wszSlash
[] = {'\\',0};
125 /* CLSID property in media category Moniker */
126 static const WCHAR wszClsidName
[] = {'C','L','S','I','D',0};
127 /* FriendlyName property in media category Moniker */
128 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
129 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
130 static const WCHAR wszMeritName
[] = {'M','e','r','i','t',0};
131 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
132 static const WCHAR wszFilterDataName
[] = {'F','i','l','t','e','r','D','a','t','a',0};
133 /* For filters registered with IFilterMapper */
134 static const WCHAR wszFilterSlash
[] = {'F','i','l','t','e','r','\\',0};
135 static const WCHAR wszFilter
[] = {'F','i','l','t','e','r',0};
136 /* For pins registered with IFilterMapper */
137 static const WCHAR wszPins
[] = {'P','i','n','s',0};
138 static const WCHAR wszAllowedMany
[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
139 static const WCHAR wszAllowedZero
[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
140 static const WCHAR wszDirection
[] = {'D','i','r','e','c','t','i','o','n',0};
141 static const WCHAR wszIsRendered
[] = {'I','s','R','e','n','d','e','r','e','d',0};
142 /* For types registered with IFilterMapper */
143 static const WCHAR wszTypes
[] = {'T','y','p','e','s',0};
146 /* registry format for REGFILTER2 */
157 BYTE signature
[4]; /* e.g. "0pi3" */
162 DWORD bCategory
; /* is there a category clsid? */
163 /* optional: dwOffsetCategoryClsid */
168 BYTE signature
[4]; /* e.g. "0ty3" */
183 int capacity
; /* in bytes */
184 int current
; /* pointer to next free byte */
187 /* returns the position it was added at */
188 static int add_data(struct Vector
* v
, const BYTE
* pData
, int size
)
190 int index
= v
->current
;
191 if (v
->current
+ size
> v
->capacity
)
193 LPBYTE pOldData
= v
->pData
;
194 v
->capacity
= (v
->capacity
+ size
) * 2;
195 v
->pData
= CoTaskMemAlloc(v
->capacity
);
196 memcpy(v
->pData
, pOldData
, v
->current
);
197 CoTaskMemFree(pOldData
);
199 memcpy(v
->pData
+ v
->current
, pData
, size
);
204 static int find_data(const struct Vector
* v
, const BYTE
* pData
, int size
)
207 for (index
= 0; index
< v
->current
; index
++)
208 if (!memcmp(v
->pData
+ index
, pData
, size
))
214 static void delete_vector(struct Vector
* v
)
216 CoTaskMemFree(v
->pData
);
221 HRESULT
FilterMapper2_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
223 FilterMapper3Impl
* pFM2impl
;
225 TRACE("(%p, %p)\n", pUnkOuter
, ppObj
);
227 pFM2impl
= CoTaskMemAlloc(sizeof(*pFM2impl
));
229 return E_OUTOFMEMORY
;
231 pFM2impl
->pUnkOuter
= pUnkOuter
;
232 pFM2impl
->bUnkOuterValid
= FALSE
;
233 pFM2impl
->bAggregatable
= FALSE
;
234 pFM2impl
->IInner_vtbl
= &IInner_VTable
;
235 pFM2impl
->lpVtbl
= &fm3vtbl
;
236 pFM2impl
->lpVtblFilterMapper
= &fmvtbl
;
237 pFM2impl
->lpVtblAMFilterData
= &AMFilterDataVtbl
;
238 pFM2impl
->refCount
= 1;
242 TRACE("-- created at %p\n", pFM2impl
);
247 HRESULT
FilterMapper_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
249 FilterMapper3Impl
*pFM2impl
;
252 TRACE("(%p, %p)\n", pUnkOuter
, ppObj
);
254 hr
= FilterMapper2_create(pUnkOuter
, (LPVOID
*)&pFM2impl
);
258 *ppObj
= &pFM2impl
->lpVtblFilterMapper
;
263 /*** IUnknown (inner) methods ***/
265 static HRESULT WINAPI
Inner_QueryInterface(IUnknown
* iface
, REFIID riid
, LPVOID
* ppv
)
267 FilterMapper3Impl
*This
= impl_from_inner_IUnknown(iface
);
268 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
270 if (This
->bAggregatable
)
271 This
->bUnkOuterValid
= TRUE
;
275 if (IsEqualIID(riid
, &IID_IUnknown
))
276 *ppv
= &This
->IInner_vtbl
;
277 else if (IsEqualIID(riid
, &IID_IFilterMapper2
) ||
278 IsEqualIID(riid
, &IID_IFilterMapper3
))
280 else if (IsEqualIID(riid
, &IID_IFilterMapper
))
281 *ppv
= &This
->lpVtblFilterMapper
;
282 else if (IsEqualIID(riid
, &IID_IAMFilterData
))
283 *ppv
= &This
->lpVtblAMFilterData
;
287 IUnknown_AddRef((IUnknown
*)*ppv
);
291 FIXME("No interface for %s\n", debugstr_guid(riid
));
292 return E_NOINTERFACE
;
295 static ULONG WINAPI
Inner_AddRef(IUnknown
* iface
)
297 FilterMapper3Impl
*This
= impl_from_inner_IUnknown(iface
);
298 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
300 TRACE("(%p)->() AddRef from %d\n", This
, refCount
- 1);
305 static ULONG WINAPI
Inner_Release(IUnknown
* iface
)
307 FilterMapper3Impl
*This
= impl_from_inner_IUnknown(iface
);
308 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
310 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
320 static const IUnknownVtbl IInner_VTable
=
322 Inner_QueryInterface
,
327 static HRESULT WINAPI
FilterMapper3_QueryInterface(IFilterMapper3
* iface
, REFIID riid
, LPVOID
*ppv
)
329 FilterMapper3Impl
*This
= (FilterMapper3Impl
*)iface
;
331 if (This
->bAggregatable
)
332 This
->bUnkOuterValid
= TRUE
;
336 if (This
->bAggregatable
)
337 return IUnknown_QueryInterface(This
->pUnkOuter
, riid
, ppv
);
339 if (IsEqualIID(riid
, &IID_IUnknown
))
343 IUnknown_AddRef((IUnknown
*)&(This
->IInner_vtbl
));
344 hr
= IUnknown_QueryInterface((IUnknown
*)&(This
->IInner_vtbl
), riid
, ppv
);
345 IUnknown_Release((IUnknown
*)&(This
->IInner_vtbl
));
346 This
->bAggregatable
= TRUE
;
351 return E_NOINTERFACE
;
354 return IUnknown_QueryInterface((IUnknown
*)&(This
->IInner_vtbl
), riid
, ppv
);
357 static ULONG WINAPI
FilterMapper3_AddRef(IFilterMapper3
* iface
)
359 FilterMapper3Impl
*This
= (FilterMapper3Impl
*)iface
;
361 if (This
->pUnkOuter
&& This
->bUnkOuterValid
)
362 return IUnknown_AddRef(This
->pUnkOuter
);
363 return IUnknown_AddRef((IUnknown
*)&(This
->IInner_vtbl
));
366 static ULONG WINAPI
FilterMapper3_Release(IFilterMapper3
* iface
)
368 FilterMapper3Impl
*This
= (FilterMapper3Impl
*)iface
;
370 if (This
->pUnkOuter
&& This
->bUnkOuterValid
)
371 return IUnknown_Release(This
->pUnkOuter
);
372 return IUnknown_Release((IUnknown
*)&(This
->IInner_vtbl
));
375 /*** IFilterMapper3 methods ***/
377 static HRESULT WINAPI
FilterMapper3_CreateCategory(
378 IFilterMapper3
* iface
,
379 REFCLSID clsidCategory
,
380 DWORD dwCategoryMerit
,
381 LPCWSTR szDescription
)
383 LPWSTR wClsidAMCat
= NULL
;
384 LPWSTR wClsidCategory
= NULL
;
385 WCHAR wszKeyName
[ARRAYSIZE(wszClsidSlash
)-1 + ARRAYSIZE(wszSlashInstance
)-1 + (CHARS_IN_GUID
-1) * 2 + 1];
390 TRACE("(%s, %x, %s)\n", debugstr_guid(clsidCategory
), dwCategoryMerit
, debugstr_w(szDescription
));
392 hr
= StringFromCLSID(&CLSID_ActiveMovieCategories
, &wClsidAMCat
);
396 hr
= StringFromCLSID(clsidCategory
, &wClsidCategory
);
401 strcpyW(wszKeyName
, wszClsidSlash
);
402 strcatW(wszKeyName
, wClsidAMCat
);
403 strcatW(wszKeyName
, wszSlashInstance
);
404 strcatW(wszKeyName
, wClsidCategory
);
406 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
407 hr
= HRESULT_FROM_WIN32(lRet
);
412 lRet
= RegSetValueExW(hKey
, wszFriendlyName
, 0, REG_SZ
, (const BYTE
*)szDescription
, (strlenW(szDescription
) + 1) * sizeof(WCHAR
));
413 hr
= HRESULT_FROM_WIN32(lRet
);
418 lRet
= RegSetValueExW(hKey
, wszClsidName
, 0, REG_SZ
, (LPBYTE
)wClsidCategory
, (strlenW(wClsidCategory
) + 1) * sizeof(WCHAR
));
419 hr
= HRESULT_FROM_WIN32(lRet
);
424 lRet
= RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwCategoryMerit
, sizeof(dwCategoryMerit
));
425 hr
= HRESULT_FROM_WIN32(lRet
);
429 CoTaskMemFree(wClsidCategory
);
430 CoTaskMemFree(wClsidAMCat
);
435 static HRESULT WINAPI
FilterMapper3_UnregisterFilter(
436 IFilterMapper3
* iface
,
437 const CLSID
*pclsidCategory
,
438 const OLECHAR
*szInstance
,
441 WCHAR wszKeyName
[MAX_PATH
];
442 LPWSTR wClsidCategory
= NULL
;
443 LPWSTR wFilter
= NULL
;
446 TRACE("(%p, %s, %s)\n", pclsidCategory
, debugstr_w(szInstance
), debugstr_guid(Filter
));
449 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
451 hr
= StringFromCLSID(pclsidCategory
, &wClsidCategory
);
455 strcpyW(wszKeyName
, wszClsidSlash
);
456 strcatW(wszKeyName
, wClsidCategory
);
457 strcatW(wszKeyName
, wszSlashInstance
);
459 strcatW(wszKeyName
, szInstance
);
462 hr
= StringFromCLSID(Filter
, &wFilter
);
464 strcatW(wszKeyName
, wFilter
);
470 LONG lRet
= RegDeleteKeyW(HKEY_CLASSES_ROOT
, wszKeyName
);
471 hr
= HRESULT_FROM_WIN32(lRet
);
474 CoTaskMemFree(wClsidCategory
);
475 CoTaskMemFree(wFilter
);
480 static HRESULT
FM2_WriteFriendlyName(IPropertyBag
* pPropBag
, LPCWSTR szName
)
486 V_VT(&var
) = VT_BSTR
;
487 V_UNION(&var
, bstrVal
) = value
= SysAllocString(szName
);
489 ret
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
490 SysFreeString(value
);
495 static HRESULT
FM2_WriteClsid(IPropertyBag
* pPropBag
, REFCLSID clsid
)
497 LPWSTR wszClsid
= NULL
;
501 hr
= StringFromCLSID(clsid
, &wszClsid
);
505 V_VT(&var
) = VT_BSTR
;
506 V_UNION(&var
, bstrVal
) = wszClsid
;
507 hr
= IPropertyBag_Write(pPropBag
, wszClsidName
, &var
);
509 CoTaskMemFree(wszClsid
);
513 static HRESULT
FM2_WriteFilterData(const REGFILTER2
* prf2
, BYTE
**ppData
, ULONG
*pcbData
)
515 int size
= sizeof(struct REG_RF
);
517 struct Vector mainStore
= {NULL
, 0, 0};
518 struct Vector clsidStore
= {NULL
, 0, 0};
522 rrf
.dwVersion
= prf2
->dwVersion
;
523 rrf
.dwMerit
= prf2
->dwMerit
;
524 rrf
.dwPins
= prf2
->u
.s1
.cPins2
;
527 add_data(&mainStore
, (LPBYTE
)&rrf
, sizeof(rrf
));
529 for (i
= 0; i
< prf2
->u
.s1
.cPins2
; i
++)
531 size
+= sizeof(struct REG_RFP
);
532 if (prf2
->u
.s1
.rgPins2
[i
].clsPinCategory
)
533 size
+= sizeof(DWORD
);
534 size
+= prf2
->u
.s1
.rgPins2
[i
].nMediaTypes
* sizeof(struct REG_TYPE
);
535 size
+= prf2
->u
.s1
.rgPins2
[i
].nMediums
* sizeof(DWORD
);
538 for (i
= 0; i
< prf2
->u
.s1
.cPins2
; i
++)
541 REGFILTERPINS2 rgPin2
= prf2
->u
.s1
.rgPins2
[i
];
544 rrfp
.signature
[0] = '0';
545 rrfp
.signature
[1] = 'p';
546 rrfp
.signature
[2] = 'i';
547 rrfp
.signature
[3] = '3';
548 rrfp
.signature
[0] += i
;
549 rrfp
.dwFlags
= rgPin2
.dwFlags
;
550 rrfp
.dwInstances
= rgPin2
.cInstances
;
551 rrfp
.dwMediaTypes
= rgPin2
.nMediaTypes
;
552 rrfp
.dwMediums
= rgPin2
.nMediums
;
553 rrfp
.bCategory
= rgPin2
.clsPinCategory
? 1 : 0;
555 add_data(&mainStore
, (LPBYTE
)&rrfp
, sizeof(rrfp
));
558 DWORD index
= find_data(&clsidStore
, (const BYTE
*)rgPin2
.clsPinCategory
, sizeof(CLSID
));
560 index
= add_data(&clsidStore
, (const BYTE
*)rgPin2
.clsPinCategory
, sizeof(CLSID
));
563 add_data(&mainStore
, (LPBYTE
)&index
, sizeof(index
));
566 for (j
= 0; j
< rgPin2
.nMediaTypes
; j
++)
569 const CLSID
* clsMinorType
= rgPin2
.lpMediaType
[j
].clsMinorType
? rgPin2
.lpMediaType
[j
].clsMinorType
: &MEDIASUBTYPE_NULL
;
570 rt
.signature
[0] = '0';
571 rt
.signature
[1] = 't';
572 rt
.signature
[2] = 'y';
573 rt
.signature
[3] = '3';
574 rt
.signature
[0] += j
;
576 rt
.dwOffsetMajor
= find_data(&clsidStore
, (const BYTE
*)rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
577 if (rt
.dwOffsetMajor
== -1)
578 rt
.dwOffsetMajor
= add_data(&clsidStore
, (const BYTE
*)rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
579 rt
.dwOffsetMajor
+= size
;
580 rt
.dwOffsetMinor
= find_data(&clsidStore
, (const BYTE
*)clsMinorType
, sizeof(CLSID
));
581 if (rt
.dwOffsetMinor
== -1)
582 rt
.dwOffsetMinor
= add_data(&clsidStore
, (const BYTE
*)clsMinorType
, sizeof(CLSID
));
583 rt
.dwOffsetMinor
+= size
;
585 add_data(&mainStore
, (LPBYTE
)&rt
, sizeof(rt
));
588 for (j
= 0; j
< rgPin2
.nMediums
; j
++)
590 DWORD index
= find_data(&clsidStore
, (const BYTE
*)(rgPin2
.lpMedium
+ j
), sizeof(REGPINMEDIUM
));
592 index
= add_data(&clsidStore
, (const BYTE
*)(rgPin2
.lpMedium
+ j
), sizeof(REGPINMEDIUM
));
595 add_data(&mainStore
, (LPBYTE
)&index
, sizeof(index
));
601 *pcbData
= mainStore
.current
+ clsidStore
.current
;
602 *ppData
= CoTaskMemAlloc(*pcbData
);
609 memcpy(*ppData
, mainStore
.pData
, mainStore
.current
);
610 memcpy((*ppData
) + mainStore
.current
, clsidStore
.pData
, clsidStore
.current
);
613 delete_vector(&mainStore
);
614 delete_vector(&clsidStore
);
618 static HRESULT
FM2_ReadFilterData(BYTE
*pData
, REGFILTER2
* prf2
)
621 struct REG_RF
* prrf
;
624 REGFILTERPINS2
* rgPins2
;
626 prrf
= (struct REG_RF
*)pData
;
629 if (prrf
->dwVersion
!= 2)
631 FIXME("Filter registry version %d not supported\n", prrf
->dwVersion
);
632 ZeroMemory(prf2
, sizeof(*prf2
));
638 TRACE("version = %d, merit = %x, #pins = %d, unused = %x\n",
639 prrf
->dwVersion
, prrf
->dwMerit
, prrf
->dwPins
, prrf
->dwUnused
);
641 prf2
->dwVersion
= prrf
->dwVersion
;
642 prf2
->dwMerit
= prrf
->dwMerit
;
643 prf2
->u
.s1
.cPins2
= prrf
->dwPins
;
644 rgPins2
= CoTaskMemAlloc(prrf
->dwPins
* sizeof(*rgPins2
));
645 prf2
->u
.s1
.rgPins2
= rgPins2
;
646 pCurrent
+= sizeof(struct REG_RF
);
648 for (i
= 0; i
< prrf
->dwPins
; i
++)
650 struct REG_RFP
* prrfp
= (struct REG_RFP
*)pCurrent
;
651 REGPINTYPES
* lpMediaType
;
652 REGPINMEDIUM
* lpMedium
;
655 /* FIXME: check signature */
657 TRACE("\tsignature = %s\n", debugstr_an((const char*)prrfp
->signature
, 4));
659 TRACE("\tpin[%d]: flags = %x, instances = %d, media types = %d, mediums = %d\n",
660 i
, prrfp
->dwFlags
, prrfp
->dwInstances
, prrfp
->dwMediaTypes
, prrfp
->dwMediums
);
662 rgPins2
[i
].dwFlags
= prrfp
->dwFlags
;
663 rgPins2
[i
].cInstances
= prrfp
->dwInstances
;
664 rgPins2
[i
].nMediaTypes
= prrfp
->dwMediaTypes
;
665 rgPins2
[i
].nMediums
= prrfp
->dwMediums
;
666 pCurrent
+= sizeof(struct REG_RFP
);
667 if (prrfp
->bCategory
)
669 CLSID
* clsCat
= CoTaskMemAlloc(sizeof(CLSID
));
670 memcpy(clsCat
, pData
+ *(DWORD
*)(pCurrent
), sizeof(CLSID
));
671 pCurrent
+= sizeof(DWORD
);
672 rgPins2
[i
].clsPinCategory
= clsCat
;
675 rgPins2
[i
].clsPinCategory
= NULL
;
677 if (rgPins2
[i
].nMediaTypes
> 0)
678 lpMediaType
= CoTaskMemAlloc(rgPins2
[i
].nMediaTypes
* sizeof(*lpMediaType
));
682 rgPins2
[i
].lpMediaType
= lpMediaType
;
684 for (j
= 0; j
< rgPins2
[i
].nMediaTypes
; j
++)
686 struct REG_TYPE
* prt
= (struct REG_TYPE
*)pCurrent
;
687 CLSID
* clsMajor
= CoTaskMemAlloc(sizeof(CLSID
));
688 CLSID
* clsMinor
= CoTaskMemAlloc(sizeof(CLSID
));
690 /* FIXME: check signature */
691 TRACE("\t\tsignature = %s\n", debugstr_an((const char*)prt
->signature
, 4));
693 memcpy(clsMajor
, pData
+ prt
->dwOffsetMajor
, sizeof(CLSID
));
694 memcpy(clsMinor
, pData
+ prt
->dwOffsetMinor
, sizeof(CLSID
));
696 lpMediaType
[j
].clsMajorType
= clsMajor
;
697 lpMediaType
[j
].clsMinorType
= clsMinor
;
699 pCurrent
+= sizeof(*prt
);
702 if (rgPins2
[i
].nMediums
> 0)
703 lpMedium
= CoTaskMemAlloc(rgPins2
[i
].nMediums
* sizeof(*lpMedium
));
707 rgPins2
[i
].lpMedium
= lpMedium
;
709 for (j
= 0; j
< rgPins2
[i
].nMediums
; j
++)
711 DWORD dwOffset
= *(DWORD
*)pCurrent
;
713 memcpy(lpMedium
+ j
, pData
+ dwOffset
, sizeof(REGPINMEDIUM
));
715 pCurrent
+= sizeof(dwOffset
);
724 static void FM2_DeleteRegFilter(REGFILTER2
* prf2
)
727 for (i
= 0; i
< prf2
->u
.s1
.cPins2
; i
++)
730 if (prf2
->u
.s1
.rgPins2
[i
].clsPinCategory
)
731 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].clsPinCategory
);
733 for (j
= 0; j
< prf2
->u
.s1
.rgPins2
[i
].nMediaTypes
; j
++)
735 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].lpMediaType
[j
].clsMajorType
);
736 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].lpMediaType
[j
].clsMinorType
);
738 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].lpMediaType
);
739 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].lpMedium
);
741 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
);
744 static HRESULT WINAPI
FilterMapper3_RegisterFilter(
745 IFilterMapper3
* iface
,
746 REFCLSID clsidFilter
,
748 IMoniker
**ppMoniker
,
749 const CLSID
*pclsidCategory
,
750 const OLECHAR
*szInstance
,
751 const REGFILTER2
*prf2
)
753 IParseDisplayName
* pParser
= NULL
;
754 IBindCtx
* pBindCtx
= NULL
;
755 IMoniker
* pMoniker
= NULL
;
756 IPropertyBag
* pPropBag
= NULL
;
758 LPWSTR pwszParseName
= NULL
;
760 static const WCHAR wszDevice
[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
763 LPWSTR szClsidTemp
= NULL
;
764 REGFILTER2 regfilter2
;
765 REGFILTERPINS2
* pregfp2
= NULL
;
767 TRACE("(%s, %s, %p, %s, %s, %p)\n",
768 debugstr_guid(clsidFilter
),
771 debugstr_guid(pclsidCategory
),
772 debugstr_w(szInstance
),
775 if (prf2
->dwVersion
== 2)
779 else if (prf2
->dwVersion
== 1)
783 /* REGFILTER2 structure is converted from version 1 to 2. Tested on Win2k. */
784 regfilter2
.dwVersion
= 2;
785 regfilter2
.dwMerit
= prf2
->dwMerit
;
786 regfilter2
.u
.s1
.cPins2
= prf2
->u
.s
.cPins
;
787 pregfp2
= CoTaskMemAlloc(prf2
->u
.s
.cPins
* sizeof(REGFILTERPINS2
));
788 regfilter2
.u
.s1
.rgPins2
= pregfp2
;
789 for (i
= 0; i
< prf2
->u
.s
.cPins
; i
++)
792 if (prf2
->u
.s
.rgPins
[i
].bRendered
)
793 flags
|= REG_PINFLAG_B_RENDERER
;
794 if (prf2
->u
.s
.rgPins
[i
].bOutput
)
795 flags
|= REG_PINFLAG_B_OUTPUT
;
796 if (prf2
->u
.s
.rgPins
[i
].bZero
)
797 flags
|= REG_PINFLAG_B_ZERO
;
798 if (prf2
->u
.s
.rgPins
[i
].bMany
)
799 flags
|= REG_PINFLAG_B_MANY
;
800 pregfp2
[i
].dwFlags
= flags
;
801 pregfp2
[i
].cInstances
= 1;
802 pregfp2
[i
].nMediaTypes
= prf2
->u
.s
.rgPins
[i
].nMediaTypes
;
803 pregfp2
[i
].lpMediaType
= prf2
->u
.s
.rgPins
[i
].lpMediaType
;
804 pregfp2
[i
].nMediums
= 0;
805 pregfp2
[i
].lpMedium
= NULL
;
806 pregfp2
[i
].clsPinCategory
= NULL
;
811 FIXME("dwVersion other that 1 or 2 not supported at the moment\n");
819 /* MSDN mentions the inexistent CLSID_ActiveMovieFilters GUID.
820 * In fact this is the CLSID_LegacyAmFilterCategory one */
821 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
823 /* sizeof... will include the null terminator and
824 * the + 1 is for the separator ('\\'). The -1 is
825 * because CHARS_IN_GUID includes the null terminator
827 nameLen
= sizeof(wszDevice
)/sizeof(wszDevice
[0]) + CHARS_IN_GUID
- 1 + 1;
830 nameLen
+= strlenW(szInstance
);
832 nameLen
+= CHARS_IN_GUID
- 1; /* CHARS_IN_GUID includes null terminator */
834 pCurrent
= pwszParseName
= CoTaskMemAlloc(nameLen
*sizeof(WCHAR
));
836 return E_OUTOFMEMORY
;
838 strcpyW(pwszParseName
, wszDevice
);
839 pCurrent
+= strlenW(wszDevice
);
841 hr
= StringFromCLSID(pclsidCategory
, &szClsidTemp
);
845 memcpy(pCurrent
, szClsidTemp
, CHARS_IN_GUID
* sizeof(WCHAR
));
846 pCurrent
+= CHARS_IN_GUID
- 1;
850 strcpyW(pCurrent
+1, szInstance
);
853 CoTaskMemFree(szClsidTemp
);
856 hr
= StringFromCLSID(clsidFilter
, &szClsidTemp
);
858 strcpyW(pCurrent
+1, szClsidTemp
);
863 hr
= CoCreateInstance(&CLSID_CDeviceMoniker
, NULL
, CLSCTX_INPROC
, &IID_IParseDisplayName
, (LPVOID
*)&pParser
);
866 hr
= CreateBindCtx(0, &pBindCtx
);
869 hr
= IParseDisplayName_ParseDisplayName(pParser
, pBindCtx
, pwszParseName
, &ulEaten
, &pMoniker
);
872 IBindCtx_Release(pBindCtx
);
874 IParseDisplayName_Release(pParser
);
877 hr
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
880 hr
= FM2_WriteFriendlyName(pPropBag
, szName
);
883 hr
= FM2_WriteClsid(pPropBag
, clsidFilter
);
890 hr
= FM2_WriteFilterData(®filter2
, &pData
, &cbData
);
895 SAFEARRAYBOUND saBound
;
898 saBound
.cElements
= cbData
;
899 psa
= SafeArrayCreate(VT_UI1
, 1, &saBound
);
902 ERR("Couldn't create SAFEARRAY\n");
909 hr
= SafeArrayAccessData(psa
, (LPVOID
*)&pbSAData
);
912 memcpy(pbSAData
, pData
, cbData
);
913 hr
= SafeArrayUnaccessData(psa
);
917 V_VT(&var
) = VT_ARRAY
| VT_UI1
;
918 V_UNION(&var
, parray
) = psa
;
921 hr
= IPropertyBag_Write(pPropBag
, wszFilterDataName
, &var
);
924 SafeArrayDestroy(psa
);
925 CoTaskMemFree(pData
);
930 IPropertyBag_Release(pPropBag
);
931 CoTaskMemFree(szClsidTemp
);
932 CoTaskMemFree(pwszParseName
);
934 if (SUCCEEDED(hr
) && ppMoniker
)
935 *ppMoniker
= pMoniker
;
937 IMoniker_Release(pMoniker
);
939 CoTaskMemFree(pregfp2
);
941 TRACE("-- returning %x\n", hr
);
946 /* internal helper function */
947 static BOOL
MatchTypes(
950 const REGPINTYPES
* pPinTypes
,
952 const GUID
* pMatchTypes
)
957 if ((nMatchTypes
== 0) && (nPinTypes
> 0))
960 for (j
= 0; j
< nPinTypes
; j
++)
963 for (i
= 0; i
< nMatchTypes
*2; i
+=2)
965 if (((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMajorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMajorType
, &pMatchTypes
[i
])) &&
966 ((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMinorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
+1], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMinorType
, &pMatchTypes
[i
+1])))
976 /* internal helper function for qsort of MONIKER_MERIT array */
977 static int mm_compare(const void * left
, const void * right
)
979 const struct MONIKER_MERIT
* mmLeft
= left
;
980 const struct MONIKER_MERIT
* mmRight
= right
;
982 if (mmLeft
->dwMerit
== mmRight
->dwMerit
)
984 if (mmLeft
->dwMerit
> mmRight
->dwMerit
)
990 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
991 * (GUID_NULL's in input to function automatically treated as wild cards)
992 * Input/Output needed means match only on criteria if TRUE (with zero input types
993 * meaning match any input/output pin as long as one exists), otherwise match any
994 * filter that meets the rest of the requirements.
996 static HRESULT WINAPI
FilterMapper3_EnumMatchingFilters(
997 IFilterMapper3
* iface
,
998 IEnumMoniker
**ppEnum
,
1004 const GUID
*pInputTypes
,
1005 const REGPINMEDIUM
*pMedIn
,
1006 const CLSID
*pPinCategoryIn
,
1010 const GUID
*pOutputTypes
,
1011 const REGPINMEDIUM
*pMedOut
,
1012 const CLSID
*pPinCategoryOut
)
1014 ICreateDevEnum
* pCreateDevEnum
;
1015 IMoniker
* pMonikerCat
;
1016 IEnumMoniker
* pEnumCat
;
1018 struct Vector monikers
= {NULL
, 0, 0};
1020 TRACE("(%p, %x, %s, %x, %s, %d, %p, %p, %p, %s, %s, %p, %p, %p)\n",
1023 bExactMatch
? "true" : "false",
1025 bInputNeeded
? "true" : "false",
1030 bRender
? "true" : "false",
1031 bOutputNeeded
? "true" : "false",
1038 FIXME("dwFlags = %x not implemented\n", dwFlags
);
1043 hr
= CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (LPVOID
*)&pCreateDevEnum
);
1047 hr
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &CLSID_ActiveMovieCategories
, &pEnumCat
, 0);
1049 ICreateDevEnum_Release(pCreateDevEnum
);
1053 while (IEnumMoniker_Next(pEnumCat
, 1, &pMonikerCat
, NULL
) == S_OK
)
1055 IPropertyBag
* pPropBagCat
= NULL
;
1057 HRESULT hrSub
; /* this is so that one buggy filter
1058 doesn't make the whole lot fail */
1062 hrSub
= IMoniker_BindToStorage(pMonikerCat
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
1064 if (SUCCEEDED(hrSub
))
1065 hrSub
= IPropertyBag_Read(pPropBagCat
, wszMeritName
, &var
, NULL
);
1067 if (SUCCEEDED(hrSub
) && (V_UNION(&var
, ulVal
) >= dwMerit
))
1070 IEnumMoniker
* pEnum
;
1071 IMoniker
* pMoniker
;
1075 if (TRACE_ON(quartz
))
1078 V_VT(&temp
) = VT_EMPTY
;
1079 IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &temp
, NULL
);
1080 TRACE("Considering category %s\n", debugstr_w(V_UNION(&temp
, bstrVal
)));
1081 VariantClear(&temp
);
1084 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
1086 if (SUCCEEDED(hrSub
))
1087 hrSub
= CLSIDFromString(V_UNION(&var
, bstrVal
), &clsidCat
);
1089 if (SUCCEEDED(hrSub
))
1090 hrSub
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &clsidCat
, &pEnum
, 0);
1094 while (IEnumMoniker_Next(pEnum
, 1, &pMoniker
, NULL
) == S_OK
)
1096 IPropertyBag
* pPropBag
= NULL
;
1101 BOOL bInputMatch
= !bInputNeeded
;
1102 BOOL bOutputMatch
= !bOutputNeeded
;
1104 ZeroMemory(&rf2
, sizeof(rf2
));
1107 hrSub
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBag
);
1109 if (TRACE_ON(quartz
))
1112 V_VT(&temp
) = VT_EMPTY
;
1113 IPropertyBag_Read(pPropBag
, wszFriendlyName
, &temp
, NULL
);
1114 TRACE("Considering filter %s\n", debugstr_w(V_UNION(&temp
, bstrVal
)));
1115 VariantClear(&temp
);
1118 if (SUCCEEDED(hrSub
))
1120 hrSub
= IPropertyBag_Read(pPropBag
, wszFilterDataName
, &var
, NULL
);
1123 if (SUCCEEDED(hrSub
))
1124 hrSub
= SafeArrayAccessData(V_UNION(&var
, parray
), (LPVOID
*)&pData
);
1126 if (SUCCEEDED(hrSub
))
1127 hrSub
= FM2_ReadFilterData(pData
, &rf2
);
1130 SafeArrayUnaccessData(V_UNION(&var
, parray
));
1134 /* Logic used for bInputMatch expression:
1135 * There exists some pin such that bInputNeeded implies (pin is an input and
1136 * (bRender implies pin has render flag) and major/minor types members of
1138 * bOutputMatch is similar, but without the "bRender implies ..." part
1139 * and substituting variables names containing input for output
1142 /* determine whether filter meets requirements */
1143 if (SUCCEEDED(hrSub
) && (rf2
.dwMerit
>= dwMerit
))
1145 for (i
= 0; (i
< rf2
.u
.s1
.cPins2
) && (!bInputMatch
|| !bOutputMatch
); i
++)
1147 const REGFILTERPINS2
* rfp2
= rf2
.u
.s1
.rgPins2
+ i
;
1149 bInputMatch
= bInputMatch
|| (!(rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1150 (!bRender
|| (rfp2
->dwFlags
& REG_PINFLAG_B_RENDERER
)) &&
1151 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cInputTypes
, pInputTypes
));
1152 bOutputMatch
= bOutputMatch
|| ((rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1153 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cOutputTypes
, pOutputTypes
));
1156 if (bInputMatch
&& bOutputMatch
)
1158 struct MONIKER_MERIT mm
= {pMoniker
, rf2
.dwMerit
};
1159 IMoniker_AddRef(pMoniker
);
1160 add_data(&monikers
, (LPBYTE
)&mm
, sizeof(mm
));
1164 FM2_DeleteRegFilter(&rf2
);
1166 IPropertyBag_Release(pPropBag
);
1167 IMoniker_Release(pMoniker
);
1169 IEnumMoniker_Release(pEnum
);
1175 IPropertyBag_Release(pPropBagCat
);
1176 IMoniker_Release(pMonikerCat
);
1181 IMoniker
** ppMoniker
;
1183 ULONG nMonikerCount
= monikers
.current
/ sizeof(struct MONIKER_MERIT
);
1185 /* sort the monikers in descending merit order */
1186 qsort(monikers
.pData
, nMonikerCount
,
1187 sizeof(struct MONIKER_MERIT
),
1190 /* construct an IEnumMoniker interface */
1191 ppMoniker
= CoTaskMemAlloc(nMonikerCount
* sizeof(IMoniker
*));
1192 for (i
= 0; i
< nMonikerCount
; i
++)
1194 /* no need to AddRef here as already AddRef'd above */
1195 ppMoniker
[i
] = ((struct MONIKER_MERIT
*)monikers
.pData
)[i
].pMoniker
;
1197 hr
= EnumMonikerImpl_Create(ppMoniker
, nMonikerCount
, ppEnum
);
1198 CoTaskMemFree(ppMoniker
);
1201 delete_vector(&monikers
);
1202 IEnumMoniker_Release(pEnumCat
);
1203 ICreateDevEnum_Release(pCreateDevEnum
);
1208 static HRESULT WINAPI
FilterMapper3_GetICreateDevEnum(IFilterMapper3
*iface
, ICreateDevEnum
**ppEnum
)
1210 TRACE("(%p, %p)\n", iface
, ppEnum
);
1213 return CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (void**)ppEnum
);
1216 static const IFilterMapper3Vtbl fm3vtbl
=
1219 FilterMapper3_QueryInterface
,
1220 FilterMapper3_AddRef
,
1221 FilterMapper3_Release
,
1223 FilterMapper3_CreateCategory
,
1224 FilterMapper3_UnregisterFilter
,
1225 FilterMapper3_RegisterFilter
,
1226 FilterMapper3_EnumMatchingFilters
,
1227 FilterMapper3_GetICreateDevEnum
1230 /*** IUnknown methods ***/
1232 static HRESULT WINAPI
FilterMapper_QueryInterface(IFilterMapper
* iface
, REFIID riid
, LPVOID
*ppv
)
1234 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1236 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1238 return FilterMapper3_QueryInterface((IFilterMapper3
*)&This
->lpVtbl
, riid
, ppv
);
1241 static ULONG WINAPI
FilterMapper_AddRef(IFilterMapper
* iface
)
1243 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1245 return FilterMapper3_AddRef((IFilterMapper3
*)This
);
1248 static ULONG WINAPI
FilterMapper_Release(IFilterMapper
* iface
)
1250 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1252 return FilterMapper3_Release((IFilterMapper3
*)This
);
1255 /*** IFilterMapper methods ***/
1257 static HRESULT WINAPI
FilterMapper_EnumMatchingFilters(
1258 IFilterMapper
* iface
,
1259 IEnumRegFilters
**ppEnum
,
1269 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1272 IEnumMoniker
* ppEnumMoniker
;
1275 ULONG idx
= 0, nb_mon
= 0;
1276 REGFILTER
* regfilters
;
1279 TRACE("(%p/%p)->(%p, %x, %s, %s, %s, %s, %s, %s, %s) stub!\n",
1283 bInputNeeded
? "true" : "false",
1284 debugstr_guid(&clsInMaj
),
1285 debugstr_guid(&clsInSub
),
1286 bRender
? "true" : "false",
1287 bOutputNeeded
? "true" : "false",
1288 debugstr_guid(&clsOutMaj
),
1289 debugstr_guid(&clsOutSub
));
1291 InputType
[0] = clsInMaj
;
1292 InputType
[1] = clsInSub
;
1293 OutputType
[0] = clsOutMaj
;
1294 OutputType
[1] = clsOutSub
;
1298 hr
= IFilterMapper3_EnumMatchingFilters((IFilterMapper3
*)This
,
1318 while(IEnumMoniker_Next(ppEnumMoniker
, 1, &IMon
, &nb
) == S_OK
)
1320 IMoniker_Release(IMon
);
1326 IEnumMoniker_Release(ppEnumMoniker
);
1327 return IEnumRegFiltersImpl_Construct(NULL
, 0, ppEnum
);
1330 regfilters
= CoTaskMemAlloc(nb_mon
* sizeof(REGFILTER
));
1333 IEnumMoniker_Release(ppEnumMoniker
);
1334 return E_OUTOFMEMORY
;
1336 ZeroMemory(regfilters
, nb_mon
* sizeof(REGFILTER
)); /* will prevent bad free of Name in case of error. */
1338 IEnumMoniker_Reset(ppEnumMoniker
);
1339 while(IEnumMoniker_Next(ppEnumMoniker
, 1, &IMon
, &nb
) == S_OK
)
1341 IPropertyBag
* pPropBagCat
= NULL
;
1349 hrSub
= IMoniker_BindToStorage(IMon
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
1351 if (SUCCEEDED(hrSub
))
1352 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
1354 if (SUCCEEDED(hrSub
))
1355 hrSub
= CLSIDFromString(V_UNION(&var
, bstrVal
), &clsid
);
1359 if (SUCCEEDED(hrSub
))
1360 hrSub
= IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &var
, NULL
);
1362 if (SUCCEEDED(hrSub
))
1364 len
= (strlenW(V_UNION(&var
, bstrVal
))+1) * sizeof(WCHAR
);
1365 if (!(regfilters
[idx
].Name
= CoTaskMemAlloc(len
*2)))
1369 if (SUCCEEDED(hrSub
) && regfilters
[idx
].Name
)
1371 memcpy(regfilters
[idx
].Name
, V_UNION(&var
, bstrVal
), len
);
1372 regfilters
[idx
].Clsid
= clsid
;
1377 IPropertyBag_Release(pPropBagCat
);
1378 IMoniker_Release(IMon
);
1384 hr
= IEnumRegFiltersImpl_Construct(regfilters
, nb_mon
, ppEnum
);
1387 for (idx
= 0; idx
< nb_mon
; idx
++)
1388 CoTaskMemFree(regfilters
[idx
].Name
);
1389 CoTaskMemFree(regfilters
);
1390 IEnumMoniker_Release(ppEnumMoniker
);
1396 static HRESULT WINAPI
FilterMapper_RegisterFilter(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, DWORD dwMerit
)
1399 LPWSTR wszClsid
= NULL
;
1402 WCHAR wszKeyName
[ARRAYSIZE(wszFilterSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1404 TRACE("(%p)->(%s, %s, %x)\n", iface
, debugstr_guid(&clsid
), debugstr_w(szName
), dwMerit
);
1406 hr
= StringFromCLSID(&clsid
, &wszClsid
);
1410 strcpyW(wszKeyName
, wszFilterSlash
);
1411 strcatW(wszKeyName
, wszClsid
);
1413 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
1414 hr
= HRESULT_FROM_WIN32(lRet
);
1419 lRet
= RegSetValueExW(hKey
, NULL
, 0, REG_SZ
, (const BYTE
*)szName
, (strlenW(szName
) + 1) * sizeof(WCHAR
));
1420 hr
= HRESULT_FROM_WIN32(lRet
);
1426 strcpyW(wszKeyName
, wszClsidSlash
);
1427 strcatW(wszKeyName
, wszClsid
);
1429 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
1430 hr
= HRESULT_FROM_WIN32(lRet
);
1435 lRet
= RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwMerit
, sizeof(dwMerit
));
1436 hr
= HRESULT_FROM_WIN32(lRet
);
1440 CoTaskMemFree(wszClsid
);
1445 static HRESULT WINAPI
FilterMapper_RegisterFilterInstance(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, CLSID
*MRId
)
1447 TRACE("(%p)->(%s, %s, %p)\n", iface
, debugstr_guid(&clsid
), debugstr_w(szName
), MRId
);
1449 /* Not implemented in Windows (tested on Win2k) */
1454 static HRESULT WINAPI
FilterMapper_RegisterPin(
1455 IFilterMapper
* iface
,
1462 CLSID ConnectsToFilter
,
1463 LPCWSTR ConnectsToPin
)
1467 LPWSTR wszClsid
= NULL
;
1469 HKEY hPinsKey
= NULL
;
1470 WCHAR
* wszPinsKeyName
;
1471 WCHAR wszKeyName
[ARRAYSIZE(wszClsidSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1473 TRACE("(%p)->(%s, %s, %d, %d, %d, %d, %s, %s)\n", iface
, debugstr_guid(&Filter
), debugstr_w(szName
), bRendered
,
1474 bOutput
, bZero
, bMany
, debugstr_guid(&ConnectsToFilter
), debugstr_w(ConnectsToPin
));
1476 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1480 strcpyW(wszKeyName
, wszClsidSlash
);
1481 strcatW(wszKeyName
, wszClsid
);
1483 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1484 hr
= HRESULT_FROM_WIN32(lRet
);
1489 wszPinsKeyName
= CoTaskMemAlloc((strlenW(wszPins
) + 1 + strlenW(szName
) + 1) * 2);
1490 if (!wszPinsKeyName
)
1496 strcpyW(wszPinsKeyName
, wszPins
);
1497 strcatW(wszPinsKeyName
, wszSlash
);
1498 strcatW(wszPinsKeyName
, szName
);
1500 lRet
= RegCreateKeyExW(hKey
, wszPinsKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hPinsKey
, NULL
);
1501 hr
= HRESULT_FROM_WIN32(lRet
);
1502 CoTaskMemFree(wszPinsKeyName
);
1507 lRet
= RegSetValueExW(hPinsKey
, wszAllowedMany
, 0, REG_DWORD
, (LPBYTE
)&bMany
, sizeof(bMany
));
1508 hr
= HRESULT_FROM_WIN32(lRet
);
1513 lRet
= RegSetValueExW(hPinsKey
, wszAllowedZero
, 0, REG_DWORD
, (LPBYTE
)&bZero
, sizeof(bZero
));
1514 hr
= HRESULT_FROM_WIN32(lRet
);
1519 lRet
= RegSetValueExW(hPinsKey
, wszDirection
, 0, REG_DWORD
, (LPBYTE
)&bOutput
, sizeof(bOutput
));
1520 hr
= HRESULT_FROM_WIN32(lRet
);
1525 lRet
= RegSetValueExW(hPinsKey
, wszIsRendered
, 0, REG_DWORD
, (LPBYTE
)&bRendered
, sizeof(bRendered
));
1526 hr
= HRESULT_FROM_WIN32(lRet
);
1531 HKEY hkeyDummy
= NULL
;
1533 lRet
= RegCreateKeyExW(hPinsKey
, wszTypes
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkeyDummy
, NULL
);
1534 hr
= HRESULT_FROM_WIN32(lRet
);
1536 if (hkeyDummy
) RegCloseKey(hkeyDummy
);
1539 CoTaskMemFree(wszClsid
);
1543 CloseHandle(hPinsKey
);
1549 static HRESULT WINAPI
FilterMapper_RegisterPinType(
1550 IFilterMapper
* iface
,
1558 LPWSTR wszClsid
= NULL
;
1559 LPWSTR wszClsidMajorType
= NULL
;
1560 LPWSTR wszClsidSubType
= NULL
;
1562 WCHAR
* wszTypesKey
;
1563 WCHAR wszKeyName
[MAX_PATH
];
1565 TRACE("(%p)->(%s, %s, %s, %s)\n", iface
, debugstr_guid(&clsFilter
), debugstr_w(szName
),
1566 debugstr_guid(&clsMajorType
), debugstr_guid(&clsSubType
));
1568 hr
= StringFromCLSID(&clsFilter
, &wszClsid
);
1572 hr
= StringFromCLSID(&clsMajorType
, &wszClsidMajorType
);
1577 hr
= StringFromCLSID(&clsSubType
, &wszClsidSubType
);
1582 wszTypesKey
= CoTaskMemAlloc((strlenW(wszClsidSlash
) + strlenW(wszClsid
) + strlenW(wszPins
) +
1583 strlenW(szName
) + strlenW(wszTypes
) + 3 + 1) * 2);
1590 strcpyW(wszTypesKey
, wszClsidSlash
);
1591 strcatW(wszTypesKey
, wszClsid
);
1592 strcatW(wszTypesKey
, wszSlash
);
1593 strcatW(wszTypesKey
, wszPins
);
1594 strcatW(wszTypesKey
, wszSlash
);
1595 strcatW(wszTypesKey
, szName
);
1596 strcatW(wszTypesKey
, wszSlash
);
1597 strcatW(wszTypesKey
, wszTypes
);
1599 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszTypesKey
, 0, KEY_WRITE
, &hKey
);
1600 hr
= HRESULT_FROM_WIN32(lRet
);
1601 CoTaskMemFree(wszTypesKey
);
1606 HKEY hkeyDummy
= NULL
;
1608 strcpyW(wszKeyName
, wszClsidMajorType
);
1609 strcatW(wszKeyName
, wszSlash
);
1610 strcatW(wszKeyName
, wszClsidSubType
);
1612 lRet
= RegCreateKeyExW(hKey
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkeyDummy
, NULL
);
1613 hr
= HRESULT_FROM_WIN32(lRet
);
1616 if (hkeyDummy
) RegCloseKey(hkeyDummy
);
1619 CoTaskMemFree(wszClsid
);
1620 CoTaskMemFree(wszClsidMajorType
);
1621 CoTaskMemFree(wszClsidSubType
);
1626 static HRESULT WINAPI
FilterMapper_UnregisterFilter(IFilterMapper
* iface
, CLSID Filter
)
1630 LPWSTR wszClsid
= NULL
;
1632 WCHAR wszKeyName
[ARRAYSIZE(wszClsidSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1634 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(&Filter
));
1636 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1640 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszFilter
, 0, KEY_WRITE
, &hKey
);
1641 hr
= HRESULT_FROM_WIN32(lRet
);
1646 lRet
= RegDeleteKeyW(hKey
, wszClsid
);
1647 hr
= HRESULT_FROM_WIN32(lRet
);
1653 strcpyW(wszKeyName
, wszClsidSlash
);
1654 strcatW(wszKeyName
, wszClsid
);
1656 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1657 hr
= HRESULT_FROM_WIN32(lRet
);
1662 lRet
= RegDeleteValueW(hKey
, wszMeritName
);
1663 if (lRet
!= ERROR_SUCCESS
)
1664 hr
= HRESULT_FROM_WIN32(lRet
);
1666 lRet
= RegDeleteTreeW(hKey
, wszPins
);
1667 if (lRet
!= ERROR_SUCCESS
)
1668 hr
= HRESULT_FROM_WIN32(lRet
);
1673 CoTaskMemFree(wszClsid
);
1678 static HRESULT WINAPI
FilterMapper_UnregisterFilterInstance(IFilterMapper
* iface
, CLSID MRId
)
1680 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(&MRId
));
1682 /* Not implemented in Windows (tested on Win2k) */
1687 static HRESULT WINAPI
FilterMapper_UnregisterPin(IFilterMapper
* iface
, CLSID Filter
, LPCWSTR Name
)
1691 LPWSTR wszClsid
= NULL
;
1693 WCHAR
* wszPinNameKey
;
1694 WCHAR wszKeyName
[ARRAYSIZE(wszClsidSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1696 TRACE("(%p)->(%s, %s)\n", iface
, debugstr_guid(&Filter
), debugstr_w(Name
));
1699 return E_INVALIDARG
;
1701 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1705 strcpyW(wszKeyName
, wszClsidSlash
);
1706 strcatW(wszKeyName
, wszClsid
);
1708 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1709 hr
= HRESULT_FROM_WIN32(lRet
);
1714 wszPinNameKey
= CoTaskMemAlloc((strlenW(wszPins
) + 1 + strlenW(Name
) + 1) * 2);
1721 strcpyW(wszPinNameKey
, wszPins
);
1722 strcatW(wszPinNameKey
, wszSlash
);
1723 strcatW(wszPinNameKey
, Name
);
1725 lRet
= RegDeleteTreeW(hKey
, wszPinNameKey
);
1726 hr
= HRESULT_FROM_WIN32(lRet
);
1727 CoTaskMemFree(wszPinNameKey
);
1730 CoTaskMemFree(wszClsid
);
1737 static const IFilterMapperVtbl fmvtbl
=
1740 FilterMapper_QueryInterface
,
1741 FilterMapper_AddRef
,
1742 FilterMapper_Release
,
1744 FilterMapper_RegisterFilter
,
1745 FilterMapper_RegisterFilterInstance
,
1746 FilterMapper_RegisterPin
,
1747 FilterMapper_RegisterPinType
,
1748 FilterMapper_UnregisterFilter
,
1749 FilterMapper_UnregisterFilterInstance
,
1750 FilterMapper_UnregisterPin
,
1751 FilterMapper_EnumMatchingFilters
1755 /*** IUnknown methods ***/
1756 static HRESULT WINAPI
AMFilterData_QueryInterface(IAMFilterData
* iface
, REFIID riid
, LPVOID
*ppv
)
1758 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1760 return FilterMapper3_QueryInterface((IFilterMapper3
*)This
, riid
, ppv
);
1763 static ULONG WINAPI
AMFilterData_AddRef(IAMFilterData
* iface
)
1765 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1767 return FilterMapper3_AddRef((IFilterMapper3
*)This
);
1770 static ULONG WINAPI
AMFilterData_Release(IAMFilterData
* iface
)
1772 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1774 return FilterMapper3_Release((IFilterMapper3
*)This
);
1777 /*** IAMFilterData methods ***/
1778 static HRESULT WINAPI
AMFilterData_ParseFilterData(IAMFilterData
* iface
,
1779 BYTE
*pData
, ULONG cb
,
1780 BYTE
**ppRegFilter2
)
1782 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1786 TRACE("(%p/%p)->(%p, %d, %p)\n", This
, iface
, pData
, cb
, ppRegFilter2
);
1788 prf2
= CoTaskMemAlloc(sizeof(*prf2
));
1790 return E_OUTOFMEMORY
;
1791 *ppRegFilter2
= (BYTE
*)prf2
;
1793 hr
= FM2_ReadFilterData(pData
, prf2
);
1796 CoTaskMemFree(prf2
);
1797 *ppRegFilter2
= NULL
;
1803 static HRESULT WINAPI
AMFilterData_CreateFilterData(IAMFilterData
* iface
,
1805 BYTE
**pRegFilterData
,
1808 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1810 TRACE("(%p/%p)->(%p, %p, %p)\n", This
, iface
, prf2
, pRegFilterData
, pcb
);
1812 return FM2_WriteFilterData(prf2
, pRegFilterData
, pcb
);
1815 static const IAMFilterDataVtbl AMFilterDataVtbl
= {
1816 AMFilterData_QueryInterface
,
1817 AMFilterData_AddRef
,
1818 AMFilterData_Release
,
1819 AMFilterData_ParseFilterData
,
1820 AMFilterData_CreateFilterData