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 #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 const GUID IID_IAMFilterData
= {
85 0x97f7c4d4, 0x547b, 0x4a5f, { 0x83,0x32, 0x53,0x64,0x30,0xad,0x2e,0x4d }
89 typedef struct FilterMapper2Impl
91 const IFilterMapper2Vtbl
*lpVtbl
;
92 const IFilterMapperVtbl
*lpVtblFilterMapper
;
93 const IAMFilterDataVtbl
*lpVtblAMFilterData
;
97 static const IFilterMapper2Vtbl fm2vtbl
;
98 static const IFilterMapperVtbl fmvtbl
;
99 static const IAMFilterDataVtbl AMFilterDataVtbl
;
101 static inline FilterMapper2Impl
*impl_from_IFilterMapper( IFilterMapper
*iface
)
103 return (FilterMapper2Impl
*)((char*)iface
- FIELD_OFFSET(FilterMapper2Impl
, lpVtblFilterMapper
));
106 static inline FilterMapper2Impl
*impl_from_IAMFilterData( IAMFilterData
*iface
)
108 return (FilterMapper2Impl
*)((char*)iface
- FIELD_OFFSET(FilterMapper2Impl
, lpVtblAMFilterData
));
111 static const WCHAR wszClsidSlash
[] = {'C','L','S','I','D','\\',0};
112 static const WCHAR wszSlashInstance
[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
113 static const WCHAR wszSlash
[] = {'\\',0};
115 /* CLSID property in media category Moniker */
116 static const WCHAR wszClsidName
[] = {'C','L','S','I','D',0};
117 /* FriendlyName property in media category Moniker */
118 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
119 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
120 static const WCHAR wszMeritName
[] = {'M','e','r','i','t',0};
121 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
122 static const WCHAR wszFilterDataName
[] = {'F','i','l','t','e','r','D','a','t','a',0};
123 /* For filters registered with IFilterMapper */
124 static const WCHAR wszFilterSlash
[] = {'F','i','l','t','e','r','\\',0};
125 static const WCHAR wszFilter
[] = {'F','i','l','t','e','r',0};
126 /* For pins registered with IFilterMapper */
127 static const WCHAR wszPins
[] = {'P','i','n','s',0};
128 static const WCHAR wszAllowedMany
[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
129 static const WCHAR wszAllowedZero
[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
130 static const WCHAR wszDirection
[] = {'D','i','r','e','c','t','i','o','n',0};
131 static const WCHAR wszIsRendered
[] = {'I','s','R','e','n','d','e','r','e','d',0};
132 /* For types registered with IFilterMapper */
133 static const WCHAR wszTypes
[] = {'T','y','p','e','s',0};
136 /* registry format for REGFILTER2 */
147 BYTE signature
[4]; /* e.g. "0pi3" */
152 DWORD bCategory
; /* is there a category clsid? */
153 /* optional: dwOffsetCategoryClsid */
158 BYTE signature
[4]; /* e.g. "0ty3" */
173 int capacity
; /* in bytes */
174 int current
; /* pointer to next free byte */
177 /* returns the position it was added at */
178 static int add_data(struct Vector
* v
, const BYTE
* pData
, int size
)
180 int index
= v
->current
;
181 if (v
->current
+ size
> v
->capacity
)
183 LPBYTE pOldData
= v
->pData
;
184 v
->capacity
= (v
->capacity
+ size
) * 2;
185 v
->pData
= CoTaskMemAlloc(v
->capacity
);
186 memcpy(v
->pData
, pOldData
, v
->current
);
187 CoTaskMemFree(pOldData
);
189 memcpy(v
->pData
+ v
->current
, pData
, size
);
194 static int find_data(const struct Vector
* v
, const BYTE
* pData
, int size
)
197 for (index
= 0; index
< v
->current
; index
++)
198 if (!memcmp(v
->pData
+ index
, pData
, size
))
204 static void delete_vector(struct Vector
* v
)
206 CoTaskMemFree(v
->pData
);
211 HRESULT
FilterMapper2_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
213 FilterMapper2Impl
* pFM2impl
;
215 TRACE("(%p, %p)\n", pUnkOuter
, ppObj
);
218 return CLASS_E_NOAGGREGATION
;
220 pFM2impl
= CoTaskMemAlloc(sizeof(*pFM2impl
));
222 return E_OUTOFMEMORY
;
224 pFM2impl
->lpVtbl
= &fm2vtbl
;
225 pFM2impl
->lpVtblFilterMapper
= &fmvtbl
;
226 pFM2impl
->lpVtblAMFilterData
= &AMFilterDataVtbl
;
227 pFM2impl
->refCount
= 1;
231 TRACE("-- created at %p\n", pFM2impl
);
236 HRESULT
FilterMapper_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
238 FilterMapper2Impl
*pFM2impl
;
241 TRACE("(%p, %p)\n", pUnkOuter
, ppObj
);
243 hr
= FilterMapper2_create(pUnkOuter
, (LPVOID
*)&pFM2impl
);
247 *ppObj
= &pFM2impl
->lpVtblFilterMapper
;
252 /*** IUnknown methods ***/
254 static HRESULT WINAPI
FilterMapper2_QueryInterface(IFilterMapper2
* iface
, REFIID riid
, LPVOID
*ppv
)
256 FilterMapper2Impl
*This
= (FilterMapper2Impl
*)iface
;
258 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
262 if (IsEqualIID(riid
, &IID_IUnknown
))
264 else if (IsEqualIID(riid
, &IID_IFilterMapper2
))
266 else if (IsEqualIID(riid
, &IID_IFilterMapper
))
267 *ppv
= &This
->lpVtblFilterMapper
;
268 else if (IsEqualIID(riid
, &IID_IAMFilterData
))
269 *ppv
= &This
->lpVtblAMFilterData
;
273 IUnknown_AddRef((IUnknown
*)*ppv
);
277 FIXME("No interface for %s\n", debugstr_guid(riid
));
278 return E_NOINTERFACE
;
281 static ULONG WINAPI
FilterMapper2_AddRef(IFilterMapper2
* iface
)
283 FilterMapper2Impl
*This
= (FilterMapper2Impl
*)iface
;
284 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
286 TRACE("(%p)->() AddRef from %d\n", This
, refCount
- 1);
291 static ULONG WINAPI
FilterMapper2_Release(IFilterMapper2
* iface
)
293 FilterMapper2Impl
*This
= (FilterMapper2Impl
*)iface
;
294 ULONG refCount
= InterlockedDecrement(&This
->refCount
);
296 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
306 /*** IFilterMapper2 methods ***/
308 static HRESULT WINAPI
FilterMapper2_CreateCategory(
309 IFilterMapper2
* iface
,
310 REFCLSID clsidCategory
,
311 DWORD dwCategoryMerit
,
312 LPCWSTR szDescription
)
314 LPWSTR wClsidAMCat
= NULL
;
315 LPWSTR wClsidCategory
= NULL
;
316 WCHAR wszKeyName
[ARRAYSIZE(wszClsidSlash
)-1 + ARRAYSIZE(wszSlashInstance
)-1 + (CHARS_IN_GUID
-1) * 2 + 1];
321 TRACE("(%s, %x, %s)\n", debugstr_guid(clsidCategory
), dwCategoryMerit
, debugstr_w(szDescription
));
323 hr
= StringFromCLSID(&CLSID_ActiveMovieCategories
, &wClsidAMCat
);
327 hr
= StringFromCLSID(clsidCategory
, &wClsidCategory
);
332 strcpyW(wszKeyName
, wszClsidSlash
);
333 strcatW(wszKeyName
, wClsidAMCat
);
334 strcatW(wszKeyName
, wszSlashInstance
);
335 strcatW(wszKeyName
, wClsidCategory
);
337 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
338 hr
= HRESULT_FROM_WIN32(lRet
);
343 lRet
= RegSetValueExW(hKey
, wszFriendlyName
, 0, REG_SZ
, (const BYTE
*)szDescription
, (strlenW(szDescription
) + 1) * sizeof(WCHAR
));
344 hr
= HRESULT_FROM_WIN32(lRet
);
349 lRet
= RegSetValueExW(hKey
, wszClsidName
, 0, REG_SZ
, (LPBYTE
)wClsidCategory
, (strlenW(wClsidCategory
) + 1) * sizeof(WCHAR
));
350 hr
= HRESULT_FROM_WIN32(lRet
);
355 lRet
= RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwCategoryMerit
, sizeof(dwCategoryMerit
));
356 hr
= HRESULT_FROM_WIN32(lRet
);
360 CoTaskMemFree(wClsidCategory
);
361 CoTaskMemFree(wClsidAMCat
);
366 static HRESULT WINAPI
FilterMapper2_UnregisterFilter(
367 IFilterMapper2
* iface
,
368 const CLSID
*pclsidCategory
,
369 const OLECHAR
*szInstance
,
372 WCHAR wszKeyName
[MAX_PATH
];
373 LPWSTR wClsidCategory
= NULL
;
374 LPWSTR wFilter
= NULL
;
377 TRACE("(%p, %s, %s)\n", pclsidCategory
, debugstr_w(szInstance
), debugstr_guid(Filter
));
380 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
382 hr
= StringFromCLSID(pclsidCategory
, &wClsidCategory
);
386 strcpyW(wszKeyName
, wszClsidSlash
);
387 strcatW(wszKeyName
, wClsidCategory
);
388 strcatW(wszKeyName
, wszSlashInstance
);
390 strcatW(wszKeyName
, szInstance
);
393 hr
= StringFromCLSID(Filter
, &wFilter
);
395 strcatW(wszKeyName
, wFilter
);
401 LONG lRet
= RegDeleteKeyW(HKEY_CLASSES_ROOT
, wszKeyName
);
402 hr
= HRESULT_FROM_WIN32(lRet
);
405 CoTaskMemFree(wClsidCategory
);
406 CoTaskMemFree(wFilter
);
411 static HRESULT
FM2_WriteFriendlyName(IPropertyBag
* pPropBag
, LPCWSTR szName
)
415 V_VT(&var
) = VT_BSTR
;
416 V_UNION(&var
, bstrVal
) = (BSTR
)szName
;
418 return IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
421 static HRESULT
FM2_WriteClsid(IPropertyBag
* pPropBag
, REFCLSID clsid
)
423 LPWSTR wszClsid
= NULL
;
427 hr
= StringFromCLSID(clsid
, &wszClsid
);
431 V_VT(&var
) = VT_BSTR
;
432 V_UNION(&var
, bstrVal
) = wszClsid
;
433 hr
= IPropertyBag_Write(pPropBag
, wszClsidName
, &var
);
435 CoTaskMemFree(wszClsid
);
439 static HRESULT
FM2_WriteFilterData(const REGFILTER2
* prf2
, BYTE
**ppData
, ULONG
*pcbData
)
441 int size
= sizeof(struct REG_RF
);
443 struct Vector mainStore
= {NULL
, 0, 0};
444 struct Vector clsidStore
= {NULL
, 0, 0};
448 rrf
.dwVersion
= prf2
->dwVersion
;
449 rrf
.dwMerit
= prf2
->dwMerit
;
450 rrf
.dwPins
= prf2
->u
.s1
.cPins2
;
453 add_data(&mainStore
, (LPBYTE
)&rrf
, sizeof(rrf
));
455 for (i
= 0; i
< prf2
->u
.s1
.cPins2
; i
++)
457 size
+= sizeof(struct REG_RFP
);
458 if (prf2
->u
.s1
.rgPins2
[i
].clsPinCategory
)
459 size
+= sizeof(DWORD
);
460 size
+= prf2
->u
.s1
.rgPins2
[i
].nMediaTypes
* sizeof(struct REG_TYPE
);
461 size
+= prf2
->u
.s1
.rgPins2
[i
].nMediums
* sizeof(DWORD
);
464 for (i
= 0; i
< prf2
->u
.s1
.cPins2
; i
++)
467 REGFILTERPINS2 rgPin2
= prf2
->u
.s1
.rgPins2
[i
];
470 rrfp
.signature
[0] = '0';
471 rrfp
.signature
[1] = 'p';
472 rrfp
.signature
[2] = 'i';
473 rrfp
.signature
[3] = '3';
474 rrfp
.signature
[0] += i
;
475 rrfp
.dwFlags
= rgPin2
.dwFlags
;
476 rrfp
.dwInstances
= rgPin2
.cInstances
;
477 rrfp
.dwMediaTypes
= rgPin2
.nMediaTypes
;
478 rrfp
.dwMediums
= rgPin2
.nMediums
;
479 rrfp
.bCategory
= rgPin2
.clsPinCategory
? 1 : 0;
481 add_data(&mainStore
, (LPBYTE
)&rrfp
, sizeof(rrfp
));
484 DWORD index
= find_data(&clsidStore
, (const BYTE
*)rgPin2
.clsPinCategory
, sizeof(CLSID
));
486 index
= add_data(&clsidStore
, (const BYTE
*)rgPin2
.clsPinCategory
, sizeof(CLSID
));
489 add_data(&mainStore
, (LPBYTE
)&index
, sizeof(index
));
492 for (j
= 0; j
< rgPin2
.nMediaTypes
; j
++)
495 rt
.signature
[0] = '0';
496 rt
.signature
[1] = 't';
497 rt
.signature
[2] = 'y';
498 rt
.signature
[3] = '3';
499 rt
.signature
[0] += j
;
502 rt
.dwOffsetMajor
= find_data(&clsidStore
, (const BYTE
*)rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
503 if (rt
.dwOffsetMajor
== -1)
504 rt
.dwOffsetMajor
= add_data(&clsidStore
, (const BYTE
*)rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
505 rt
.dwOffsetMajor
+= size
;
506 rt
.dwOffsetMinor
= find_data(&clsidStore
, (const BYTE
*)rgPin2
.lpMediaType
[j
].clsMinorType
, sizeof(CLSID
));
507 if (rt
.dwOffsetMinor
== -1)
508 rt
.dwOffsetMinor
= add_data(&clsidStore
, (const BYTE
*)rgPin2
.lpMediaType
[j
].clsMinorType
, sizeof(CLSID
));
509 rt
.dwOffsetMinor
+= size
;
511 add_data(&mainStore
, (LPBYTE
)&rt
, sizeof(rt
));
514 for (j
= 0; j
< rgPin2
.nMediums
; j
++)
516 DWORD index
= find_data(&clsidStore
, (const BYTE
*)(rgPin2
.lpMedium
+ j
), sizeof(REGPINMEDIUM
));
518 index
= add_data(&clsidStore
, (const BYTE
*)(rgPin2
.lpMedium
+ j
), sizeof(REGPINMEDIUM
));
521 add_data(&mainStore
, (LPBYTE
)&index
, sizeof(index
));
527 *pcbData
= mainStore
.current
+ clsidStore
.current
;
528 *ppData
= CoTaskMemAlloc(*pcbData
);
535 memcpy(*ppData
, mainStore
.pData
, mainStore
.current
);
536 memcpy((*ppData
) + mainStore
.current
, clsidStore
.pData
, clsidStore
.current
);
539 delete_vector(&mainStore
);
540 delete_vector(&clsidStore
);
544 static HRESULT
FM2_ReadFilterData(BYTE
*pData
, REGFILTER2
* prf2
)
547 struct REG_RF
* prrf
;
550 REGFILTERPINS2
* rgPins2
;
552 prrf
= (struct REG_RF
*)pData
;
555 if (prrf
->dwVersion
!= 2)
557 FIXME("Filter registry version %d not supported\n", prrf
->dwVersion
);
558 ZeroMemory(prf2
, sizeof(*prf2
));
564 TRACE("version = %d, merit = %x, #pins = %d, unused = %x\n",
565 prrf
->dwVersion
, prrf
->dwMerit
, prrf
->dwPins
, prrf
->dwUnused
);
567 prf2
->dwVersion
= prrf
->dwVersion
;
568 prf2
->dwMerit
= prrf
->dwMerit
;
569 prf2
->u
.s1
.cPins2
= prrf
->dwPins
;
570 rgPins2
= CoTaskMemAlloc(prrf
->dwPins
* sizeof(*rgPins2
));
571 prf2
->u
.s1
.rgPins2
= rgPins2
;
572 pCurrent
+= sizeof(struct REG_RF
);
574 for (i
= 0; i
< prrf
->dwPins
; i
++)
576 struct REG_RFP
* prrfp
= (struct REG_RFP
*)pCurrent
;
577 REGPINTYPES
* lpMediaType
;
578 REGPINMEDIUM
* lpMedium
;
581 /* FIXME: check signature */
583 TRACE("\tsignature = %s\n", debugstr_an((const char*)prrfp
->signature
, 4));
585 TRACE("\tpin[%d]: flags = %x, instances = %d, media types = %d, mediums = %d\n",
586 i
, prrfp
->dwFlags
, prrfp
->dwInstances
, prrfp
->dwMediaTypes
, prrfp
->dwMediums
);
588 rgPins2
[i
].dwFlags
= prrfp
->dwFlags
;
589 rgPins2
[i
].cInstances
= prrfp
->dwInstances
;
590 rgPins2
[i
].nMediaTypes
= prrfp
->dwMediaTypes
;
591 rgPins2
[i
].nMediums
= prrfp
->dwMediums
;
592 pCurrent
+= sizeof(struct REG_RFP
);
593 if (prrfp
->bCategory
)
595 CLSID
* clsCat
= CoTaskMemAlloc(sizeof(CLSID
));
596 memcpy(clsCat
, pData
+ *(DWORD
*)(pCurrent
), sizeof(CLSID
));
597 pCurrent
+= sizeof(DWORD
);
598 rgPins2
[i
].clsPinCategory
= clsCat
;
601 rgPins2
[i
].clsPinCategory
= NULL
;
603 if (rgPins2
[i
].nMediaTypes
> 0)
604 lpMediaType
= CoTaskMemAlloc(rgPins2
[i
].nMediaTypes
* sizeof(*lpMediaType
));
608 rgPins2
[i
].lpMediaType
= lpMediaType
;
610 for (j
= 0; j
< rgPins2
[i
].nMediaTypes
; j
++)
612 struct REG_TYPE
* prt
= (struct REG_TYPE
*)pCurrent
;
613 CLSID
* clsMajor
= CoTaskMemAlloc(sizeof(CLSID
));
614 CLSID
* clsMinor
= CoTaskMemAlloc(sizeof(CLSID
));
616 /* FIXME: check signature */
617 TRACE("\t\tsignature = %s\n", debugstr_an((const char*)prt
->signature
, 4));
619 memcpy(clsMajor
, pData
+ prt
->dwOffsetMajor
, sizeof(CLSID
));
620 memcpy(clsMinor
, pData
+ prt
->dwOffsetMinor
, sizeof(CLSID
));
622 lpMediaType
[j
].clsMajorType
= clsMajor
;
623 lpMediaType
[j
].clsMinorType
= clsMinor
;
625 pCurrent
+= sizeof(*prt
);
628 if (rgPins2
[i
].nMediums
> 0)
629 lpMedium
= CoTaskMemAlloc(rgPins2
[i
].nMediums
* sizeof(*lpMedium
));
633 rgPins2
[i
].lpMedium
= lpMedium
;
635 for (j
= 0; j
< rgPins2
[i
].nMediums
; j
++)
637 DWORD dwOffset
= *(DWORD
*)pCurrent
;
639 memcpy(lpMedium
+ j
, pData
+ dwOffset
, sizeof(REGPINMEDIUM
));
641 pCurrent
+= sizeof(dwOffset
);
650 static void FM2_DeleteRegFilter(REGFILTER2
* prf2
)
653 for (i
= 0; i
< prf2
->u
.s1
.cPins2
; i
++)
656 if (prf2
->u
.s1
.rgPins2
[i
].clsPinCategory
)
657 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].clsPinCategory
);
659 for (j
= 0; j
< prf2
->u
.s1
.rgPins2
[i
].nMediaTypes
; j
++)
661 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].lpMediaType
[j
].clsMajorType
);
662 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].lpMediaType
[j
].clsMinorType
);
664 CoTaskMemFree((LPVOID
)prf2
->u
.s1
.rgPins2
[i
].lpMedium
);
668 static HRESULT WINAPI
FilterMapper2_RegisterFilter(
669 IFilterMapper2
* iface
,
670 REFCLSID clsidFilter
,
672 IMoniker
**ppMoniker
,
673 const CLSID
*pclsidCategory
,
674 const OLECHAR
*szInstance
,
675 const REGFILTER2
*prf2
)
677 IParseDisplayName
* pParser
= NULL
;
678 IBindCtx
* pBindCtx
= NULL
;
679 IMoniker
* pMoniker
= NULL
;
680 IPropertyBag
* pPropBag
= NULL
;
682 LPWSTR pwszParseName
= NULL
;
684 static const WCHAR wszDevice
[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
687 LPWSTR szClsidTemp
= NULL
;
688 REGFILTER2 regfilter2
;
689 REGFILTERPINS2
* pregfp2
= NULL
;
691 TRACE("(%s, %s, %p, %s, %s, %p)\n",
692 debugstr_guid(clsidFilter
),
695 debugstr_guid(pclsidCategory
),
696 debugstr_w(szInstance
),
699 if (prf2
->dwVersion
== 2)
703 else if (prf2
->dwVersion
== 1)
707 /* REGFILTER2 structure is converted from version 1 to 2. Tested on Win2k. */
708 regfilter2
.dwVersion
= 2;
709 regfilter2
.dwMerit
= prf2
->dwMerit
;
710 regfilter2
.u
.s1
.cPins2
= prf2
->u
.s
.cPins
;
711 pregfp2
= CoTaskMemAlloc(prf2
->u
.s
.cPins
* sizeof(REGFILTERPINS2
));
712 regfilter2
.u
.s1
.rgPins2
= pregfp2
;
713 for (i
= 0; i
< prf2
->u
.s
.cPins
; i
++)
716 if (prf2
->u
.s
.rgPins
[i
].bRendered
)
717 flags
|= REG_PINFLAG_B_RENDERER
;
718 if (prf2
->u
.s
.rgPins
[i
].bOutput
)
719 flags
|= REG_PINFLAG_B_OUTPUT
;
720 if (prf2
->u
.s
.rgPins
[i
].bZero
)
721 flags
|= REG_PINFLAG_B_ZERO
;
722 if (prf2
->u
.s
.rgPins
[i
].bMany
)
723 flags
|= REG_PINFLAG_B_MANY
;
724 pregfp2
[i
].dwFlags
= flags
;
725 pregfp2
[i
].cInstances
= 1;
726 pregfp2
[i
].nMediaTypes
= prf2
->u
.s
.rgPins
[i
].nMediaTypes
;
727 pregfp2
[i
].lpMediaType
= prf2
->u
.s
.rgPins
[i
].lpMediaType
;
728 pregfp2
[i
].nMediums
= 0;
729 pregfp2
[i
].lpMedium
= NULL
;
730 pregfp2
[i
].clsPinCategory
= NULL
;
735 FIXME("dwVersion other that 1 or 2 not supported at the moment\n");
743 /* MSDN mentions the inexistent CLSID_ActiveMovieFilters GUID.
744 * In fact this is the CLSID_LegacyAmFilterCategory one */
745 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
747 /* sizeof... will include the null terminator and
748 * the + 1 is for the separator ('\\'). The -1 is
749 * because CHARS_IN_GUID includes the null terminator
751 nameLen
= sizeof(wszDevice
)/sizeof(wszDevice
[0]) + CHARS_IN_GUID
- 1 + 1;
754 nameLen
+= strlenW(szInstance
);
756 nameLen
+= CHARS_IN_GUID
- 1; /* CHARS_IN_GUID includes null terminator */
758 pCurrent
= pwszParseName
= CoTaskMemAlloc(nameLen
*sizeof(WCHAR
));
760 return E_OUTOFMEMORY
;
762 strcpyW(pwszParseName
, wszDevice
);
763 pCurrent
+= strlenW(wszDevice
);
765 hr
= StringFromCLSID(pclsidCategory
, &szClsidTemp
);
769 memcpy(pCurrent
, szClsidTemp
, CHARS_IN_GUID
* sizeof(WCHAR
));
770 pCurrent
+= CHARS_IN_GUID
- 1;
774 strcpyW(pCurrent
+1, szInstance
);
777 CoTaskMemFree(szClsidTemp
);
780 hr
= StringFromCLSID(clsidFilter
, &szClsidTemp
);
782 strcpyW(pCurrent
+1, szClsidTemp
);
787 hr
= CoCreateInstance(&CLSID_CDeviceMoniker
, NULL
, CLSCTX_INPROC
, &IID_IParseDisplayName
, (LPVOID
*)&pParser
);
790 hr
= CreateBindCtx(0, &pBindCtx
);
793 hr
= IParseDisplayName_ParseDisplayName(pParser
, pBindCtx
, pwszParseName
, &ulEaten
, &pMoniker
);
796 IBindCtx_Release(pBindCtx
);
798 IParseDisplayName_Release(pParser
);
801 hr
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
804 hr
= FM2_WriteFriendlyName(pPropBag
, szName
);
807 hr
= FM2_WriteClsid(pPropBag
, clsidFilter
);
814 hr
= FM2_WriteFilterData(®filter2
, &pData
, &cbData
);
819 SAFEARRAYBOUND saBound
;
822 saBound
.cElements
= cbData
;
823 psa
= SafeArrayCreate(VT_UI1
, 1, &saBound
);
826 ERR("Couldn't create SAFEARRAY\n");
833 hr
= SafeArrayAccessData(psa
, (LPVOID
*)&pbSAData
);
836 memcpy(pbSAData
, pData
, cbData
);
837 hr
= SafeArrayUnaccessData(psa
);
841 V_VT(&var
) = VT_ARRAY
| VT_UI1
;
842 V_UNION(&var
, parray
) = psa
;
845 hr
= IPropertyBag_Write(pPropBag
, wszFilterDataName
, &var
);
848 SafeArrayDestroy(psa
);
849 CoTaskMemFree(pData
);
854 IPropertyBag_Release(pPropBag
);
855 CoTaskMemFree(szClsidTemp
);
857 if (SUCCEEDED(hr
) && ppMoniker
)
858 *ppMoniker
= pMoniker
;
860 IMoniker_Release(pMoniker
);
862 CoTaskMemFree(pregfp2
);
864 TRACE("-- returning %x\n", hr
);
869 /* internal helper function */
870 static BOOL
MatchTypes(
873 const REGPINTYPES
* pPinTypes
,
875 const GUID
* pMatchTypes
)
880 if ((nMatchTypes
== 0) && (nPinTypes
> 0))
883 for (j
= 0; j
< nPinTypes
; j
++)
886 for (i
= 0; i
< nMatchTypes
*2; i
+=2)
888 if (((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMajorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMajorType
, &pMatchTypes
[i
])) &&
889 ((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMinorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
+1], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMinorType
, &pMatchTypes
[i
+1])))
899 /* internal helper function for qsort of MONIKER_MERIT array */
900 static int mm_compare(const void * left
, const void * right
)
902 const struct MONIKER_MERIT
* mmLeft
= (const struct MONIKER_MERIT
*)left
;
903 const struct MONIKER_MERIT
* mmRight
= (const struct MONIKER_MERIT
*)right
;
905 if (mmLeft
->dwMerit
== mmRight
->dwMerit
)
907 if (mmLeft
->dwMerit
> mmRight
->dwMerit
)
913 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
914 * (GUID_NULL's in input to function automatically treated as wild cards)
915 * Input/Output needed means match only on criteria if TRUE (with zero input types
916 * meaning match any input/output pin as long as one exists), otherwise match any
917 * filter that meets the rest of the requirements.
919 static HRESULT WINAPI
FilterMapper2_EnumMatchingFilters(
920 IFilterMapper2
* iface
,
921 IEnumMoniker
**ppEnum
,
927 const GUID
*pInputTypes
,
928 const REGPINMEDIUM
*pMedIn
,
929 const CLSID
*pPinCategoryIn
,
933 const GUID
*pOutputTypes
,
934 const REGPINMEDIUM
*pMedOut
,
935 const CLSID
*pPinCategoryOut
)
937 ICreateDevEnum
* pCreateDevEnum
;
938 IMoniker
* pMonikerCat
;
939 IEnumMoniker
* pEnumCat
;
941 struct Vector monikers
= {NULL
, 0, 0};
943 TRACE("(%p, %x, %s, %x, %s, %d, %p, %p, %p, %s, %s, %p, %p, %p)\n",
946 bExactMatch
? "true" : "false",
948 bInputNeeded
? "true" : "false",
953 bRender
? "true" : "false",
954 bOutputNeeded
? "true" : "false",
961 FIXME("dwFlags = %x not implemented\n", dwFlags
);
966 hr
= CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (LPVOID
*)&pCreateDevEnum
);
970 hr
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &CLSID_ActiveMovieCategories
, &pEnumCat
, 0);
972 ICreateDevEnum_Release(pCreateDevEnum
);
976 while (IEnumMoniker_Next(pEnumCat
, 1, &pMonikerCat
, NULL
) == S_OK
)
978 IPropertyBag
* pPropBagCat
= NULL
;
980 HRESULT hrSub
; /* this is so that one buggy filter
981 doesn't make the whole lot fail */
985 hrSub
= IMoniker_BindToStorage(pMonikerCat
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
987 if (SUCCEEDED(hrSub
))
988 hrSub
= IPropertyBag_Read(pPropBagCat
, wszMeritName
, &var
, NULL
);
990 if (SUCCEEDED(hrSub
) && (V_UNION(&var
, ulVal
) >= dwMerit
))
993 IEnumMoniker
* pEnum
;
998 if (TRACE_ON(quartz
))
1001 V_VT(&temp
) = VT_EMPTY
;
1002 IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &temp
, NULL
);
1003 TRACE("Considering category %s\n", debugstr_w(V_UNION(&temp
, bstrVal
)));
1004 VariantClear(&temp
);
1007 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
1009 if (SUCCEEDED(hrSub
))
1010 hrSub
= CLSIDFromString(V_UNION(&var
, bstrVal
), &clsidCat
);
1012 if (SUCCEEDED(hrSub
))
1013 hrSub
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &clsidCat
, &pEnum
, 0);
1017 while (IEnumMoniker_Next(pEnum
, 1, &pMoniker
, NULL
) == S_OK
)
1019 IPropertyBag
* pPropBag
= NULL
;
1024 BOOL bInputMatch
= !bInputNeeded
;
1025 BOOL bOutputMatch
= !bOutputNeeded
;
1027 ZeroMemory(&rf2
, sizeof(rf2
));
1030 hrSub
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBag
);
1032 if (TRACE_ON(quartz
))
1035 V_VT(&temp
) = VT_EMPTY
;
1036 IPropertyBag_Read(pPropBag
, wszFriendlyName
, &temp
, NULL
);
1037 TRACE("Considering filter %s\n", debugstr_w(V_UNION(&temp
, bstrVal
)));
1038 VariantClear(&temp
);
1041 if (SUCCEEDED(hrSub
))
1043 V_VT(&var
) = VT_ARRAY
| VT_UI1
;
1044 hrSub
= IPropertyBag_Read(pPropBag
, wszFilterDataName
, &var
, NULL
);
1047 if (SUCCEEDED(hrSub
))
1048 hrSub
= SafeArrayAccessData(V_UNION(&var
, parray
), (LPVOID
*)&pData
);
1050 if (SUCCEEDED(hrSub
))
1051 hrSub
= FM2_ReadFilterData(pData
, &rf2
);
1054 SafeArrayUnaccessData(V_UNION(&var
, parray
));
1058 /* Logic used for bInputMatch expression:
1059 * There exists some pin such that bInputNeeded implies (pin is an input and
1060 * (bRender implies pin has render flag) and major/minor types members of
1062 * bOutputMatch is similar, but without the "bRender implies ..." part
1063 * and substituting variables names containing input for output
1066 /* determine whether filter meets requirements */
1067 if (SUCCEEDED(hrSub
) && (rf2
.dwMerit
>= dwMerit
))
1069 for (i
= 0; (i
< rf2
.u
.s1
.cPins2
) && (!bInputMatch
|| !bOutputMatch
); i
++)
1071 const REGFILTERPINS2
* rfp2
= rf2
.u
.s1
.rgPins2
+ i
;
1073 bInputMatch
= bInputMatch
|| (!(rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1074 (!bRender
|| (rfp2
->dwFlags
& REG_PINFLAG_B_RENDERER
)) &&
1075 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cInputTypes
, pInputTypes
));
1076 bOutputMatch
= bOutputMatch
|| ((rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1077 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cOutputTypes
, pOutputTypes
));
1080 if (bInputMatch
&& bOutputMatch
)
1082 struct MONIKER_MERIT mm
= {pMoniker
, rf2
.dwMerit
};
1083 IMoniker_AddRef(pMoniker
);
1084 add_data(&monikers
, (LPBYTE
)&mm
, sizeof(mm
));
1088 FM2_DeleteRegFilter(&rf2
);
1090 IPropertyBag_Release(pPropBag
);
1091 IMoniker_Release(pMoniker
);
1093 IEnumMoniker_Release(pEnum
);
1099 IPropertyBag_Release(pPropBagCat
);
1100 IMoniker_Release(pMonikerCat
);
1105 IMoniker
** ppMoniker
;
1107 ULONG nMonikerCount
= monikers
.current
/ sizeof(struct MONIKER_MERIT
);
1109 /* sort the monikers in descending merit order */
1110 qsort(monikers
.pData
, nMonikerCount
,
1111 sizeof(struct MONIKER_MERIT
),
1114 /* construct an IEnumMoniker interface */
1115 ppMoniker
= CoTaskMemAlloc(nMonikerCount
* sizeof(IMoniker
*));
1116 for (i
= 0; i
< nMonikerCount
; i
++)
1118 /* no need to AddRef here as already AddRef'd above */
1119 ppMoniker
[i
] = ((struct MONIKER_MERIT
*)monikers
.pData
)[i
].pMoniker
;
1121 hr
= EnumMonikerImpl_Create(ppMoniker
, nMonikerCount
, ppEnum
);
1122 CoTaskMemFree(ppMoniker
);
1125 delete_vector(&monikers
);
1126 IEnumMoniker_Release(pEnumCat
);
1127 ICreateDevEnum_Release(pCreateDevEnum
);
1132 static const IFilterMapper2Vtbl fm2vtbl
=
1135 FilterMapper2_QueryInterface
,
1136 FilterMapper2_AddRef
,
1137 FilterMapper2_Release
,
1139 FilterMapper2_CreateCategory
,
1140 FilterMapper2_UnregisterFilter
,
1141 FilterMapper2_RegisterFilter
,
1142 FilterMapper2_EnumMatchingFilters
1145 /*** IUnknown methods ***/
1147 static HRESULT WINAPI
FilterMapper_QueryInterface(IFilterMapper
* iface
, REFIID riid
, LPVOID
*ppv
)
1149 FilterMapper2Impl
*This
= impl_from_IFilterMapper(iface
);
1151 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1153 return FilterMapper2_QueryInterface((IFilterMapper2
*)&This
->lpVtbl
, riid
, ppv
);
1156 static ULONG WINAPI
FilterMapper_AddRef(IFilterMapper
* iface
)
1158 FilterMapper2Impl
*This
= impl_from_IFilterMapper(iface
);
1160 return FilterMapper2_AddRef((IFilterMapper2
*)This
);
1163 static ULONG WINAPI
FilterMapper_Release(IFilterMapper
* iface
)
1165 FilterMapper2Impl
*This
= impl_from_IFilterMapper(iface
);
1167 return FilterMapper2_Release((IFilterMapper2
*)This
);
1170 /*** IFilterMapper methods ***/
1172 static HRESULT WINAPI
FilterMapper_EnumMatchingFilters(
1173 IFilterMapper
* iface
,
1174 IEnumRegFilters
**ppEnum
,
1184 FilterMapper2Impl
*This
= impl_from_IFilterMapper(iface
);
1187 IEnumMoniker
* ppEnumMoniker
;
1190 ULONG idx
= 0, nb_mon
= 0;
1191 REGFILTER
* regfilters
;
1194 TRACE("(%p/%p)->(%p, %x, %s, %s, %s, %s, %s, %s, %s) stub!\n",
1198 bInputNeeded
? "true" : "false",
1199 debugstr_guid(&clsInMaj
),
1200 debugstr_guid(&clsInSub
),
1201 bRender
? "true" : "false",
1202 bOutputNeeded
? "true" : "false",
1203 debugstr_guid(&clsOutMaj
),
1204 debugstr_guid(&clsOutSub
));
1206 InputType
[0] = clsInMaj
;
1207 InputType
[1] = clsInSub
;
1208 OutputType
[0] = clsOutMaj
;
1209 OutputType
[1] = clsOutSub
;
1211 hr
= IFilterMapper2_EnumMatchingFilters((IFilterMapper2
*)This
,
1231 while(IEnumMoniker_Next(ppEnumMoniker
, 1, &IMon
, &nb
) == S_OK
)
1233 IMoniker_Release(IMon
);
1240 IEnumMoniker_Release(ppEnumMoniker
);
1241 return IEnumRegFiltersImpl_Construct(NULL
, 0, ppEnum
);
1244 regfilters
= CoTaskMemAlloc(nb_mon
* sizeof(REGFILTER
));
1247 IEnumMoniker_Release(ppEnumMoniker
);
1248 return E_OUTOFMEMORY
;
1251 IEnumMoniker_Reset(ppEnumMoniker
);
1252 while(IEnumMoniker_Next(ppEnumMoniker
, 1, &IMon
, &nb
) == S_OK
)
1254 IPropertyBag
* pPropBagCat
= NULL
;
1261 V_VT(&var
) = VT_BSTR
;
1263 hrSub
= IMoniker_BindToStorage(IMon
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
1265 if (SUCCEEDED(hrSub
))
1266 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
1268 if (SUCCEEDED(hrSub
))
1269 hrSub
= CLSIDFromString(V_UNION(&var
, bstrVal
), &clsid
);
1271 if (SUCCEEDED(hrSub
))
1272 hrSub
= IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &var
, NULL
);
1274 if (SUCCEEDED(hrSub
))
1276 len
= (strlenW((WCHAR
*)&V_UNION(&var
, bstrVal
))+1) * sizeof(WCHAR
);
1277 if (!(regfilters
[idx
].Name
= CoTaskMemAlloc(len
*2)))
1281 if (SUCCEEDED(hrSub
))
1283 memcpy(regfilters
[idx
].Name
, &V_UNION(&var
, bstrVal
), len
);
1284 regfilters
[idx
].Clsid
= clsid
;
1289 IPropertyBag_Release(pPropBagCat
);
1290 IMoniker_Release(IMon
);
1293 /* In case of release all resources */
1296 for (idx
= 0; idx
< nb_mon
; idx
++)
1297 CoTaskMemFree(regfilters
[idx
].Name
);
1298 CoTaskMemFree(regfilters
);
1299 IEnumMoniker_Release(ppEnumMoniker
);
1303 hr
= IEnumRegFiltersImpl_Construct(regfilters
, nb_mon
, ppEnum
);
1304 CoTaskMemFree(regfilters
);
1305 IEnumMoniker_Release(ppEnumMoniker
);
1311 static HRESULT WINAPI
FilterMapper_RegisterFilter(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, DWORD dwMerit
)
1314 LPWSTR wszClsid
= NULL
;
1317 WCHAR wszKeyName
[strlenW(wszFilterSlash
) + (CHARS_IN_GUID
-1) + 1];
1319 TRACE("(%p)->(%s, %s, %x)\n", iface
, debugstr_guid(&clsid
), debugstr_w(szName
), dwMerit
);
1321 hr
= StringFromCLSID(&clsid
, &wszClsid
);
1325 strcpyW(wszKeyName
, wszFilterSlash
);
1326 strcatW(wszKeyName
, wszClsid
);
1328 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
1329 hr
= HRESULT_FROM_WIN32(lRet
);
1334 lRet
= RegSetValueExW(hKey
, NULL
, 0, REG_SZ
, (const BYTE
*)szName
, strlenW(szName
) + 1);
1335 hr
= HRESULT_FROM_WIN32(lRet
);
1341 strcpyW(wszKeyName
, wszClsidSlash
);
1342 strcatW(wszKeyName
, wszClsid
);
1344 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
1345 hr
= HRESULT_FROM_WIN32(lRet
);
1350 lRet
= RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwMerit
, sizeof(dwMerit
));
1351 hr
= HRESULT_FROM_WIN32(lRet
);
1358 static HRESULT WINAPI
FilterMapper_RegisterFilterInstance(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, CLSID
*MRId
)
1360 TRACE("(%p)->(%s, %s, %p)\n", iface
, debugstr_guid(&clsid
), debugstr_w(szName
), MRId
);
1362 /* Not implemented in Windows (tested on Win2k) */
1367 static HRESULT WINAPI
FilterMapper_RegisterPin(
1368 IFilterMapper
* iface
,
1375 CLSID ConnectsToFilter
,
1376 LPCWSTR ConnectsToPin
)
1380 LPWSTR wszClsid
= NULL
;
1382 HKEY hPinsKey
= NULL
;
1383 WCHAR
* wszPinsKeyName
;
1384 WCHAR wszKeyName
[strlenW(wszClsidSlash
) + (CHARS_IN_GUID
-1) + 1];
1386 TRACE("(%p)->(%s, %s, %d, %d, %d, %d, %s, %s)\n", iface
, debugstr_guid(&Filter
), debugstr_w(szName
), bRendered
,
1387 bOutput
, bZero
, bMany
, debugstr_guid(&ConnectsToFilter
), debugstr_w(ConnectsToPin
));
1389 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1393 strcpyW(wszKeyName
, wszClsidSlash
);
1394 strcatW(wszKeyName
, wszClsid
);
1396 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1397 hr
= HRESULT_FROM_WIN32(lRet
);
1402 wszPinsKeyName
= CoTaskMemAlloc((strlenW(wszPins
) + 1 + strlenW(szName
) + 1) * 2);
1403 if (!wszPinsKeyName
)
1409 strcpyW(wszPinsKeyName
, wszPins
);
1410 strcatW(wszPinsKeyName
, wszSlash
);
1411 strcatW(wszPinsKeyName
, szName
);
1413 lRet
= RegCreateKeyExW(hKey
, wszPinsKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hPinsKey
, NULL
);
1414 hr
= HRESULT_FROM_WIN32(lRet
);
1415 CoTaskMemFree(wszPinsKeyName
);
1420 lRet
= RegSetValueExW(hPinsKey
, wszAllowedMany
, 0, REG_DWORD
, (LPBYTE
)&bMany
, sizeof(bMany
));
1421 hr
= HRESULT_FROM_WIN32(lRet
);
1426 lRet
= RegSetValueExW(hPinsKey
, wszAllowedZero
, 0, REG_DWORD
, (LPBYTE
)&bZero
, sizeof(bZero
));
1427 hr
= HRESULT_FROM_WIN32(lRet
);
1432 lRet
= RegSetValueExW(hPinsKey
, wszDirection
, 0, REG_DWORD
, (LPBYTE
)&bOutput
, sizeof(bOutput
));
1433 hr
= HRESULT_FROM_WIN32(lRet
);
1438 lRet
= RegSetValueExW(hPinsKey
, wszIsRendered
, 0, REG_DWORD
, (LPBYTE
)&bRendered
, sizeof(bRendered
));
1439 hr
= HRESULT_FROM_WIN32(lRet
);
1444 lRet
= RegCreateKeyExW(hPinsKey
, wszTypes
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, NULL
, NULL
);
1445 hr
= HRESULT_FROM_WIN32(lRet
);
1448 CoTaskMemFree(wszClsid
);
1452 CloseHandle(hPinsKey
);
1458 static HRESULT WINAPI
FilterMapper_RegisterPinType(
1459 IFilterMapper
* iface
,
1467 LPWSTR wszClsid
= NULL
;
1468 LPWSTR wszClsidMajorType
= NULL
;
1469 LPWSTR wszClsidSubType
= NULL
;
1471 WCHAR
* wszTypesKey
;
1472 WCHAR wszKeyName
[strlenW(wszClsidSlash
) + (CHARS_IN_GUID
-1) + 1];
1474 TRACE("(%p)->(%s, %s, %s, %s)\n", iface
, debugstr_guid(&clsFilter
), debugstr_w(szName
),
1475 debugstr_guid(&clsMajorType
), debugstr_guid(&clsSubType
));
1477 hr
= StringFromCLSID(&clsFilter
, &wszClsid
);
1481 hr
= StringFromCLSID(&clsMajorType
, &wszClsidMajorType
);
1486 hr
= StringFromCLSID(&clsSubType
, &wszClsidSubType
);
1491 wszTypesKey
= CoTaskMemAlloc((strlenW(wszClsidSlash
) + strlenW(wszClsid
) + strlenW(wszPins
) +
1492 strlenW(szName
) + strlenW(wszTypes
) + 3 + 1) * 2);
1499 strcpyW(wszTypesKey
, wszClsidSlash
);
1500 strcatW(wszTypesKey
, wszClsid
);
1501 strcatW(wszTypesKey
, wszSlash
);
1502 strcatW(wszTypesKey
, wszPins
);
1503 strcatW(wszTypesKey
, wszSlash
);
1504 strcatW(wszTypesKey
, szName
);
1505 strcatW(wszTypesKey
, wszSlash
);
1506 strcatW(wszTypesKey
, wszTypes
);
1508 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszTypesKey
, 0, KEY_WRITE
, &hKey
);
1509 hr
= HRESULT_FROM_WIN32(lRet
);
1510 CoTaskMemFree(wszTypesKey
);
1515 strcpyW(wszKeyName
, wszClsidMajorType
);
1516 strcatW(wszKeyName
, wszSlash
);
1517 strcatW(wszKeyName
, wszClsidSubType
);
1519 lRet
= RegCreateKeyExW(hKey
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, NULL
, NULL
);
1520 hr
= HRESULT_FROM_WIN32(lRet
);
1524 CoTaskMemFree(wszClsid
);
1525 CoTaskMemFree(wszClsidMajorType
);
1526 CoTaskMemFree(wszClsidSubType
);
1531 static HRESULT WINAPI
FilterMapper_UnregisterFilter(IFilterMapper
* iface
, CLSID Filter
)
1535 LPWSTR wszClsid
= NULL
;
1537 WCHAR wszKeyName
[strlenW(wszClsidSlash
) + (CHARS_IN_GUID
-1) + 1];
1539 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(&Filter
));
1541 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1545 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszFilter
, 0, KEY_WRITE
, &hKey
);
1546 hr
= HRESULT_FROM_WIN32(lRet
);
1551 lRet
= RegDeleteKeyW(hKey
, wszClsid
);
1552 hr
= HRESULT_FROM_WIN32(lRet
);
1558 strcpyW(wszKeyName
, wszClsidSlash
);
1559 strcatW(wszKeyName
, wszClsid
);
1561 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1562 hr
= HRESULT_FROM_WIN32(lRet
);
1567 lRet
= RegDeleteKeyW(hKey
, wszMeritName
);
1568 hr
= HRESULT_FROM_WIN32(lRet
);
1572 CoTaskMemFree(wszClsid
);
1577 static HRESULT WINAPI
FilterMapper_UnregisterFilterInstance(IFilterMapper
* iface
, CLSID MRId
)
1579 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(&MRId
));
1581 /* Not implemented in Windows (tested on Win2k) */
1586 static HRESULT WINAPI
FilterMapper_UnregisterPin(IFilterMapper
* iface
, CLSID Filter
, LPCWSTR Name
)
1590 LPWSTR wszClsid
= NULL
;
1592 WCHAR
* wszPinNameKey
;
1593 WCHAR wszKeyName
[strlenW(wszClsidSlash
) + (CHARS_IN_GUID
-1) + 1];
1595 TRACE("(%p)->(%s, %s)\n", iface
, debugstr_guid(&Filter
), debugstr_w(Name
));
1598 return E_INVALIDARG
;
1600 hr
= StringFromCLSID(&Filter
, &wszClsid
);
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 wszPinNameKey
= CoTaskMemAlloc((strlenW(wszPins
) + 1 + strlenW(Name
) + 1) * 2);
1620 strcpyW(wszPinNameKey
, wszPins
);
1621 strcatW(wszPinNameKey
, wszSlash
);
1622 strcatW(wszPinNameKey
, Name
);
1624 lRet
= RegDeleteKeyW(hKey
, wszPinNameKey
);
1625 hr
= HRESULT_FROM_WIN32(lRet
);
1626 CoTaskMemFree(wszPinNameKey
);
1629 CoTaskMemFree(wszClsid
);
1636 static const IFilterMapperVtbl fmvtbl
=
1639 FilterMapper_QueryInterface
,
1640 FilterMapper_AddRef
,
1641 FilterMapper_Release
,
1643 FilterMapper_RegisterFilter
,
1644 FilterMapper_RegisterFilterInstance
,
1645 FilterMapper_RegisterPin
,
1646 FilterMapper_RegisterPinType
,
1647 FilterMapper_UnregisterFilter
,
1648 FilterMapper_UnregisterFilterInstance
,
1649 FilterMapper_UnregisterPin
,
1650 FilterMapper_EnumMatchingFilters
1654 /*** IUnknown methods ***/
1655 static HRESULT WINAPI
AMFilterData_QueryInterface(IAMFilterData
* iface
, REFIID riid
, LPVOID
*ppv
)
1657 FilterMapper2Impl
*This
= impl_from_IAMFilterData(iface
);
1659 return FilterMapper2_QueryInterface((IFilterMapper2
*)This
, riid
, ppv
);
1662 static ULONG WINAPI
AMFilterData_AddRef(IAMFilterData
* iface
)
1664 FilterMapper2Impl
*This
= impl_from_IAMFilterData(iface
);
1666 return FilterMapper2_AddRef((IFilterMapper2
*)This
);
1669 static ULONG WINAPI
AMFilterData_Release(IAMFilterData
* iface
)
1671 FilterMapper2Impl
*This
= impl_from_IAMFilterData(iface
);
1673 return FilterMapper2_Release((IFilterMapper2
*)This
);
1676 /*** IAMFilterData methods ***/
1677 static HRESULT WINAPI
AMFilterData_ParseFilterData(IAMFilterData
* iface
,
1678 BYTE
*pData
, ULONG cb
,
1679 BYTE
**ppRegFilter2
)
1681 FilterMapper2Impl
*This
= impl_from_IAMFilterData(iface
);
1685 TRACE("(%p/%p)->(%p, %d, %p)\n", This
, iface
, pData
, cb
, ppRegFilter2
);
1687 prf2
= CoTaskMemAlloc(sizeof(*prf2
));
1689 return E_OUTOFMEMORY
;
1690 *ppRegFilter2
= (BYTE
*)&prf2
;
1692 hr
= FM2_ReadFilterData(pData
, prf2
);
1695 CoTaskMemFree(prf2
);
1696 *ppRegFilter2
= NULL
;
1702 static HRESULT WINAPI
AMFilterData_CreateFilterData(IAMFilterData
* iface
,
1704 BYTE
**pRegFilterData
,
1707 FilterMapper2Impl
*This
= impl_from_IAMFilterData(iface
);
1709 TRACE("(%p/%p)->(%p, %p, %p)\n", This
, iface
, prf2
, pRegFilterData
, pcb
);
1711 return FM2_WriteFilterData(prf2
, pRegFilterData
, pcb
);
1714 static const IAMFilterDataVtbl AMFilterDataVtbl
= {
1715 AMFilterData_QueryInterface
,
1716 AMFilterData_AddRef
,
1717 AMFilterData_Release
,
1718 AMFilterData_ParseFilterData
,
1719 AMFilterData_CreateFilterData