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"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
46 #define ARRAYSIZE(array) (sizeof(array)/sizeof((array)[0]))
48 typedef struct FilterMapper3Impl
50 IFilterMapper3 IFilterMapper3_iface
;
51 IFilterMapper IFilterMapper_iface
;
52 IAMFilterData IAMFilterData_iface
;
53 const IUnknownVtbl
*IInner_vtbl
;
60 static const IUnknownVtbl IInner_VTable
;
61 static const IFilterMapper3Vtbl fm3vtbl
;
62 static const IFilterMapperVtbl fmvtbl
;
63 static const IAMFilterDataVtbl AMFilterDataVtbl
;
65 static inline FilterMapper3Impl
*impl_from_IFilterMapper3( IFilterMapper3
*iface
)
67 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IFilterMapper3_iface
);
70 static inline FilterMapper3Impl
*impl_from_IFilterMapper( IFilterMapper
*iface
)
72 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IFilterMapper_iface
);
75 static inline FilterMapper3Impl
*impl_from_IAMFilterData( IAMFilterData
*iface
)
77 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IAMFilterData_iface
);
80 static inline FilterMapper3Impl
*impl_from_inner_IUnknown( IUnknown
*iface
)
82 return (FilterMapper3Impl
*)((char*)iface
- FIELD_OFFSET(FilterMapper3Impl
, IInner_vtbl
));
85 static const WCHAR wszClsidSlash
[] = {'C','L','S','I','D','\\',0};
86 static const WCHAR wszSlashInstance
[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
87 static const WCHAR wszSlash
[] = {'\\',0};
89 /* CLSID property in media category Moniker */
90 static const WCHAR wszClsidName
[] = {'C','L','S','I','D',0};
91 /* FriendlyName property in media category Moniker */
92 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
93 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
94 static const WCHAR wszMeritName
[] = {'M','e','r','i','t',0};
95 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
96 static const WCHAR wszFilterDataName
[] = {'F','i','l','t','e','r','D','a','t','a',0};
97 /* For filters registered with IFilterMapper */
98 static const WCHAR wszFilterSlash
[] = {'F','i','l','t','e','r','\\',0};
99 static const WCHAR wszFilter
[] = {'F','i','l','t','e','r',0};
100 /* For pins registered with IFilterMapper */
101 static const WCHAR wszPins
[] = {'P','i','n','s',0};
102 static const WCHAR wszAllowedMany
[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
103 static const WCHAR wszAllowedZero
[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
104 static const WCHAR wszDirection
[] = {'D','i','r','e','c','t','i','o','n',0};
105 static const WCHAR wszIsRendered
[] = {'I','s','R','e','n','d','e','r','e','d',0};
106 /* For types registered with IFilterMapper */
107 static const WCHAR wszTypes
[] = {'T','y','p','e','s',0};
110 /* registry format for REGFILTER2 */
121 BYTE signature
[4]; /* e.g. "0pi3" */
126 DWORD bCategory
; /* is there a category clsid? */
127 /* optional: dwOffsetCategoryClsid */
132 BYTE signature
[4]; /* e.g. "0ty3" */
147 int capacity
; /* in bytes */
148 int current
; /* pointer to next free byte */
151 /* returns the position it was added at */
152 static int add_data(struct Vector
* v
, const BYTE
* pData
, int size
)
154 int index
= v
->current
;
155 if (v
->current
+ size
> v
->capacity
)
157 LPBYTE pOldData
= v
->pData
;
158 v
->capacity
= (v
->capacity
+ size
) * 2;
159 v
->pData
= CoTaskMemAlloc(v
->capacity
);
160 memcpy(v
->pData
, pOldData
, v
->current
);
161 CoTaskMemFree(pOldData
);
163 memcpy(v
->pData
+ v
->current
, pData
, size
);
168 static int find_data(const struct Vector
* v
, const BYTE
* pData
, int size
)
171 for (index
= 0; index
< v
->current
; index
++)
172 if (!memcmp(v
->pData
+ index
, pData
, size
))
178 static void delete_vector(struct Vector
* v
)
180 CoTaskMemFree(v
->pData
);
185 HRESULT
FilterMapper2_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
187 FilterMapper3Impl
* pFM2impl
;
189 TRACE("(%p, %p)\n", pUnkOuter
, ppObj
);
191 pFM2impl
= CoTaskMemAlloc(sizeof(*pFM2impl
));
193 return E_OUTOFMEMORY
;
195 pFM2impl
->pUnkOuter
= pUnkOuter
;
196 pFM2impl
->bUnkOuterValid
= FALSE
;
197 pFM2impl
->bAggregatable
= FALSE
;
198 pFM2impl
->IInner_vtbl
= &IInner_VTable
;
199 pFM2impl
->IFilterMapper3_iface
.lpVtbl
= &fm3vtbl
;
200 pFM2impl
->IFilterMapper_iface
.lpVtbl
= &fmvtbl
;
201 pFM2impl
->IAMFilterData_iface
.lpVtbl
= &AMFilterDataVtbl
;
202 pFM2impl
->refCount
= 1;
206 TRACE("-- created at %p\n", pFM2impl
);
211 HRESULT
FilterMapper_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
213 FilterMapper3Impl
*pFM2impl
;
216 TRACE("(%p, %p)\n", pUnkOuter
, ppObj
);
218 hr
= FilterMapper2_create(pUnkOuter
, (LPVOID
*)&pFM2impl
);
222 *ppObj
= &pFM2impl
->IFilterMapper_iface
;
227 /*** IUnknown (inner) methods ***/
229 static HRESULT WINAPI
Inner_QueryInterface(IUnknown
* iface
, REFIID riid
, LPVOID
* ppv
)
231 FilterMapper3Impl
*This
= impl_from_inner_IUnknown(iface
);
232 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
234 if (This
->bAggregatable
)
235 This
->bUnkOuterValid
= TRUE
;
239 if (IsEqualIID(riid
, &IID_IUnknown
))
240 *ppv
= &This
->IInner_vtbl
;
241 else if (IsEqualIID(riid
, &IID_IFilterMapper2
) ||
242 IsEqualIID(riid
, &IID_IFilterMapper3
))
244 else if (IsEqualIID(riid
, &IID_IFilterMapper
))
245 *ppv
= &This
->IFilterMapper_iface
;
246 else if (IsEqualIID(riid
, &IID_IAMFilterData
))
247 *ppv
= &This
->IAMFilterData_iface
;
251 IUnknown_AddRef((IUnknown
*)*ppv
);
255 FIXME("No interface for %s\n", debugstr_guid(riid
));
256 return E_NOINTERFACE
;
259 static ULONG WINAPI
Inner_AddRef(IUnknown
* iface
)
261 FilterMapper3Impl
*This
= impl_from_inner_IUnknown(iface
);
262 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
264 TRACE("(%p)->() AddRef from %d\n", This
, refCount
- 1);
269 static ULONG WINAPI
Inner_Release(IUnknown
* iface
)
271 FilterMapper3Impl
*This
= impl_from_inner_IUnknown(iface
);
272 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
274 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
284 static const IUnknownVtbl IInner_VTable
=
286 Inner_QueryInterface
,
291 static HRESULT WINAPI
FilterMapper3_QueryInterface(IFilterMapper3
* iface
, REFIID riid
, LPVOID
*ppv
)
293 FilterMapper3Impl
*This
= impl_from_IFilterMapper3(iface
);
295 if (This
->bAggregatable
)
296 This
->bUnkOuterValid
= TRUE
;
300 if (This
->bAggregatable
)
301 return IUnknown_QueryInterface(This
->pUnkOuter
, riid
, ppv
);
303 if (IsEqualIID(riid
, &IID_IUnknown
))
307 IUnknown_AddRef((IUnknown
*)&(This
->IInner_vtbl
));
308 hr
= IUnknown_QueryInterface((IUnknown
*)&(This
->IInner_vtbl
), riid
, ppv
);
309 IUnknown_Release((IUnknown
*)&(This
->IInner_vtbl
));
310 This
->bAggregatable
= TRUE
;
315 return E_NOINTERFACE
;
318 return IUnknown_QueryInterface((IUnknown
*)&(This
->IInner_vtbl
), riid
, ppv
);
321 static ULONG WINAPI
FilterMapper3_AddRef(IFilterMapper3
* iface
)
323 FilterMapper3Impl
*This
= impl_from_IFilterMapper3(iface
);
325 if (This
->pUnkOuter
&& This
->bUnkOuterValid
)
326 return IUnknown_AddRef(This
->pUnkOuter
);
327 return IUnknown_AddRef((IUnknown
*)&(This
->IInner_vtbl
));
330 static ULONG WINAPI
FilterMapper3_Release(IFilterMapper3
* iface
)
332 FilterMapper3Impl
*This
= impl_from_IFilterMapper3(iface
);
334 if (This
->pUnkOuter
&& This
->bUnkOuterValid
)
335 return IUnknown_Release(This
->pUnkOuter
);
336 return IUnknown_Release((IUnknown
*)&(This
->IInner_vtbl
));
339 /*** IFilterMapper3 methods ***/
341 static HRESULT WINAPI
FilterMapper3_CreateCategory(
342 IFilterMapper3
* iface
,
343 REFCLSID clsidCategory
,
344 DWORD dwCategoryMerit
,
345 LPCWSTR szDescription
)
347 LPWSTR wClsidAMCat
= NULL
;
348 LPWSTR wClsidCategory
= NULL
;
349 WCHAR wszKeyName
[ARRAYSIZE(wszClsidSlash
)-1 + ARRAYSIZE(wszSlashInstance
)-1 + (CHARS_IN_GUID
-1) * 2 + 1];
354 TRACE("(%s, %x, %s)\n", debugstr_guid(clsidCategory
), dwCategoryMerit
, debugstr_w(szDescription
));
356 hr
= StringFromCLSID(&CLSID_ActiveMovieCategories
, &wClsidAMCat
);
360 hr
= StringFromCLSID(clsidCategory
, &wClsidCategory
);
365 strcpyW(wszKeyName
, wszClsidSlash
);
366 strcatW(wszKeyName
, wClsidAMCat
);
367 strcatW(wszKeyName
, wszSlashInstance
);
368 strcatW(wszKeyName
, wClsidCategory
);
370 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
371 hr
= HRESULT_FROM_WIN32(lRet
);
376 lRet
= RegSetValueExW(hKey
, wszFriendlyName
, 0, REG_SZ
, (const BYTE
*)szDescription
, (strlenW(szDescription
) + 1) * sizeof(WCHAR
));
377 hr
= HRESULT_FROM_WIN32(lRet
);
382 lRet
= RegSetValueExW(hKey
, wszClsidName
, 0, REG_SZ
, (LPBYTE
)wClsidCategory
, (strlenW(wClsidCategory
) + 1) * sizeof(WCHAR
));
383 hr
= HRESULT_FROM_WIN32(lRet
);
388 lRet
= RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwCategoryMerit
, sizeof(dwCategoryMerit
));
389 hr
= HRESULT_FROM_WIN32(lRet
);
393 CoTaskMemFree(wClsidCategory
);
394 CoTaskMemFree(wClsidAMCat
);
399 static HRESULT WINAPI
FilterMapper3_UnregisterFilter(
400 IFilterMapper3
* iface
,
401 const CLSID
*pclsidCategory
,
402 const OLECHAR
*szInstance
,
405 WCHAR wszKeyName
[MAX_PATH
];
406 LPWSTR wClsidCategory
= NULL
;
407 LPWSTR wFilter
= NULL
;
410 TRACE("(%p, %s, %s)\n", pclsidCategory
, debugstr_w(szInstance
), debugstr_guid(Filter
));
413 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
415 hr
= StringFromCLSID(pclsidCategory
, &wClsidCategory
);
419 strcpyW(wszKeyName
, wszClsidSlash
);
420 strcatW(wszKeyName
, wClsidCategory
);
421 strcatW(wszKeyName
, wszSlashInstance
);
423 strcatW(wszKeyName
, szInstance
);
426 hr
= StringFromCLSID(Filter
, &wFilter
);
428 strcatW(wszKeyName
, wFilter
);
434 LONG lRet
= RegDeleteKeyW(HKEY_CLASSES_ROOT
, wszKeyName
);
435 hr
= HRESULT_FROM_WIN32(lRet
);
438 CoTaskMemFree(wClsidCategory
);
439 CoTaskMemFree(wFilter
);
444 static HRESULT
FM2_WriteFriendlyName(IPropertyBag
* pPropBag
, LPCWSTR szName
)
450 V_VT(&var
) = VT_BSTR
;
451 V_UNION(&var
, bstrVal
) = value
= SysAllocString(szName
);
453 ret
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
454 SysFreeString(value
);
459 static HRESULT
FM2_WriteClsid(IPropertyBag
* pPropBag
, REFCLSID clsid
)
461 LPWSTR wszClsid
= NULL
;
465 hr
= StringFromCLSID(clsid
, &wszClsid
);
469 V_VT(&var
) = VT_BSTR
;
470 V_UNION(&var
, bstrVal
) = wszClsid
;
471 hr
= IPropertyBag_Write(pPropBag
, wszClsidName
, &var
);
473 CoTaskMemFree(wszClsid
);
477 static HRESULT
FM2_WriteFilterData(const REGFILTER2
* prf2
, BYTE
**ppData
, ULONG
*pcbData
)
479 int size
= sizeof(struct REG_RF
);
481 struct Vector mainStore
= {NULL
, 0, 0};
482 struct Vector clsidStore
= {NULL
, 0, 0};
486 rrf
.dwVersion
= prf2
->dwVersion
;
487 rrf
.dwMerit
= prf2
->dwMerit
;
488 rrf
.dwPins
= prf2
->u
.s2
.cPins2
;
491 add_data(&mainStore
, (LPBYTE
)&rrf
, sizeof(rrf
));
493 for (i
= 0; i
< prf2
->u
.s2
.cPins2
; i
++)
495 size
+= sizeof(struct REG_RFP
);
496 if (prf2
->u
.s2
.rgPins2
[i
].clsPinCategory
)
497 size
+= sizeof(DWORD
);
498 size
+= prf2
->u
.s2
.rgPins2
[i
].nMediaTypes
* sizeof(struct REG_TYPE
);
499 size
+= prf2
->u
.s2
.rgPins2
[i
].nMediums
* sizeof(DWORD
);
502 for (i
= 0; i
< prf2
->u
.s2
.cPins2
; i
++)
505 REGFILTERPINS2 rgPin2
= prf2
->u
.s2
.rgPins2
[i
];
508 rrfp
.signature
[0] = '0';
509 rrfp
.signature
[1] = 'p';
510 rrfp
.signature
[2] = 'i';
511 rrfp
.signature
[3] = '3';
512 rrfp
.signature
[0] += i
;
513 rrfp
.dwFlags
= rgPin2
.dwFlags
;
514 rrfp
.dwInstances
= rgPin2
.cInstances
;
515 rrfp
.dwMediaTypes
= rgPin2
.nMediaTypes
;
516 rrfp
.dwMediums
= rgPin2
.nMediums
;
517 rrfp
.bCategory
= rgPin2
.clsPinCategory
? 1 : 0;
519 add_data(&mainStore
, (LPBYTE
)&rrfp
, sizeof(rrfp
));
522 DWORD index
= find_data(&clsidStore
, (const BYTE
*)rgPin2
.clsPinCategory
, sizeof(CLSID
));
524 index
= add_data(&clsidStore
, (const BYTE
*)rgPin2
.clsPinCategory
, sizeof(CLSID
));
527 add_data(&mainStore
, (LPBYTE
)&index
, sizeof(index
));
530 for (j
= 0; j
< rgPin2
.nMediaTypes
; j
++)
533 const CLSID
* clsMinorType
= rgPin2
.lpMediaType
[j
].clsMinorType
? rgPin2
.lpMediaType
[j
].clsMinorType
: &MEDIASUBTYPE_NULL
;
534 rt
.signature
[0] = '0';
535 rt
.signature
[1] = 't';
536 rt
.signature
[2] = 'y';
537 rt
.signature
[3] = '3';
538 rt
.signature
[0] += j
;
540 rt
.dwOffsetMajor
= find_data(&clsidStore
, (const BYTE
*)rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
541 if (rt
.dwOffsetMajor
== -1)
542 rt
.dwOffsetMajor
= add_data(&clsidStore
, (const BYTE
*)rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
543 rt
.dwOffsetMajor
+= size
;
544 rt
.dwOffsetMinor
= find_data(&clsidStore
, (const BYTE
*)clsMinorType
, sizeof(CLSID
));
545 if (rt
.dwOffsetMinor
== -1)
546 rt
.dwOffsetMinor
= add_data(&clsidStore
, (const BYTE
*)clsMinorType
, sizeof(CLSID
));
547 rt
.dwOffsetMinor
+= size
;
549 add_data(&mainStore
, (LPBYTE
)&rt
, sizeof(rt
));
552 for (j
= 0; j
< rgPin2
.nMediums
; j
++)
554 DWORD index
= find_data(&clsidStore
, (const BYTE
*)(rgPin2
.lpMedium
+ j
), sizeof(REGPINMEDIUM
));
556 index
= add_data(&clsidStore
, (const BYTE
*)(rgPin2
.lpMedium
+ j
), sizeof(REGPINMEDIUM
));
559 add_data(&mainStore
, (LPBYTE
)&index
, sizeof(index
));
565 *pcbData
= mainStore
.current
+ clsidStore
.current
;
566 *ppData
= CoTaskMemAlloc(*pcbData
);
573 memcpy(*ppData
, mainStore
.pData
, mainStore
.current
);
574 memcpy((*ppData
) + mainStore
.current
, clsidStore
.pData
, clsidStore
.current
);
577 delete_vector(&mainStore
);
578 delete_vector(&clsidStore
);
582 static HRESULT
FM2_ReadFilterData(BYTE
*pData
, REGFILTER2
* prf2
)
585 struct REG_RF
* prrf
;
588 REGFILTERPINS2
* rgPins2
;
590 prrf
= (struct REG_RF
*)pData
;
593 if (prrf
->dwVersion
!= 2)
595 FIXME("Filter registry version %d not supported\n", prrf
->dwVersion
);
596 ZeroMemory(prf2
, sizeof(*prf2
));
602 TRACE("version = %d, merit = %x, #pins = %d, unused = %x\n",
603 prrf
->dwVersion
, prrf
->dwMerit
, prrf
->dwPins
, prrf
->dwUnused
);
605 prf2
->dwVersion
= prrf
->dwVersion
;
606 prf2
->dwMerit
= prrf
->dwMerit
;
607 prf2
->u
.s2
.cPins2
= prrf
->dwPins
;
608 rgPins2
= CoTaskMemAlloc(prrf
->dwPins
* sizeof(*rgPins2
));
609 prf2
->u
.s2
.rgPins2
= rgPins2
;
610 pCurrent
+= sizeof(struct REG_RF
);
612 for (i
= 0; i
< prrf
->dwPins
; i
++)
614 struct REG_RFP
* prrfp
= (struct REG_RFP
*)pCurrent
;
615 REGPINTYPES
* lpMediaType
;
616 REGPINMEDIUM
* lpMedium
;
619 /* FIXME: check signature */
621 TRACE("\tsignature = %s\n", debugstr_an((const char*)prrfp
->signature
, 4));
623 TRACE("\tpin[%d]: flags = %x, instances = %d, media types = %d, mediums = %d\n",
624 i
, prrfp
->dwFlags
, prrfp
->dwInstances
, prrfp
->dwMediaTypes
, prrfp
->dwMediums
);
626 rgPins2
[i
].dwFlags
= prrfp
->dwFlags
;
627 rgPins2
[i
].cInstances
= prrfp
->dwInstances
;
628 rgPins2
[i
].nMediaTypes
= prrfp
->dwMediaTypes
;
629 rgPins2
[i
].nMediums
= prrfp
->dwMediums
;
630 pCurrent
+= sizeof(struct REG_RFP
);
631 if (prrfp
->bCategory
)
633 CLSID
* clsCat
= CoTaskMemAlloc(sizeof(CLSID
));
634 memcpy(clsCat
, pData
+ *(DWORD
*)(pCurrent
), sizeof(CLSID
));
635 pCurrent
+= sizeof(DWORD
);
636 rgPins2
[i
].clsPinCategory
= clsCat
;
639 rgPins2
[i
].clsPinCategory
= NULL
;
641 if (rgPins2
[i
].nMediaTypes
> 0)
642 lpMediaType
= CoTaskMemAlloc(rgPins2
[i
].nMediaTypes
* sizeof(*lpMediaType
));
646 rgPins2
[i
].lpMediaType
= lpMediaType
;
648 for (j
= 0; j
< rgPins2
[i
].nMediaTypes
; j
++)
650 struct REG_TYPE
* prt
= (struct REG_TYPE
*)pCurrent
;
651 CLSID
* clsMajor
= CoTaskMemAlloc(sizeof(CLSID
));
652 CLSID
* clsMinor
= CoTaskMemAlloc(sizeof(CLSID
));
654 /* FIXME: check signature */
655 TRACE("\t\tsignature = %s\n", debugstr_an((const char*)prt
->signature
, 4));
657 memcpy(clsMajor
, pData
+ prt
->dwOffsetMajor
, sizeof(CLSID
));
658 memcpy(clsMinor
, pData
+ prt
->dwOffsetMinor
, sizeof(CLSID
));
660 lpMediaType
[j
].clsMajorType
= clsMajor
;
661 lpMediaType
[j
].clsMinorType
= clsMinor
;
663 pCurrent
+= sizeof(*prt
);
666 if (rgPins2
[i
].nMediums
> 0)
667 lpMedium
= CoTaskMemAlloc(rgPins2
[i
].nMediums
* sizeof(*lpMedium
));
671 rgPins2
[i
].lpMedium
= lpMedium
;
673 for (j
= 0; j
< rgPins2
[i
].nMediums
; j
++)
675 DWORD dwOffset
= *(DWORD
*)pCurrent
;
677 memcpy(lpMedium
+ j
, pData
+ dwOffset
, sizeof(REGPINMEDIUM
));
679 pCurrent
+= sizeof(dwOffset
);
688 static void FM2_DeleteRegFilter(REGFILTER2
* prf2
)
691 for (i
= 0; i
< prf2
->u
.s2
.cPins2
; i
++)
694 if (prf2
->u
.s2
.rgPins2
[i
].clsPinCategory
)
695 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].clsPinCategory
);
697 for (j
= 0; j
< prf2
->u
.s2
.rgPins2
[i
].nMediaTypes
; j
++)
699 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
[j
].clsMajorType
);
700 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
[j
].clsMinorType
);
702 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
);
703 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMedium
);
705 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
);
708 static HRESULT WINAPI
FilterMapper3_RegisterFilter(
709 IFilterMapper3
* iface
,
710 REFCLSID clsidFilter
,
712 IMoniker
**ppMoniker
,
713 const CLSID
*pclsidCategory
,
714 const OLECHAR
*szInstance
,
715 const REGFILTER2
*prf2
)
717 IParseDisplayName
* pParser
= NULL
;
718 IBindCtx
* pBindCtx
= NULL
;
719 IMoniker
* pMoniker
= NULL
;
720 IPropertyBag
* pPropBag
= NULL
;
722 LPWSTR pwszParseName
= NULL
;
724 static const WCHAR wszDevice
[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
727 LPWSTR szClsidTemp
= NULL
;
728 REGFILTER2 regfilter2
;
729 REGFILTERPINS2
* pregfp2
= NULL
;
731 TRACE("(%s, %s, %p, %s, %s, %p)\n",
732 debugstr_guid(clsidFilter
),
735 debugstr_guid(pclsidCategory
),
736 debugstr_w(szInstance
),
739 if (prf2
->dwVersion
== 2)
743 else if (prf2
->dwVersion
== 1)
747 /* REGFILTER2 structure is converted from version 1 to 2. Tested on Win2k. */
748 regfilter2
.dwVersion
= 2;
749 regfilter2
.dwMerit
= prf2
->dwMerit
;
750 regfilter2
.u
.s2
.cPins2
= prf2
->u
.s1
.cPins
;
751 pregfp2
= CoTaskMemAlloc(prf2
->u
.s1
.cPins
* sizeof(REGFILTERPINS2
));
752 regfilter2
.u
.s2
.rgPins2
= pregfp2
;
753 for (i
= 0; i
< prf2
->u
.s1
.cPins
; i
++)
756 if (prf2
->u
.s1
.rgPins
[i
].bRendered
)
757 flags
|= REG_PINFLAG_B_RENDERER
;
758 if (prf2
->u
.s1
.rgPins
[i
].bOutput
)
759 flags
|= REG_PINFLAG_B_OUTPUT
;
760 if (prf2
->u
.s1
.rgPins
[i
].bZero
)
761 flags
|= REG_PINFLAG_B_ZERO
;
762 if (prf2
->u
.s1
.rgPins
[i
].bMany
)
763 flags
|= REG_PINFLAG_B_MANY
;
764 pregfp2
[i
].dwFlags
= flags
;
765 pregfp2
[i
].cInstances
= 1;
766 pregfp2
[i
].nMediaTypes
= prf2
->u
.s1
.rgPins
[i
].nMediaTypes
;
767 pregfp2
[i
].lpMediaType
= prf2
->u
.s1
.rgPins
[i
].lpMediaType
;
768 pregfp2
[i
].nMediums
= 0;
769 pregfp2
[i
].lpMedium
= NULL
;
770 pregfp2
[i
].clsPinCategory
= NULL
;
775 FIXME("dwVersion other that 1 or 2 not supported at the moment\n");
783 /* MSDN mentions the inexistent CLSID_ActiveMovieFilters GUID.
784 * In fact this is the CLSID_LegacyAmFilterCategory one */
785 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
787 /* sizeof... will include the null terminator and
788 * the + 1 is for the separator ('\\'). The -1 is
789 * because CHARS_IN_GUID includes the null terminator
791 nameLen
= sizeof(wszDevice
)/sizeof(wszDevice
[0]) + CHARS_IN_GUID
- 1 + 1;
794 nameLen
+= strlenW(szInstance
);
796 nameLen
+= CHARS_IN_GUID
- 1; /* CHARS_IN_GUID includes null terminator */
798 pCurrent
= pwszParseName
= CoTaskMemAlloc(nameLen
*sizeof(WCHAR
));
800 return E_OUTOFMEMORY
;
802 strcpyW(pwszParseName
, wszDevice
);
803 pCurrent
+= strlenW(wszDevice
);
805 hr
= StringFromCLSID(pclsidCategory
, &szClsidTemp
);
809 memcpy(pCurrent
, szClsidTemp
, CHARS_IN_GUID
* sizeof(WCHAR
));
810 pCurrent
+= CHARS_IN_GUID
- 1;
814 strcpyW(pCurrent
+1, szInstance
);
817 CoTaskMemFree(szClsidTemp
);
820 hr
= StringFromCLSID(clsidFilter
, &szClsidTemp
);
822 strcpyW(pCurrent
+1, szClsidTemp
);
827 hr
= CoCreateInstance(&CLSID_CDeviceMoniker
, NULL
, CLSCTX_INPROC
, &IID_IParseDisplayName
, (LPVOID
*)&pParser
);
830 hr
= CreateBindCtx(0, &pBindCtx
);
833 hr
= IParseDisplayName_ParseDisplayName(pParser
, pBindCtx
, pwszParseName
, &ulEaten
, &pMoniker
);
836 IBindCtx_Release(pBindCtx
);
838 IParseDisplayName_Release(pParser
);
841 hr
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
844 hr
= FM2_WriteFriendlyName(pPropBag
, szName
);
847 hr
= FM2_WriteClsid(pPropBag
, clsidFilter
);
854 hr
= FM2_WriteFilterData(®filter2
, &pData
, &cbData
);
859 SAFEARRAYBOUND saBound
;
862 saBound
.cElements
= cbData
;
863 psa
= SafeArrayCreate(VT_UI1
, 1, &saBound
);
866 ERR("Couldn't create SAFEARRAY\n");
873 hr
= SafeArrayAccessData(psa
, (LPVOID
*)&pbSAData
);
876 memcpy(pbSAData
, pData
, cbData
);
877 hr
= SafeArrayUnaccessData(psa
);
881 V_VT(&var
) = VT_ARRAY
| VT_UI1
;
882 V_UNION(&var
, parray
) = psa
;
885 hr
= IPropertyBag_Write(pPropBag
, wszFilterDataName
, &var
);
888 SafeArrayDestroy(psa
);
889 CoTaskMemFree(pData
);
894 IPropertyBag_Release(pPropBag
);
895 CoTaskMemFree(szClsidTemp
);
896 CoTaskMemFree(pwszParseName
);
898 if (SUCCEEDED(hr
) && ppMoniker
)
899 *ppMoniker
= pMoniker
;
901 IMoniker_Release(pMoniker
);
903 CoTaskMemFree(pregfp2
);
905 TRACE("-- returning %x\n", hr
);
910 /* internal helper function */
911 static BOOL
MatchTypes(
914 const REGPINTYPES
* pPinTypes
,
916 const GUID
* pMatchTypes
)
921 if ((nMatchTypes
== 0) && (nPinTypes
> 0))
924 for (j
= 0; j
< nPinTypes
; j
++)
927 for (i
= 0; i
< nMatchTypes
*2; i
+=2)
929 if (((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMajorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMajorType
, &pMatchTypes
[i
])) &&
930 ((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMinorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
+1], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMinorType
, &pMatchTypes
[i
+1])))
940 /* internal helper function for qsort of MONIKER_MERIT array */
941 static int mm_compare(const void * left
, const void * right
)
943 const struct MONIKER_MERIT
* mmLeft
= left
;
944 const struct MONIKER_MERIT
* mmRight
= right
;
946 if (mmLeft
->dwMerit
== mmRight
->dwMerit
)
948 if (mmLeft
->dwMerit
> mmRight
->dwMerit
)
954 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
955 * (GUID_NULL's in input to function automatically treated as wild cards)
956 * Input/Output needed means match only on criteria if TRUE (with zero input types
957 * meaning match any input/output pin as long as one exists), otherwise match any
958 * filter that meets the rest of the requirements.
960 static HRESULT WINAPI
FilterMapper3_EnumMatchingFilters(
961 IFilterMapper3
* iface
,
962 IEnumMoniker
**ppEnum
,
968 const GUID
*pInputTypes
,
969 const REGPINMEDIUM
*pMedIn
,
970 const CLSID
*pPinCategoryIn
,
974 const GUID
*pOutputTypes
,
975 const REGPINMEDIUM
*pMedOut
,
976 const CLSID
*pPinCategoryOut
)
978 ICreateDevEnum
* pCreateDevEnum
;
979 IMoniker
* pMonikerCat
;
980 IEnumMoniker
* pEnumCat
;
982 struct Vector monikers
= {NULL
, 0, 0};
984 TRACE("(%p, %x, %s, %x, %s, %d, %p, %p, %p, %s, %s, %p, %p, %p)\n",
987 bExactMatch
? "true" : "false",
989 bInputNeeded
? "true" : "false",
994 bRender
? "true" : "false",
995 bOutputNeeded
? "true" : "false",
1002 FIXME("dwFlags = %x not implemented\n", dwFlags
);
1007 hr
= CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (LPVOID
*)&pCreateDevEnum
);
1011 hr
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &CLSID_ActiveMovieCategories
, &pEnumCat
, 0);
1013 ICreateDevEnum_Release(pCreateDevEnum
);
1017 while (IEnumMoniker_Next(pEnumCat
, 1, &pMonikerCat
, NULL
) == S_OK
)
1019 IPropertyBag
* pPropBagCat
= NULL
;
1021 HRESULT hrSub
; /* this is so that one buggy filter
1022 doesn't make the whole lot fail */
1026 hrSub
= IMoniker_BindToStorage(pMonikerCat
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
1028 if (SUCCEEDED(hrSub
))
1029 hrSub
= IPropertyBag_Read(pPropBagCat
, wszMeritName
, &var
, NULL
);
1031 if (SUCCEEDED(hrSub
) && (V_UNION(&var
, ulVal
) >= dwMerit
))
1034 IEnumMoniker
* pEnum
;
1035 IMoniker
* pMoniker
;
1039 if (TRACE_ON(quartz
))
1042 V_VT(&temp
) = VT_EMPTY
;
1043 IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &temp
, NULL
);
1044 TRACE("Considering category %s\n", debugstr_w(V_UNION(&temp
, bstrVal
)));
1045 VariantClear(&temp
);
1048 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
1050 if (SUCCEEDED(hrSub
))
1051 hrSub
= CLSIDFromString(V_UNION(&var
, bstrVal
), &clsidCat
);
1053 if (SUCCEEDED(hrSub
))
1054 hrSub
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &clsidCat
, &pEnum
, 0);
1058 while (IEnumMoniker_Next(pEnum
, 1, &pMoniker
, NULL
) == S_OK
)
1060 IPropertyBag
* pPropBag
= NULL
;
1065 BOOL bInputMatch
= !bInputNeeded
;
1066 BOOL bOutputMatch
= !bOutputNeeded
;
1068 ZeroMemory(&rf2
, sizeof(rf2
));
1071 hrSub
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBag
);
1073 if (TRACE_ON(quartz
))
1076 V_VT(&temp
) = VT_EMPTY
;
1077 IPropertyBag_Read(pPropBag
, wszFriendlyName
, &temp
, NULL
);
1078 TRACE("Considering filter %s\n", debugstr_w(V_UNION(&temp
, bstrVal
)));
1079 VariantClear(&temp
);
1082 if (SUCCEEDED(hrSub
))
1084 hrSub
= IPropertyBag_Read(pPropBag
, wszFilterDataName
, &var
, NULL
);
1087 if (SUCCEEDED(hrSub
))
1088 hrSub
= SafeArrayAccessData(V_UNION(&var
, parray
), (LPVOID
*)&pData
);
1090 if (SUCCEEDED(hrSub
))
1091 hrSub
= FM2_ReadFilterData(pData
, &rf2
);
1094 SafeArrayUnaccessData(V_UNION(&var
, parray
));
1098 /* Logic used for bInputMatch expression:
1099 * There exists some pin such that bInputNeeded implies (pin is an input and
1100 * (bRender implies pin has render flag) and major/minor types members of
1102 * bOutputMatch is similar, but without the "bRender implies ..." part
1103 * and substituting variables names containing input for output
1106 /* determine whether filter meets requirements */
1107 if (SUCCEEDED(hrSub
) && (rf2
.dwMerit
>= dwMerit
))
1109 for (i
= 0; (i
< rf2
.u
.s2
.cPins2
) && (!bInputMatch
|| !bOutputMatch
); i
++)
1111 const REGFILTERPINS2
* rfp2
= rf2
.u
.s2
.rgPins2
+ i
;
1113 bInputMatch
= bInputMatch
|| (!(rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1114 (!bRender
|| (rfp2
->dwFlags
& REG_PINFLAG_B_RENDERER
)) &&
1115 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cInputTypes
, pInputTypes
));
1116 bOutputMatch
= bOutputMatch
|| ((rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1117 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cOutputTypes
, pOutputTypes
));
1120 if (bInputMatch
&& bOutputMatch
)
1122 struct MONIKER_MERIT mm
= {pMoniker
, rf2
.dwMerit
};
1123 IMoniker_AddRef(pMoniker
);
1124 add_data(&monikers
, (LPBYTE
)&mm
, sizeof(mm
));
1128 FM2_DeleteRegFilter(&rf2
);
1130 IPropertyBag_Release(pPropBag
);
1131 IMoniker_Release(pMoniker
);
1133 IEnumMoniker_Release(pEnum
);
1139 IPropertyBag_Release(pPropBagCat
);
1140 IMoniker_Release(pMonikerCat
);
1145 IMoniker
** ppMoniker
;
1147 ULONG nMonikerCount
= monikers
.current
/ sizeof(struct MONIKER_MERIT
);
1149 /* sort the monikers in descending merit order */
1150 qsort(monikers
.pData
, nMonikerCount
,
1151 sizeof(struct MONIKER_MERIT
),
1154 /* construct an IEnumMoniker interface */
1155 ppMoniker
= CoTaskMemAlloc(nMonikerCount
* sizeof(IMoniker
*));
1156 for (i
= 0; i
< nMonikerCount
; i
++)
1158 /* no need to AddRef here as already AddRef'd above */
1159 ppMoniker
[i
] = ((struct MONIKER_MERIT
*)monikers
.pData
)[i
].pMoniker
;
1161 hr
= EnumMonikerImpl_Create(ppMoniker
, nMonikerCount
, ppEnum
);
1162 CoTaskMemFree(ppMoniker
);
1165 delete_vector(&monikers
);
1166 IEnumMoniker_Release(pEnumCat
);
1167 ICreateDevEnum_Release(pCreateDevEnum
);
1172 static HRESULT WINAPI
FilterMapper3_GetICreateDevEnum(IFilterMapper3
*iface
, ICreateDevEnum
**ppEnum
)
1174 TRACE("(%p, %p)\n", iface
, ppEnum
);
1177 return CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (void**)ppEnum
);
1180 static const IFilterMapper3Vtbl fm3vtbl
=
1183 FilterMapper3_QueryInterface
,
1184 FilterMapper3_AddRef
,
1185 FilterMapper3_Release
,
1187 FilterMapper3_CreateCategory
,
1188 FilterMapper3_UnregisterFilter
,
1189 FilterMapper3_RegisterFilter
,
1190 FilterMapper3_EnumMatchingFilters
,
1191 FilterMapper3_GetICreateDevEnum
1194 /*** IUnknown methods ***/
1196 static HRESULT WINAPI
FilterMapper_QueryInterface(IFilterMapper
* iface
, REFIID riid
, LPVOID
*ppv
)
1198 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1200 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1202 return FilterMapper3_QueryInterface(&This
->IFilterMapper3_iface
, riid
, ppv
);
1205 static ULONG WINAPI
FilterMapper_AddRef(IFilterMapper
* iface
)
1207 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1209 return FilterMapper3_AddRef(&This
->IFilterMapper3_iface
);
1212 static ULONG WINAPI
FilterMapper_Release(IFilterMapper
* iface
)
1214 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1216 return FilterMapper3_Release(&This
->IFilterMapper3_iface
);
1219 /*** IFilterMapper methods ***/
1221 static HRESULT WINAPI
FilterMapper_EnumMatchingFilters(
1222 IFilterMapper
* iface
,
1223 IEnumRegFilters
**ppEnum
,
1233 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1236 IEnumMoniker
* ppEnumMoniker
;
1239 ULONG idx
= 0, nb_mon
= 0;
1240 REGFILTER
* regfilters
;
1243 TRACE("(%p/%p)->(%p, %x, %s, %s, %s, %s, %s, %s, %s) stub!\n",
1247 bInputNeeded
? "true" : "false",
1248 debugstr_guid(&clsInMaj
),
1249 debugstr_guid(&clsInSub
),
1250 bRender
? "true" : "false",
1251 bOutputNeeded
? "true" : "false",
1252 debugstr_guid(&clsOutMaj
),
1253 debugstr_guid(&clsOutSub
));
1255 InputType
[0] = clsInMaj
;
1256 InputType
[1] = clsInSub
;
1257 OutputType
[0] = clsOutMaj
;
1258 OutputType
[1] = clsOutSub
;
1262 hr
= IFilterMapper3_EnumMatchingFilters(&This
->IFilterMapper3_iface
, &ppEnumMoniker
, 0, TRUE
,
1263 dwMerit
, bInputNeeded
, 1, InputType
, NULL
, &GUID_NULL
, bRender
, bOutputNeeded
, 1,
1264 OutputType
, NULL
, &GUID_NULL
);
1269 while(IEnumMoniker_Next(ppEnumMoniker
, 1, &IMon
, &nb
) == S_OK
)
1271 IMoniker_Release(IMon
);
1277 IEnumMoniker_Release(ppEnumMoniker
);
1278 return IEnumRegFiltersImpl_Construct(NULL
, 0, ppEnum
);
1281 regfilters
= CoTaskMemAlloc(nb_mon
* sizeof(REGFILTER
));
1284 IEnumMoniker_Release(ppEnumMoniker
);
1285 return E_OUTOFMEMORY
;
1287 ZeroMemory(regfilters
, nb_mon
* sizeof(REGFILTER
)); /* will prevent bad free of Name in case of error. */
1289 IEnumMoniker_Reset(ppEnumMoniker
);
1290 while(IEnumMoniker_Next(ppEnumMoniker
, 1, &IMon
, &nb
) == S_OK
)
1292 IPropertyBag
* pPropBagCat
= NULL
;
1300 hrSub
= IMoniker_BindToStorage(IMon
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
1302 if (SUCCEEDED(hrSub
))
1303 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
1305 if (SUCCEEDED(hrSub
))
1306 hrSub
= CLSIDFromString(V_UNION(&var
, bstrVal
), &clsid
);
1310 if (SUCCEEDED(hrSub
))
1311 hrSub
= IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &var
, NULL
);
1313 if (SUCCEEDED(hrSub
))
1315 len
= (strlenW(V_UNION(&var
, bstrVal
))+1) * sizeof(WCHAR
);
1316 if (!(regfilters
[idx
].Name
= CoTaskMemAlloc(len
*2)))
1320 if (SUCCEEDED(hrSub
) && regfilters
[idx
].Name
)
1322 memcpy(regfilters
[idx
].Name
, V_UNION(&var
, bstrVal
), len
);
1323 regfilters
[idx
].Clsid
= clsid
;
1328 IPropertyBag_Release(pPropBagCat
);
1329 IMoniker_Release(IMon
);
1335 hr
= IEnumRegFiltersImpl_Construct(regfilters
, nb_mon
, ppEnum
);
1338 for (idx
= 0; idx
< nb_mon
; idx
++)
1339 CoTaskMemFree(regfilters
[idx
].Name
);
1340 CoTaskMemFree(regfilters
);
1341 IEnumMoniker_Release(ppEnumMoniker
);
1347 static HRESULT WINAPI
FilterMapper_RegisterFilter(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, DWORD dwMerit
)
1350 LPWSTR wszClsid
= NULL
;
1353 WCHAR wszKeyName
[ARRAYSIZE(wszFilterSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1355 TRACE("(%p)->(%s, %s, %x)\n", iface
, debugstr_guid(&clsid
), debugstr_w(szName
), dwMerit
);
1357 hr
= StringFromCLSID(&clsid
, &wszClsid
);
1361 strcpyW(wszKeyName
, wszFilterSlash
);
1362 strcatW(wszKeyName
, wszClsid
);
1364 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
1365 hr
= HRESULT_FROM_WIN32(lRet
);
1370 lRet
= RegSetValueExW(hKey
, NULL
, 0, REG_SZ
, (const BYTE
*)szName
, (strlenW(szName
) + 1) * sizeof(WCHAR
));
1371 hr
= HRESULT_FROM_WIN32(lRet
);
1377 strcpyW(wszKeyName
, wszClsidSlash
);
1378 strcatW(wszKeyName
, wszClsid
);
1380 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
1381 hr
= HRESULT_FROM_WIN32(lRet
);
1386 lRet
= RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwMerit
, sizeof(dwMerit
));
1387 hr
= HRESULT_FROM_WIN32(lRet
);
1391 CoTaskMemFree(wszClsid
);
1396 static HRESULT WINAPI
FilterMapper_RegisterFilterInstance(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, CLSID
*MRId
)
1398 TRACE("(%p)->(%s, %s, %p)\n", iface
, debugstr_guid(&clsid
), debugstr_w(szName
), MRId
);
1400 /* Not implemented in Windows (tested on Win2k) */
1405 static HRESULT WINAPI
FilterMapper_RegisterPin(
1406 IFilterMapper
* iface
,
1413 CLSID ConnectsToFilter
,
1414 LPCWSTR ConnectsToPin
)
1418 LPWSTR wszClsid
= NULL
;
1420 HKEY hPinsKey
= NULL
;
1421 WCHAR
* wszPinsKeyName
;
1422 WCHAR wszKeyName
[ARRAYSIZE(wszClsidSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1424 TRACE("(%p)->(%s, %s, %d, %d, %d, %d, %s, %s)\n", iface
, debugstr_guid(&Filter
), debugstr_w(szName
), bRendered
,
1425 bOutput
, bZero
, bMany
, debugstr_guid(&ConnectsToFilter
), debugstr_w(ConnectsToPin
));
1427 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1431 strcpyW(wszKeyName
, wszClsidSlash
);
1432 strcatW(wszKeyName
, wszClsid
);
1434 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1435 hr
= HRESULT_FROM_WIN32(lRet
);
1440 wszPinsKeyName
= CoTaskMemAlloc((strlenW(wszPins
) + 1 + strlenW(szName
) + 1) * 2);
1441 if (!wszPinsKeyName
)
1447 strcpyW(wszPinsKeyName
, wszPins
);
1448 strcatW(wszPinsKeyName
, wszSlash
);
1449 strcatW(wszPinsKeyName
, szName
);
1451 lRet
= RegCreateKeyExW(hKey
, wszPinsKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hPinsKey
, NULL
);
1452 hr
= HRESULT_FROM_WIN32(lRet
);
1453 CoTaskMemFree(wszPinsKeyName
);
1458 lRet
= RegSetValueExW(hPinsKey
, wszAllowedMany
, 0, REG_DWORD
, (LPBYTE
)&bMany
, sizeof(bMany
));
1459 hr
= HRESULT_FROM_WIN32(lRet
);
1464 lRet
= RegSetValueExW(hPinsKey
, wszAllowedZero
, 0, REG_DWORD
, (LPBYTE
)&bZero
, sizeof(bZero
));
1465 hr
= HRESULT_FROM_WIN32(lRet
);
1470 lRet
= RegSetValueExW(hPinsKey
, wszDirection
, 0, REG_DWORD
, (LPBYTE
)&bOutput
, sizeof(bOutput
));
1471 hr
= HRESULT_FROM_WIN32(lRet
);
1476 lRet
= RegSetValueExW(hPinsKey
, wszIsRendered
, 0, REG_DWORD
, (LPBYTE
)&bRendered
, sizeof(bRendered
));
1477 hr
= HRESULT_FROM_WIN32(lRet
);
1482 HKEY hkeyDummy
= NULL
;
1484 lRet
= RegCreateKeyExW(hPinsKey
, wszTypes
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkeyDummy
, NULL
);
1485 hr
= HRESULT_FROM_WIN32(lRet
);
1487 if (hkeyDummy
) RegCloseKey(hkeyDummy
);
1490 CoTaskMemFree(wszClsid
);
1494 CloseHandle(hPinsKey
);
1500 static HRESULT WINAPI
FilterMapper_RegisterPinType(
1501 IFilterMapper
* iface
,
1509 LPWSTR wszClsid
= NULL
;
1510 LPWSTR wszClsidMajorType
= NULL
;
1511 LPWSTR wszClsidSubType
= NULL
;
1513 WCHAR
* wszTypesKey
;
1514 WCHAR wszKeyName
[MAX_PATH
];
1516 TRACE("(%p)->(%s, %s, %s, %s)\n", iface
, debugstr_guid(&clsFilter
), debugstr_w(szName
),
1517 debugstr_guid(&clsMajorType
), debugstr_guid(&clsSubType
));
1519 hr
= StringFromCLSID(&clsFilter
, &wszClsid
);
1523 hr
= StringFromCLSID(&clsMajorType
, &wszClsidMajorType
);
1528 hr
= StringFromCLSID(&clsSubType
, &wszClsidSubType
);
1533 wszTypesKey
= CoTaskMemAlloc((strlenW(wszClsidSlash
) + strlenW(wszClsid
) + strlenW(wszPins
) +
1534 strlenW(szName
) + strlenW(wszTypes
) + 3 + 1) * 2);
1541 strcpyW(wszTypesKey
, wszClsidSlash
);
1542 strcatW(wszTypesKey
, wszClsid
);
1543 strcatW(wszTypesKey
, wszSlash
);
1544 strcatW(wszTypesKey
, wszPins
);
1545 strcatW(wszTypesKey
, wszSlash
);
1546 strcatW(wszTypesKey
, szName
);
1547 strcatW(wszTypesKey
, wszSlash
);
1548 strcatW(wszTypesKey
, wszTypes
);
1550 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszTypesKey
, 0, KEY_WRITE
, &hKey
);
1551 hr
= HRESULT_FROM_WIN32(lRet
);
1552 CoTaskMemFree(wszTypesKey
);
1557 HKEY hkeyDummy
= NULL
;
1559 strcpyW(wszKeyName
, wszClsidMajorType
);
1560 strcatW(wszKeyName
, wszSlash
);
1561 strcatW(wszKeyName
, wszClsidSubType
);
1563 lRet
= RegCreateKeyExW(hKey
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkeyDummy
, NULL
);
1564 hr
= HRESULT_FROM_WIN32(lRet
);
1567 if (hkeyDummy
) RegCloseKey(hkeyDummy
);
1570 CoTaskMemFree(wszClsid
);
1571 CoTaskMemFree(wszClsidMajorType
);
1572 CoTaskMemFree(wszClsidSubType
);
1577 static HRESULT WINAPI
FilterMapper_UnregisterFilter(IFilterMapper
* iface
, CLSID Filter
)
1581 LPWSTR wszClsid
= NULL
;
1583 WCHAR wszKeyName
[ARRAYSIZE(wszClsidSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1585 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(&Filter
));
1587 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1591 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszFilter
, 0, KEY_WRITE
, &hKey
);
1592 hr
= HRESULT_FROM_WIN32(lRet
);
1597 lRet
= RegDeleteKeyW(hKey
, wszClsid
);
1598 hr
= HRESULT_FROM_WIN32(lRet
);
1604 strcpyW(wszKeyName
, wszClsidSlash
);
1605 strcatW(wszKeyName
, wszClsid
);
1607 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1608 hr
= HRESULT_FROM_WIN32(lRet
);
1613 lRet
= RegDeleteValueW(hKey
, wszMeritName
);
1614 if (lRet
!= ERROR_SUCCESS
)
1615 hr
= HRESULT_FROM_WIN32(lRet
);
1617 lRet
= RegDeleteTreeW(hKey
, wszPins
);
1618 if (lRet
!= ERROR_SUCCESS
)
1619 hr
= HRESULT_FROM_WIN32(lRet
);
1624 CoTaskMemFree(wszClsid
);
1629 static HRESULT WINAPI
FilterMapper_UnregisterFilterInstance(IFilterMapper
* iface
, CLSID MRId
)
1631 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(&MRId
));
1633 /* Not implemented in Windows (tested on Win2k) */
1638 static HRESULT WINAPI
FilterMapper_UnregisterPin(IFilterMapper
* iface
, CLSID Filter
, LPCWSTR Name
)
1642 LPWSTR wszClsid
= NULL
;
1644 WCHAR
* wszPinNameKey
;
1645 WCHAR wszKeyName
[ARRAYSIZE(wszClsidSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1647 TRACE("(%p)->(%s, %s)\n", iface
, debugstr_guid(&Filter
), debugstr_w(Name
));
1650 return E_INVALIDARG
;
1652 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1656 strcpyW(wszKeyName
, wszClsidSlash
);
1657 strcatW(wszKeyName
, wszClsid
);
1659 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1660 hr
= HRESULT_FROM_WIN32(lRet
);
1665 wszPinNameKey
= CoTaskMemAlloc((strlenW(wszPins
) + 1 + strlenW(Name
) + 1) * 2);
1672 strcpyW(wszPinNameKey
, wszPins
);
1673 strcatW(wszPinNameKey
, wszSlash
);
1674 strcatW(wszPinNameKey
, Name
);
1676 lRet
= RegDeleteTreeW(hKey
, wszPinNameKey
);
1677 hr
= HRESULT_FROM_WIN32(lRet
);
1678 CoTaskMemFree(wszPinNameKey
);
1681 CoTaskMemFree(wszClsid
);
1688 static const IFilterMapperVtbl fmvtbl
=
1691 FilterMapper_QueryInterface
,
1692 FilterMapper_AddRef
,
1693 FilterMapper_Release
,
1695 FilterMapper_RegisterFilter
,
1696 FilterMapper_RegisterFilterInstance
,
1697 FilterMapper_RegisterPin
,
1698 FilterMapper_RegisterPinType
,
1699 FilterMapper_UnregisterFilter
,
1700 FilterMapper_UnregisterFilterInstance
,
1701 FilterMapper_UnregisterPin
,
1702 FilterMapper_EnumMatchingFilters
1706 /*** IUnknown methods ***/
1707 static HRESULT WINAPI
AMFilterData_QueryInterface(IAMFilterData
* iface
, REFIID riid
, LPVOID
*ppv
)
1709 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1711 return FilterMapper3_QueryInterface(&This
->IFilterMapper3_iface
, riid
, ppv
);
1714 static ULONG WINAPI
AMFilterData_AddRef(IAMFilterData
* iface
)
1716 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1718 return FilterMapper3_AddRef(&This
->IFilterMapper3_iface
);
1721 static ULONG WINAPI
AMFilterData_Release(IAMFilterData
* iface
)
1723 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1725 return FilterMapper3_Release(&This
->IFilterMapper3_iface
);
1728 /*** IAMFilterData methods ***/
1729 static HRESULT WINAPI
AMFilterData_ParseFilterData(IAMFilterData
* iface
,
1730 BYTE
*pData
, ULONG cb
,
1731 BYTE
**ppRegFilter2
)
1733 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1735 static REGFILTER2
*prf2
;
1737 TRACE("(%p/%p)->(%p, %d, %p)\n", This
, iface
, pData
, cb
, ppRegFilter2
);
1739 prf2
= CoTaskMemAlloc(sizeof(*prf2
));
1741 return E_OUTOFMEMORY
;
1742 *ppRegFilter2
= (BYTE
*)&prf2
;
1744 hr
= FM2_ReadFilterData(pData
, prf2
);
1747 CoTaskMemFree(prf2
);
1748 *ppRegFilter2
= NULL
;
1754 static HRESULT WINAPI
AMFilterData_CreateFilterData(IAMFilterData
* iface
,
1756 BYTE
**pRegFilterData
,
1759 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1761 TRACE("(%p/%p)->(%p, %p, %p)\n", This
, iface
, prf2
, pRegFilterData
, pcb
);
1763 return FM2_WriteFilterData(prf2
, pRegFilterData
, pcb
);
1766 static const IAMFilterDataVtbl AMFilterDataVtbl
= {
1767 AMFilterData_QueryInterface
,
1768 AMFilterData_AddRef
,
1769 AMFilterData_Release
,
1770 AMFilterData_ParseFilterData
,
1771 AMFilterData_CreateFilterData