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/fil_data.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
46 typedef struct FilterMapper3Impl
48 IUnknown IUnknown_inner
;
49 IFilterMapper3 IFilterMapper3_iface
;
50 IFilterMapper IFilterMapper_iface
;
51 IAMFilterData IAMFilterData_iface
;
56 static inline FilterMapper3Impl
*impl_from_IFilterMapper3( IFilterMapper3
*iface
)
58 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IFilterMapper3_iface
);
61 static inline FilterMapper3Impl
*impl_from_IFilterMapper( IFilterMapper
*iface
)
63 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IFilterMapper_iface
);
66 static inline FilterMapper3Impl
*impl_from_IAMFilterData( IAMFilterData
*iface
)
68 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IAMFilterData_iface
);
71 static inline FilterMapper3Impl
*impl_from_IUnknown( IUnknown
*iface
)
73 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IUnknown_inner
);
76 static const WCHAR wszClsidSlash
[] = {'C','L','S','I','D','\\',0};
77 static const WCHAR wszSlashInstance
[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
78 static const WCHAR wszSlash
[] = {'\\',0};
80 /* CLSID property in media category Moniker */
81 static const WCHAR wszClsidName
[] = {'C','L','S','I','D',0};
82 /* FriendlyName property in media category Moniker */
83 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
84 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
85 static const WCHAR wszMeritName
[] = {'M','e','r','i','t',0};
86 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
87 static const WCHAR wszFilterDataName
[] = {'F','i','l','t','e','r','D','a','t','a',0};
88 /* For filters registered with IFilterMapper */
89 static const WCHAR wszFilterSlash
[] = {'F','i','l','t','e','r','\\',0};
90 static const WCHAR wszFilter
[] = {'F','i','l','t','e','r',0};
91 /* For pins registered with IFilterMapper */
92 static const WCHAR wszPins
[] = {'P','i','n','s',0};
93 static const WCHAR wszAllowedMany
[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
94 static const WCHAR wszAllowedZero
[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
95 static const WCHAR wszDirection
[] = {'D','i','r','e','c','t','i','o','n',0};
96 static const WCHAR wszIsRendered
[] = {'I','s','R','e','n','d','e','r','e','d',0};
97 /* For types registered with IFilterMapper */
98 static const WCHAR wszTypes
[] = {'T','y','p','e','s',0};
101 /* registry format for REGFILTER2 */
112 BYTE signature
[4]; /* e.g. "0pi3" */
117 DWORD bCategory
; /* is there a category clsid? */
118 /* optional: dwOffsetCategoryClsid */
123 BYTE signature
[4]; /* e.g. "0ty3" */
138 int capacity
; /* in bytes */
139 int current
; /* pointer to next free byte */
142 /* returns the position it was added at */
143 static int add_data(struct Vector
*v
, const void *pData
, int size
)
145 int index
= v
->current
;
146 if (v
->current
+ size
> v
->capacity
)
148 int new_capacity
= (v
->capacity
+ size
) * 2;
149 BYTE
*new_data
= CoTaskMemRealloc(v
->pData
, new_capacity
);
150 if (!new_data
) return -1;
151 v
->capacity
= new_capacity
;
154 memcpy(v
->pData
+ v
->current
, pData
, size
);
159 static int find_data(const struct Vector
*v
, const void *pData
, int size
)
162 for (index
= 0; index
< v
->current
; index
++)
163 if (!memcmp(v
->pData
+ index
, pData
, size
))
169 static void delete_vector(struct Vector
* v
)
171 CoTaskMemFree(v
->pData
);
176 /*** IUnknown (inner) methods ***/
178 static HRESULT WINAPI
Inner_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
180 FilterMapper3Impl
*This
= impl_from_IUnknown(iface
);
182 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
185 if (IsEqualIID(riid
, &IID_IUnknown
))
186 *ppv
= &This
->IUnknown_inner
;
187 else if (IsEqualIID(riid
, &IID_IFilterMapper2
) || IsEqualIID(riid
, &IID_IFilterMapper3
))
188 *ppv
= &This
->IFilterMapper3_iface
;
189 else if (IsEqualIID(riid
, &IID_IFilterMapper
))
190 *ppv
= &This
->IFilterMapper_iface
;
191 else if (IsEqualIID(riid
, &IID_IAMFilterData
))
192 *ppv
= &This
->IAMFilterData_iface
;
196 IUnknown_AddRef((IUnknown
*)*ppv
);
200 FIXME("No interface for %s\n", debugstr_guid(riid
));
201 return E_NOINTERFACE
;
204 static ULONG WINAPI
Inner_AddRef(IUnknown
*iface
)
206 FilterMapper3Impl
*This
= impl_from_IUnknown(iface
);
207 ULONG ref
= InterlockedIncrement(&This
->ref
);
209 TRACE("(%p)->(): new ref = %d\n", This
, ref
);
214 static ULONG WINAPI
Inner_Release(IUnknown
*iface
)
216 FilterMapper3Impl
*This
= impl_from_IUnknown(iface
);
217 ULONG ref
= InterlockedDecrement(&This
->ref
);
219 TRACE("(%p)->(): new ref = %d\n", This
, ref
);
227 static const IUnknownVtbl IInner_VTable
=
229 Inner_QueryInterface
,
234 static HRESULT WINAPI
FilterMapper3_QueryInterface(IFilterMapper3
* iface
, REFIID riid
, LPVOID
*ppv
)
236 FilterMapper3Impl
*This
= impl_from_IFilterMapper3(iface
);
238 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
241 static ULONG WINAPI
FilterMapper3_AddRef(IFilterMapper3
* iface
)
243 FilterMapper3Impl
*This
= impl_from_IFilterMapper3(iface
);
245 return IUnknown_AddRef(This
->outer_unk
);
248 static ULONG WINAPI
FilterMapper3_Release(IFilterMapper3
* iface
)
250 FilterMapper3Impl
*This
= impl_from_IFilterMapper3(iface
);
252 return IUnknown_Release(This
->outer_unk
);
255 /*** IFilterMapper3 methods ***/
257 static HRESULT WINAPI
FilterMapper3_CreateCategory(
258 IFilterMapper3
* iface
,
259 REFCLSID clsidCategory
,
260 DWORD dwCategoryMerit
,
261 LPCWSTR szDescription
)
263 LPWSTR wClsidAMCat
= NULL
;
264 LPWSTR wClsidCategory
= NULL
;
265 WCHAR wszKeyName
[ARRAY_SIZE(wszClsidSlash
)-1 + ARRAY_SIZE(wszSlashInstance
)-1 + (CHARS_IN_GUID
-1) * 2 + 1];
270 TRACE("(%s, %x, %s)\n", debugstr_guid(clsidCategory
), dwCategoryMerit
, debugstr_w(szDescription
));
272 hr
= StringFromCLSID(&CLSID_ActiveMovieCategories
, &wClsidAMCat
);
276 hr
= StringFromCLSID(clsidCategory
, &wClsidCategory
);
281 strcpyW(wszKeyName
, wszClsidSlash
);
282 strcatW(wszKeyName
, wClsidAMCat
);
283 strcatW(wszKeyName
, wszSlashInstance
);
284 strcatW(wszKeyName
, wClsidCategory
);
286 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
287 hr
= HRESULT_FROM_WIN32(lRet
);
292 lRet
= RegSetValueExW(hKey
, wszFriendlyName
, 0, REG_SZ
, (const BYTE
*)szDescription
, (strlenW(szDescription
) + 1) * sizeof(WCHAR
));
293 hr
= HRESULT_FROM_WIN32(lRet
);
298 lRet
= RegSetValueExW(hKey
, wszClsidName
, 0, REG_SZ
, (LPBYTE
)wClsidCategory
, (strlenW(wClsidCategory
) + 1) * sizeof(WCHAR
));
299 hr
= HRESULT_FROM_WIN32(lRet
);
304 lRet
= RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwCategoryMerit
, sizeof(dwCategoryMerit
));
305 hr
= HRESULT_FROM_WIN32(lRet
);
309 CoTaskMemFree(wClsidCategory
);
310 CoTaskMemFree(wClsidAMCat
);
315 static HRESULT WINAPI
FilterMapper3_UnregisterFilter(
316 IFilterMapper3
* iface
,
317 const CLSID
*pclsidCategory
,
318 const OLECHAR
*szInstance
,
321 WCHAR wszKeyName
[MAX_PATH
];
322 LPWSTR wClsidCategory
= NULL
;
323 LPWSTR wFilter
= NULL
;
326 TRACE("(%p, %s, %s)\n", pclsidCategory
, debugstr_w(szInstance
), debugstr_guid(Filter
));
329 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
331 hr
= StringFromCLSID(pclsidCategory
, &wClsidCategory
);
335 strcpyW(wszKeyName
, wszClsidSlash
);
336 strcatW(wszKeyName
, wClsidCategory
);
337 strcatW(wszKeyName
, wszSlashInstance
);
339 strcatW(wszKeyName
, szInstance
);
342 hr
= StringFromCLSID(Filter
, &wFilter
);
344 strcatW(wszKeyName
, wFilter
);
350 LONG lRet
= RegDeleteKeyW(HKEY_CLASSES_ROOT
, wszKeyName
);
351 hr
= HRESULT_FROM_WIN32(lRet
);
354 CoTaskMemFree(wClsidCategory
);
355 CoTaskMemFree(wFilter
);
360 static HRESULT
FM2_WriteFriendlyName(IPropertyBag
* pPropBag
, LPCWSTR szName
)
366 V_VT(&var
) = VT_BSTR
;
367 V_BSTR(&var
) = value
= SysAllocString(szName
);
369 ret
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
370 SysFreeString(value
);
375 static HRESULT
FM2_WriteClsid(IPropertyBag
* pPropBag
, REFCLSID clsid
)
377 LPWSTR wszClsid
= NULL
;
381 hr
= StringFromCLSID(clsid
, &wszClsid
);
385 V_VT(&var
) = VT_BSTR
;
386 V_BSTR(&var
) = wszClsid
;
387 hr
= IPropertyBag_Write(pPropBag
, wszClsidName
, &var
);
389 CoTaskMemFree(wszClsid
);
393 static HRESULT
FM2_WriteFilterData(const REGFILTER2
* prf2
, BYTE
**ppData
, ULONG
*pcbData
)
395 int size
= sizeof(struct REG_RF
);
397 struct Vector mainStore
= {NULL
, 0, 0};
398 struct Vector clsidStore
= {NULL
, 0, 0};
402 rrf
.dwVersion
= prf2
->dwVersion
;
403 rrf
.dwMerit
= prf2
->dwMerit
;
404 rrf
.dwPins
= prf2
->u
.s2
.cPins2
;
407 add_data(&mainStore
, &rrf
, sizeof(rrf
));
409 for (i
= 0; i
< prf2
->u
.s2
.cPins2
; i
++)
411 size
+= sizeof(struct REG_RFP
);
412 if (prf2
->u
.s2
.rgPins2
[i
].clsPinCategory
)
413 size
+= sizeof(DWORD
);
414 size
+= prf2
->u
.s2
.rgPins2
[i
].nMediaTypes
* sizeof(struct REG_TYPE
);
415 size
+= prf2
->u
.s2
.rgPins2
[i
].nMediums
* sizeof(DWORD
);
418 for (i
= 0; i
< prf2
->u
.s2
.cPins2
; i
++)
421 REGFILTERPINS2 rgPin2
= prf2
->u
.s2
.rgPins2
[i
];
424 rrfp
.signature
[0] = '0';
425 rrfp
.signature
[1] = 'p';
426 rrfp
.signature
[2] = 'i';
427 rrfp
.signature
[3] = '3';
428 rrfp
.signature
[0] += i
;
429 rrfp
.dwFlags
= rgPin2
.dwFlags
;
430 rrfp
.dwInstances
= rgPin2
.cInstances
;
431 rrfp
.dwMediaTypes
= rgPin2
.nMediaTypes
;
432 rrfp
.dwMediums
= rgPin2
.nMediums
;
433 rrfp
.bCategory
= rgPin2
.clsPinCategory
? 1 : 0;
435 add_data(&mainStore
, &rrfp
, sizeof(rrfp
));
438 DWORD index
= find_data(&clsidStore
, rgPin2
.clsPinCategory
, sizeof(CLSID
));
440 index
= add_data(&clsidStore
, rgPin2
.clsPinCategory
, sizeof(CLSID
));
443 add_data(&mainStore
, &index
, sizeof(index
));
446 for (j
= 0; j
< rgPin2
.nMediaTypes
; j
++)
449 const CLSID
* clsMinorType
= rgPin2
.lpMediaType
[j
].clsMinorType
? rgPin2
.lpMediaType
[j
].clsMinorType
: &MEDIASUBTYPE_NULL
;
450 rt
.signature
[0] = '0';
451 rt
.signature
[1] = 't';
452 rt
.signature
[2] = 'y';
453 rt
.signature
[3] = '3';
454 rt
.signature
[0] += j
;
456 rt
.dwOffsetMajor
= find_data(&clsidStore
, rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
457 if (rt
.dwOffsetMajor
== -1)
458 rt
.dwOffsetMajor
= add_data(&clsidStore
, rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
459 rt
.dwOffsetMajor
+= size
;
460 rt
.dwOffsetMinor
= find_data(&clsidStore
, clsMinorType
, sizeof(CLSID
));
461 if (rt
.dwOffsetMinor
== -1)
462 rt
.dwOffsetMinor
= add_data(&clsidStore
, clsMinorType
, sizeof(CLSID
));
463 rt
.dwOffsetMinor
+= size
;
465 add_data(&mainStore
, &rt
, sizeof(rt
));
468 for (j
= 0; j
< rgPin2
.nMediums
; j
++)
470 DWORD index
= find_data(&clsidStore
, rgPin2
.lpMedium
+ j
, sizeof(REGPINMEDIUM
));
472 index
= add_data(&clsidStore
, rgPin2
.lpMedium
+ j
, sizeof(REGPINMEDIUM
));
475 add_data(&mainStore
, &index
, sizeof(index
));
481 *pcbData
= mainStore
.current
+ clsidStore
.current
;
482 *ppData
= CoTaskMemAlloc(*pcbData
);
489 memcpy(*ppData
, mainStore
.pData
, mainStore
.current
);
490 memcpy((*ppData
) + mainStore
.current
, clsidStore
.pData
, clsidStore
.current
);
493 delete_vector(&mainStore
);
494 delete_vector(&clsidStore
);
498 static HRESULT
FM2_ReadFilterData(BYTE
*pData
, REGFILTER2
* prf2
)
501 struct REG_RF
* prrf
;
504 REGFILTERPINS2
* rgPins2
;
506 prrf
= (struct REG_RF
*)pData
;
509 if (prrf
->dwVersion
!= 2)
511 FIXME("Filter registry version %d not supported\n", prrf
->dwVersion
);
512 ZeroMemory(prf2
, sizeof(*prf2
));
518 TRACE("version = %d, merit = %x, #pins = %d, unused = %x\n",
519 prrf
->dwVersion
, prrf
->dwMerit
, prrf
->dwPins
, prrf
->dwUnused
);
521 prf2
->dwVersion
= prrf
->dwVersion
;
522 prf2
->dwMerit
= prrf
->dwMerit
;
523 prf2
->u
.s2
.cPins2
= prrf
->dwPins
;
524 rgPins2
= CoTaskMemAlloc(prrf
->dwPins
* sizeof(*rgPins2
));
525 prf2
->u
.s2
.rgPins2
= rgPins2
;
526 pCurrent
+= sizeof(struct REG_RF
);
528 for (i
= 0; i
< prrf
->dwPins
; i
++)
530 struct REG_RFP
* prrfp
= (struct REG_RFP
*)pCurrent
;
531 REGPINTYPES
* lpMediaType
;
532 REGPINMEDIUM
* lpMedium
;
535 /* FIXME: check signature */
537 TRACE("\tsignature = %s\n", debugstr_an((const char*)prrfp
->signature
, 4));
539 TRACE("\tpin[%d]: flags = %x, instances = %d, media types = %d, mediums = %d\n",
540 i
, prrfp
->dwFlags
, prrfp
->dwInstances
, prrfp
->dwMediaTypes
, prrfp
->dwMediums
);
542 rgPins2
[i
].dwFlags
= prrfp
->dwFlags
;
543 rgPins2
[i
].cInstances
= prrfp
->dwInstances
;
544 rgPins2
[i
].nMediaTypes
= prrfp
->dwMediaTypes
;
545 rgPins2
[i
].nMediums
= prrfp
->dwMediums
;
546 pCurrent
+= sizeof(struct REG_RFP
);
547 if (prrfp
->bCategory
)
549 CLSID
* clsCat
= CoTaskMemAlloc(sizeof(CLSID
));
550 memcpy(clsCat
, pData
+ *(DWORD
*)(pCurrent
), sizeof(CLSID
));
551 pCurrent
+= sizeof(DWORD
);
552 rgPins2
[i
].clsPinCategory
= clsCat
;
555 rgPins2
[i
].clsPinCategory
= NULL
;
557 if (rgPins2
[i
].nMediaTypes
> 0)
558 lpMediaType
= CoTaskMemAlloc(rgPins2
[i
].nMediaTypes
* sizeof(*lpMediaType
));
562 rgPins2
[i
].lpMediaType
= lpMediaType
;
564 for (j
= 0; j
< rgPins2
[i
].nMediaTypes
; j
++)
566 struct REG_TYPE
* prt
= (struct REG_TYPE
*)pCurrent
;
567 CLSID
* clsMajor
= CoTaskMemAlloc(sizeof(CLSID
));
568 CLSID
* clsMinor
= CoTaskMemAlloc(sizeof(CLSID
));
570 /* FIXME: check signature */
571 TRACE("\t\tsignature = %s\n", debugstr_an((const char*)prt
->signature
, 4));
573 memcpy(clsMajor
, pData
+ prt
->dwOffsetMajor
, sizeof(CLSID
));
574 memcpy(clsMinor
, pData
+ prt
->dwOffsetMinor
, sizeof(CLSID
));
576 lpMediaType
[j
].clsMajorType
= clsMajor
;
577 lpMediaType
[j
].clsMinorType
= clsMinor
;
579 pCurrent
+= sizeof(*prt
);
582 if (rgPins2
[i
].nMediums
> 0)
583 lpMedium
= CoTaskMemAlloc(rgPins2
[i
].nMediums
* sizeof(*lpMedium
));
587 rgPins2
[i
].lpMedium
= lpMedium
;
589 for (j
= 0; j
< rgPins2
[i
].nMediums
; j
++)
591 DWORD dwOffset
= *(DWORD
*)pCurrent
;
593 memcpy(lpMedium
+ j
, pData
+ dwOffset
, sizeof(REGPINMEDIUM
));
595 pCurrent
+= sizeof(dwOffset
);
604 static void FM2_DeleteRegFilter(REGFILTER2
* prf2
)
607 for (i
= 0; i
< prf2
->u
.s2
.cPins2
; i
++)
610 CoTaskMemFree((void*)prf2
->u
.s2
.rgPins2
[i
].clsPinCategory
);
612 for (j
= 0; j
< prf2
->u
.s2
.rgPins2
[i
].nMediaTypes
; j
++)
614 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
[j
].clsMajorType
);
615 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
[j
].clsMinorType
);
617 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
);
618 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMedium
);
620 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
);
623 static HRESULT WINAPI
FilterMapper3_RegisterFilter(
624 IFilterMapper3
* iface
,
625 REFCLSID clsidFilter
,
627 IMoniker
**ppMoniker
,
628 const CLSID
*pclsidCategory
,
629 const OLECHAR
*szInstance
,
630 const REGFILTER2
*prf2
)
632 IParseDisplayName
* pParser
= NULL
;
633 IBindCtx
* pBindCtx
= NULL
;
634 IMoniker
* pMoniker
= NULL
;
635 IPropertyBag
* pPropBag
= NULL
;
637 LPWSTR pwszParseName
= NULL
;
639 static const WCHAR wszDevice
[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
642 LPWSTR szClsidTemp
= NULL
;
643 REGFILTER2 regfilter2
;
644 REGFILTERPINS2
* pregfp2
= NULL
;
646 TRACE("(%s, %s, %p, %s, %s, %p)\n",
647 debugstr_guid(clsidFilter
),
650 debugstr_guid(pclsidCategory
),
651 debugstr_w(szInstance
),
654 if (prf2
->dwVersion
== 2)
658 else if (prf2
->dwVersion
== 1)
662 /* REGFILTER2 structure is converted from version 1 to 2. Tested on Win2k. */
663 regfilter2
.dwVersion
= 2;
664 regfilter2
.dwMerit
= prf2
->dwMerit
;
665 regfilter2
.u
.s2
.cPins2
= prf2
->u
.s1
.cPins
;
666 pregfp2
= CoTaskMemAlloc(prf2
->u
.s1
.cPins
* sizeof(REGFILTERPINS2
));
667 regfilter2
.u
.s2
.rgPins2
= pregfp2
;
668 for (i
= 0; i
< prf2
->u
.s1
.cPins
; i
++)
671 if (prf2
->u
.s1
.rgPins
[i
].bRendered
)
672 flags
|= REG_PINFLAG_B_RENDERER
;
673 if (prf2
->u
.s1
.rgPins
[i
].bOutput
)
674 flags
|= REG_PINFLAG_B_OUTPUT
;
675 if (prf2
->u
.s1
.rgPins
[i
].bZero
)
676 flags
|= REG_PINFLAG_B_ZERO
;
677 if (prf2
->u
.s1
.rgPins
[i
].bMany
)
678 flags
|= REG_PINFLAG_B_MANY
;
679 pregfp2
[i
].dwFlags
= flags
;
680 pregfp2
[i
].cInstances
= 1;
681 pregfp2
[i
].nMediaTypes
= prf2
->u
.s1
.rgPins
[i
].nMediaTypes
;
682 pregfp2
[i
].lpMediaType
= prf2
->u
.s1
.rgPins
[i
].lpMediaType
;
683 pregfp2
[i
].nMediums
= 0;
684 pregfp2
[i
].lpMedium
= NULL
;
685 pregfp2
[i
].clsPinCategory
= NULL
;
690 FIXME("dwVersion other that 1 or 2 not supported at the moment\n");
698 /* MSDN mentions the inexistent CLSID_ActiveMovieFilters GUID.
699 * In fact this is the CLSID_LegacyAmFilterCategory one */
700 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
702 /* sizeof... will include the null terminator and
703 * the + 1 is for the separator ('\\'). The -1 is
704 * because CHARS_IN_GUID includes the null terminator
706 nameLen
= ARRAY_SIZE(wszDevice
) + CHARS_IN_GUID
- 1 + 1;
709 nameLen
+= strlenW(szInstance
);
711 nameLen
+= CHARS_IN_GUID
- 1; /* CHARS_IN_GUID includes null terminator */
713 pCurrent
= pwszParseName
= CoTaskMemAlloc(nameLen
*sizeof(WCHAR
));
715 return E_OUTOFMEMORY
;
717 strcpyW(pwszParseName
, wszDevice
);
718 pCurrent
+= strlenW(wszDevice
);
720 hr
= StringFromCLSID(pclsidCategory
, &szClsidTemp
);
724 memcpy(pCurrent
, szClsidTemp
, CHARS_IN_GUID
* sizeof(WCHAR
));
725 pCurrent
+= CHARS_IN_GUID
- 1;
729 strcpyW(pCurrent
+1, szInstance
);
732 CoTaskMemFree(szClsidTemp
);
735 hr
= StringFromCLSID(clsidFilter
, &szClsidTemp
);
737 strcpyW(pCurrent
+1, szClsidTemp
);
742 hr
= CoCreateInstance(&CLSID_CDeviceMoniker
, NULL
, CLSCTX_INPROC
, &IID_IParseDisplayName
, (LPVOID
*)&pParser
);
745 hr
= CreateBindCtx(0, &pBindCtx
);
748 hr
= IParseDisplayName_ParseDisplayName(pParser
, pBindCtx
, pwszParseName
, &ulEaten
, &pMoniker
);
751 IBindCtx_Release(pBindCtx
);
753 IParseDisplayName_Release(pParser
);
756 hr
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
759 hr
= FM2_WriteFriendlyName(pPropBag
, szName
);
762 hr
= FM2_WriteClsid(pPropBag
, clsidFilter
);
769 hr
= FM2_WriteFilterData(®filter2
, &pData
, &cbData
);
774 SAFEARRAYBOUND saBound
;
777 saBound
.cElements
= cbData
;
778 psa
= SafeArrayCreate(VT_UI1
, 1, &saBound
);
781 ERR("Couldn't create SAFEARRAY\n");
788 hr
= SafeArrayAccessData(psa
, (LPVOID
*)&pbSAData
);
791 memcpy(pbSAData
, pData
, cbData
);
792 hr
= SafeArrayUnaccessData(psa
);
796 V_VT(&var
) = VT_ARRAY
| VT_UI1
;
800 hr
= IPropertyBag_Write(pPropBag
, wszFilterDataName
, &var
);
803 SafeArrayDestroy(psa
);
804 CoTaskMemFree(pData
);
809 IPropertyBag_Release(pPropBag
);
810 CoTaskMemFree(szClsidTemp
);
811 CoTaskMemFree(pwszParseName
);
813 if (SUCCEEDED(hr
) && ppMoniker
)
814 *ppMoniker
= pMoniker
;
816 IMoniker_Release(pMoniker
);
818 CoTaskMemFree(pregfp2
);
820 TRACE("-- returning %x\n", hr
);
825 /* internal helper function */
826 static BOOL
MatchTypes(
829 const REGPINTYPES
* pPinTypes
,
831 const GUID
* pMatchTypes
)
836 if ((nMatchTypes
== 0) && (nPinTypes
> 0))
839 for (j
= 0; j
< nPinTypes
; j
++)
842 for (i
= 0; i
< nMatchTypes
*2; i
+=2)
844 if (((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMajorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMajorType
, &pMatchTypes
[i
])) &&
845 ((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMinorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
+1], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMinorType
, &pMatchTypes
[i
+1])))
855 /* internal helper function for qsort of MONIKER_MERIT array */
856 static int mm_compare(const void * left
, const void * right
)
858 const struct MONIKER_MERIT
* mmLeft
= left
;
859 const struct MONIKER_MERIT
* mmRight
= right
;
861 if (mmLeft
->dwMerit
== mmRight
->dwMerit
)
863 if (mmLeft
->dwMerit
> mmRight
->dwMerit
)
869 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
870 * (GUID_NULL's in input to function automatically treated as wild cards)
871 * Input/Output needed means match only on criteria if TRUE (with zero input types
872 * meaning match any input/output pin as long as one exists), otherwise match any
873 * filter that meets the rest of the requirements.
875 static HRESULT WINAPI
FilterMapper3_EnumMatchingFilters(
876 IFilterMapper3
* iface
,
877 IEnumMoniker
**ppEnum
,
883 const GUID
*pInputTypes
,
884 const REGPINMEDIUM
*pMedIn
,
885 const CLSID
*pPinCategoryIn
,
889 const GUID
*pOutputTypes
,
890 const REGPINMEDIUM
*pMedOut
,
891 const CLSID
*pPinCategoryOut
)
893 ICreateDevEnum
* pCreateDevEnum
;
894 IMoniker
* pMonikerCat
;
895 IEnumMoniker
* pEnumCat
;
897 struct Vector monikers
= {NULL
, 0, 0};
899 TRACE("(%p, %x, %s, %x, %s, %d, %p, %p, %p, %s, %s, %p, %p, %p)\n",
902 bExactMatch
? "true" : "false",
904 bInputNeeded
? "true" : "false",
909 bRender
? "true" : "false",
910 bOutputNeeded
? "true" : "false",
917 FIXME("dwFlags = %x not implemented\n", dwFlags
);
922 hr
= CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (LPVOID
*)&pCreateDevEnum
);
926 hr
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &CLSID_ActiveMovieCategories
, &pEnumCat
, 0);
928 ICreateDevEnum_Release(pCreateDevEnum
);
932 while (IEnumMoniker_Next(pEnumCat
, 1, &pMonikerCat
, NULL
) == S_OK
)
934 IPropertyBag
* pPropBagCat
= NULL
;
936 HRESULT hrSub
; /* this is so that one buggy filter
937 doesn't make the whole lot fail */
941 hrSub
= IMoniker_BindToStorage(pMonikerCat
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
943 if (SUCCEEDED(hrSub
))
944 hrSub
= IPropertyBag_Read(pPropBagCat
, wszMeritName
, &var
, NULL
);
946 if (SUCCEEDED(hrSub
) && (V_UI4(&var
) >= dwMerit
))
949 IEnumMoniker
* pEnum
;
954 if (TRACE_ON(quartz
))
957 V_VT(&temp
) = VT_EMPTY
;
958 IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &temp
, NULL
);
959 TRACE("Considering category %s\n", debugstr_w(V_BSTR(&temp
)));
963 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
965 if (SUCCEEDED(hrSub
))
966 hrSub
= CLSIDFromString(V_BSTR(&var
), &clsidCat
);
968 if (SUCCEEDED(hrSub
))
969 hrSub
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &clsidCat
, &pEnum
, 0);
973 while (IEnumMoniker_Next(pEnum
, 1, &pMoniker
, NULL
) == S_OK
)
975 IPropertyBag
* pPropBag
= NULL
;
980 BOOL bInputMatch
= !bInputNeeded
;
981 BOOL bOutputMatch
= !bOutputNeeded
;
983 ZeroMemory(&rf2
, sizeof(rf2
));
986 hrSub
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBag
);
988 if (TRACE_ON(quartz
))
991 V_VT(&temp
) = VT_EMPTY
;
992 IPropertyBag_Read(pPropBag
, wszFriendlyName
, &temp
, NULL
);
993 TRACE("Considering filter %s\n", debugstr_w(V_BSTR(&temp
)));
997 if (SUCCEEDED(hrSub
))
999 hrSub
= IPropertyBag_Read(pPropBag
, wszFilterDataName
, &var
, NULL
);
1002 if (SUCCEEDED(hrSub
))
1003 hrSub
= SafeArrayAccessData(V_ARRAY(&var
), (LPVOID
*)&pData
);
1005 if (SUCCEEDED(hrSub
))
1006 hrSub
= FM2_ReadFilterData(pData
, &rf2
);
1009 SafeArrayUnaccessData(V_ARRAY(&var
));
1013 /* Logic used for bInputMatch expression:
1014 * There exists some pin such that bInputNeeded implies (pin is an input and
1015 * (bRender implies pin has render flag) and major/minor types members of
1017 * bOutputMatch is similar, but without the "bRender implies ..." part
1018 * and substituting variables names containing input for output
1021 /* determine whether filter meets requirements */
1022 if (SUCCEEDED(hrSub
) && (rf2
.dwMerit
>= dwMerit
))
1024 for (i
= 0; (i
< rf2
.u
.s2
.cPins2
) && (!bInputMatch
|| !bOutputMatch
); i
++)
1026 const REGFILTERPINS2
* rfp2
= rf2
.u
.s2
.rgPins2
+ i
;
1028 bInputMatch
= bInputMatch
|| (!(rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1029 (!bRender
|| (rfp2
->dwFlags
& REG_PINFLAG_B_RENDERER
)) &&
1030 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cInputTypes
, pInputTypes
));
1031 bOutputMatch
= bOutputMatch
|| ((rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1032 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cOutputTypes
, pOutputTypes
));
1035 if (bInputMatch
&& bOutputMatch
)
1037 struct MONIKER_MERIT mm
= {pMoniker
, rf2
.dwMerit
};
1038 IMoniker_AddRef(pMoniker
);
1039 add_data(&monikers
, &mm
, sizeof(mm
));
1043 FM2_DeleteRegFilter(&rf2
);
1045 IPropertyBag_Release(pPropBag
);
1046 IMoniker_Release(pMoniker
);
1048 IEnumMoniker_Release(pEnum
);
1054 IPropertyBag_Release(pPropBagCat
);
1055 IMoniker_Release(pMonikerCat
);
1060 IMoniker
** ppMoniker
;
1062 ULONG nMonikerCount
= monikers
.current
/ sizeof(struct MONIKER_MERIT
);
1064 /* sort the monikers in descending merit order */
1065 qsort(monikers
.pData
, nMonikerCount
,
1066 sizeof(struct MONIKER_MERIT
),
1069 /* construct an IEnumMoniker interface */
1070 ppMoniker
= CoTaskMemAlloc(nMonikerCount
* sizeof(IMoniker
*));
1071 for (i
= 0; i
< nMonikerCount
; i
++)
1073 /* no need to AddRef here as already AddRef'd above */
1074 ppMoniker
[i
] = ((struct MONIKER_MERIT
*)monikers
.pData
)[i
].pMoniker
;
1076 hr
= EnumMonikerImpl_Create(ppMoniker
, nMonikerCount
, ppEnum
);
1077 CoTaskMemFree(ppMoniker
);
1080 delete_vector(&monikers
);
1081 IEnumMoniker_Release(pEnumCat
);
1082 ICreateDevEnum_Release(pCreateDevEnum
);
1087 static HRESULT WINAPI
FilterMapper3_GetICreateDevEnum(IFilterMapper3
*iface
, ICreateDevEnum
**ppEnum
)
1089 TRACE("(%p, %p)\n", iface
, ppEnum
);
1092 return CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (void**)ppEnum
);
1095 static const IFilterMapper3Vtbl fm3vtbl
=
1098 FilterMapper3_QueryInterface
,
1099 FilterMapper3_AddRef
,
1100 FilterMapper3_Release
,
1102 FilterMapper3_CreateCategory
,
1103 FilterMapper3_UnregisterFilter
,
1104 FilterMapper3_RegisterFilter
,
1105 FilterMapper3_EnumMatchingFilters
,
1106 FilterMapper3_GetICreateDevEnum
1109 /*** IUnknown methods ***/
1111 static HRESULT WINAPI
FilterMapper_QueryInterface(IFilterMapper
* iface
, REFIID riid
, LPVOID
*ppv
)
1113 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1115 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1117 return FilterMapper3_QueryInterface(&This
->IFilterMapper3_iface
, riid
, ppv
);
1120 static ULONG WINAPI
FilterMapper_AddRef(IFilterMapper
* iface
)
1122 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1124 return IUnknown_AddRef(This
->outer_unk
);
1127 static ULONG WINAPI
FilterMapper_Release(IFilterMapper
* iface
)
1129 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1131 return IUnknown_Release(This
->outer_unk
);
1134 /*** IFilterMapper methods ***/
1136 static HRESULT WINAPI
FilterMapper_EnumMatchingFilters(
1137 IFilterMapper
* iface
,
1138 IEnumRegFilters
**ppEnum
,
1148 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1151 IEnumMoniker
* ppEnumMoniker
;
1154 ULONG idx
= 0, nb_mon
= 0;
1155 REGFILTER
* regfilters
;
1158 TRACE("(%p/%p)->(%p, %x, %s, %s, %s, %s, %s, %s, %s)\n",
1163 bInputNeeded
? "true" : "false",
1164 debugstr_guid(&clsInMaj
),
1165 debugstr_guid(&clsInSub
),
1166 bRender
? "true" : "false",
1167 bOutputNeeded
? "true" : "false",
1168 debugstr_guid(&clsOutMaj
),
1169 debugstr_guid(&clsOutSub
));
1171 InputType
[0] = clsInMaj
;
1172 InputType
[1] = clsInSub
;
1173 OutputType
[0] = clsOutMaj
;
1174 OutputType
[1] = clsOutSub
;
1178 hr
= IFilterMapper3_EnumMatchingFilters(&This
->IFilterMapper3_iface
, &ppEnumMoniker
, 0, TRUE
,
1179 dwMerit
, bInputNeeded
, 1, InputType
, NULL
, &GUID_NULL
, bRender
, bOutputNeeded
, 1,
1180 OutputType
, NULL
, &GUID_NULL
);
1185 while(IEnumMoniker_Next(ppEnumMoniker
, 1, &IMon
, &nb
) == S_OK
)
1187 IMoniker_Release(IMon
);
1193 IEnumMoniker_Release(ppEnumMoniker
);
1194 return IEnumRegFiltersImpl_Construct(NULL
, 0, ppEnum
);
1197 regfilters
= CoTaskMemAlloc(nb_mon
* sizeof(REGFILTER
));
1200 IEnumMoniker_Release(ppEnumMoniker
);
1201 return E_OUTOFMEMORY
;
1203 ZeroMemory(regfilters
, nb_mon
* sizeof(REGFILTER
)); /* will prevent bad free of Name in case of error. */
1205 IEnumMoniker_Reset(ppEnumMoniker
);
1206 while(IEnumMoniker_Next(ppEnumMoniker
, 1, &IMon
, &nb
) == S_OK
)
1208 IPropertyBag
* pPropBagCat
= NULL
;
1216 hrSub
= IMoniker_BindToStorage(IMon
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
1218 if (SUCCEEDED(hrSub
))
1219 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
1221 if (SUCCEEDED(hrSub
))
1222 hrSub
= CLSIDFromString(V_BSTR(&var
), &clsid
);
1226 if (SUCCEEDED(hrSub
))
1227 hrSub
= IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &var
, NULL
);
1229 if (SUCCEEDED(hrSub
))
1231 len
= (strlenW(V_BSTR(&var
))+1) * sizeof(WCHAR
);
1232 if (!(regfilters
[idx
].Name
= CoTaskMemAlloc(len
*2)))
1236 if (SUCCEEDED(hrSub
) && regfilters
[idx
].Name
)
1238 memcpy(regfilters
[idx
].Name
, V_BSTR(&var
), len
);
1239 regfilters
[idx
].Clsid
= clsid
;
1244 IPropertyBag_Release(pPropBagCat
);
1245 IMoniker_Release(IMon
);
1251 hr
= IEnumRegFiltersImpl_Construct(regfilters
, nb_mon
, ppEnum
);
1254 for (idx
= 0; idx
< nb_mon
; idx
++)
1255 CoTaskMemFree(regfilters
[idx
].Name
);
1256 CoTaskMemFree(regfilters
);
1257 IEnumMoniker_Release(ppEnumMoniker
);
1263 static HRESULT WINAPI
FilterMapper_RegisterFilter(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, DWORD dwMerit
)
1266 LPWSTR wszClsid
= NULL
;
1269 WCHAR wszKeyName
[ARRAY_SIZE(wszFilterSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1271 TRACE("(%p)->(%s, %s, %x)\n", iface
, debugstr_guid(&clsid
), debugstr_w(szName
), dwMerit
);
1273 hr
= StringFromCLSID(&clsid
, &wszClsid
);
1277 strcpyW(wszKeyName
, wszFilterSlash
);
1278 strcatW(wszKeyName
, wszClsid
);
1280 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
1281 hr
= HRESULT_FROM_WIN32(lRet
);
1286 lRet
= RegSetValueExW(hKey
, NULL
, 0, REG_SZ
, (const BYTE
*)szName
, (strlenW(szName
) + 1) * sizeof(WCHAR
));
1287 hr
= HRESULT_FROM_WIN32(lRet
);
1293 strcpyW(wszKeyName
, wszClsidSlash
);
1294 strcatW(wszKeyName
, wszClsid
);
1296 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
1297 hr
= HRESULT_FROM_WIN32(lRet
);
1302 lRet
= RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwMerit
, sizeof(dwMerit
));
1303 hr
= HRESULT_FROM_WIN32(lRet
);
1307 CoTaskMemFree(wszClsid
);
1312 static HRESULT WINAPI
FilterMapper_RegisterFilterInstance(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, CLSID
*MRId
)
1314 TRACE("(%p)->(%s, %s, %p)\n", iface
, debugstr_guid(&clsid
), debugstr_w(szName
), MRId
);
1316 /* Not implemented in Windows (tested on Win2k) */
1321 static HRESULT WINAPI
FilterMapper_RegisterPin(
1322 IFilterMapper
* iface
,
1329 CLSID ConnectsToFilter
,
1330 LPCWSTR ConnectsToPin
)
1334 LPWSTR wszClsid
= NULL
;
1336 HKEY hPinsKey
= NULL
;
1337 WCHAR
* wszPinsKeyName
;
1338 WCHAR wszKeyName
[ARRAY_SIZE(wszClsidSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1340 TRACE("(%p)->(%s, %s, %d, %d, %d, %d, %s, %s)\n", iface
, debugstr_guid(&Filter
), debugstr_w(szName
), bRendered
,
1341 bOutput
, bZero
, bMany
, debugstr_guid(&ConnectsToFilter
), debugstr_w(ConnectsToPin
));
1343 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1347 strcpyW(wszKeyName
, wszClsidSlash
);
1348 strcatW(wszKeyName
, wszClsid
);
1350 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1351 hr
= HRESULT_FROM_WIN32(lRet
);
1356 wszPinsKeyName
= CoTaskMemAlloc((strlenW(wszPins
) + 1 + strlenW(szName
) + 1) * 2);
1357 if (!wszPinsKeyName
)
1363 strcpyW(wszPinsKeyName
, wszPins
);
1364 strcatW(wszPinsKeyName
, wszSlash
);
1365 strcatW(wszPinsKeyName
, szName
);
1367 lRet
= RegCreateKeyExW(hKey
, wszPinsKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hPinsKey
, NULL
);
1368 hr
= HRESULT_FROM_WIN32(lRet
);
1369 CoTaskMemFree(wszPinsKeyName
);
1374 lRet
= RegSetValueExW(hPinsKey
, wszAllowedMany
, 0, REG_DWORD
, (LPBYTE
)&bMany
, sizeof(bMany
));
1375 hr
= HRESULT_FROM_WIN32(lRet
);
1380 lRet
= RegSetValueExW(hPinsKey
, wszAllowedZero
, 0, REG_DWORD
, (LPBYTE
)&bZero
, sizeof(bZero
));
1381 hr
= HRESULT_FROM_WIN32(lRet
);
1386 lRet
= RegSetValueExW(hPinsKey
, wszDirection
, 0, REG_DWORD
, (LPBYTE
)&bOutput
, sizeof(bOutput
));
1387 hr
= HRESULT_FROM_WIN32(lRet
);
1392 lRet
= RegSetValueExW(hPinsKey
, wszIsRendered
, 0, REG_DWORD
, (LPBYTE
)&bRendered
, sizeof(bRendered
));
1393 hr
= HRESULT_FROM_WIN32(lRet
);
1398 HKEY hkeyDummy
= NULL
;
1400 lRet
= RegCreateKeyExW(hPinsKey
, wszTypes
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkeyDummy
, NULL
);
1401 hr
= HRESULT_FROM_WIN32(lRet
);
1403 if (hkeyDummy
) RegCloseKey(hkeyDummy
);
1406 CoTaskMemFree(wszClsid
);
1410 RegCloseKey(hPinsKey
);
1416 static HRESULT WINAPI
FilterMapper_RegisterPinType(
1417 IFilterMapper
* iface
,
1425 LPWSTR wszClsid
= NULL
;
1426 LPWSTR wszClsidMajorType
= NULL
;
1427 LPWSTR wszClsidSubType
= NULL
;
1429 WCHAR
* wszTypesKey
;
1430 WCHAR wszKeyName
[MAX_PATH
];
1432 TRACE("(%p)->(%s, %s, %s, %s)\n", iface
, debugstr_guid(&clsFilter
), debugstr_w(szName
),
1433 debugstr_guid(&clsMajorType
), debugstr_guid(&clsSubType
));
1435 hr
= StringFromCLSID(&clsFilter
, &wszClsid
);
1439 hr
= StringFromCLSID(&clsMajorType
, &wszClsidMajorType
);
1444 hr
= StringFromCLSID(&clsSubType
, &wszClsidSubType
);
1449 wszTypesKey
= CoTaskMemAlloc((strlenW(wszClsidSlash
) + strlenW(wszClsid
) + strlenW(wszPins
) +
1450 strlenW(szName
) + strlenW(wszTypes
) + 3 + 1) * 2);
1457 strcpyW(wszTypesKey
, wszClsidSlash
);
1458 strcatW(wszTypesKey
, wszClsid
);
1459 strcatW(wszTypesKey
, wszSlash
);
1460 strcatW(wszTypesKey
, wszPins
);
1461 strcatW(wszTypesKey
, wszSlash
);
1462 strcatW(wszTypesKey
, szName
);
1463 strcatW(wszTypesKey
, wszSlash
);
1464 strcatW(wszTypesKey
, wszTypes
);
1466 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszTypesKey
, 0, KEY_WRITE
, &hKey
);
1467 hr
= HRESULT_FROM_WIN32(lRet
);
1468 CoTaskMemFree(wszTypesKey
);
1473 HKEY hkeyDummy
= NULL
;
1475 strcpyW(wszKeyName
, wszClsidMajorType
);
1476 strcatW(wszKeyName
, wszSlash
);
1477 strcatW(wszKeyName
, wszClsidSubType
);
1479 lRet
= RegCreateKeyExW(hKey
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkeyDummy
, NULL
);
1480 hr
= HRESULT_FROM_WIN32(lRet
);
1483 if (hkeyDummy
) RegCloseKey(hkeyDummy
);
1486 CoTaskMemFree(wszClsid
);
1487 CoTaskMemFree(wszClsidMajorType
);
1488 CoTaskMemFree(wszClsidSubType
);
1493 static HRESULT WINAPI
FilterMapper_UnregisterFilter(IFilterMapper
* iface
, CLSID Filter
)
1497 LPWSTR wszClsid
= NULL
;
1499 WCHAR wszKeyName
[ARRAY_SIZE(wszClsidSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1501 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(&Filter
));
1503 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1507 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszFilter
, 0, KEY_WRITE
, &hKey
);
1508 hr
= HRESULT_FROM_WIN32(lRet
);
1513 lRet
= RegDeleteKeyW(hKey
, wszClsid
);
1514 hr
= HRESULT_FROM_WIN32(lRet
);
1520 strcpyW(wszKeyName
, wszClsidSlash
);
1521 strcatW(wszKeyName
, wszClsid
);
1523 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1524 if (lRet
== ERROR_FILE_NOT_FOUND
)
1526 hr
= HRESULT_FROM_WIN32(lRet
);
1531 lRet
= RegDeleteValueW(hKey
, wszMeritName
);
1532 if (lRet
!= ERROR_SUCCESS
&& lRet
!= ERROR_FILE_NOT_FOUND
)
1533 hr
= HRESULT_FROM_WIN32(lRet
);
1535 lRet
= RegDeleteTreeW(hKey
, wszPins
);
1536 if (lRet
!= ERROR_SUCCESS
&& lRet
!= ERROR_FILE_NOT_FOUND
)
1537 hr
= HRESULT_FROM_WIN32(lRet
);
1543 CoTaskMemFree(wszClsid
);
1548 static HRESULT WINAPI
FilterMapper_UnregisterFilterInstance(IFilterMapper
* iface
, CLSID MRId
)
1550 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(&MRId
));
1552 /* Not implemented in Windows (tested on Win2k) */
1557 static HRESULT WINAPI
FilterMapper_UnregisterPin(IFilterMapper
* iface
, CLSID Filter
, LPCWSTR Name
)
1561 LPWSTR wszClsid
= NULL
;
1563 WCHAR
* wszPinNameKey
;
1564 WCHAR wszKeyName
[ARRAY_SIZE(wszClsidSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1566 TRACE("(%p)->(%s, %s)\n", iface
, debugstr_guid(&Filter
), debugstr_w(Name
));
1569 return E_INVALIDARG
;
1571 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1575 strcpyW(wszKeyName
, wszClsidSlash
);
1576 strcatW(wszKeyName
, wszClsid
);
1578 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1579 hr
= HRESULT_FROM_WIN32(lRet
);
1584 wszPinNameKey
= CoTaskMemAlloc((strlenW(wszPins
) + 1 + strlenW(Name
) + 1) * 2);
1591 strcpyW(wszPinNameKey
, wszPins
);
1592 strcatW(wszPinNameKey
, wszSlash
);
1593 strcatW(wszPinNameKey
, Name
);
1595 lRet
= RegDeleteTreeW(hKey
, wszPinNameKey
);
1596 hr
= HRESULT_FROM_WIN32(lRet
);
1597 CoTaskMemFree(wszPinNameKey
);
1600 CoTaskMemFree(wszClsid
);
1607 static const IFilterMapperVtbl fmvtbl
=
1610 FilterMapper_QueryInterface
,
1611 FilterMapper_AddRef
,
1612 FilterMapper_Release
,
1614 FilterMapper_RegisterFilter
,
1615 FilterMapper_RegisterFilterInstance
,
1616 FilterMapper_RegisterPin
,
1617 FilterMapper_RegisterPinType
,
1618 FilterMapper_UnregisterFilter
,
1619 FilterMapper_UnregisterFilterInstance
,
1620 FilterMapper_UnregisterPin
,
1621 FilterMapper_EnumMatchingFilters
1625 /*** IUnknown methods ***/
1626 static HRESULT WINAPI
AMFilterData_QueryInterface(IAMFilterData
* iface
, REFIID riid
, LPVOID
*ppv
)
1628 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1630 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
1633 static ULONG WINAPI
AMFilterData_AddRef(IAMFilterData
* iface
)
1635 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1637 return IUnknown_AddRef(This
->outer_unk
);
1640 static ULONG WINAPI
AMFilterData_Release(IAMFilterData
* iface
)
1642 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1644 return IUnknown_Release(This
->outer_unk
);
1647 /*** IAMFilterData methods ***/
1648 static HRESULT WINAPI
AMFilterData_ParseFilterData(IAMFilterData
* iface
,
1649 BYTE
*pData
, ULONG cb
,
1650 BYTE
**ppRegFilter2
)
1652 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1654 static REGFILTER2
*prf2
;
1656 TRACE("(%p/%p)->(%p, %d, %p)\n", This
, iface
, pData
, cb
, ppRegFilter2
);
1658 prf2
= CoTaskMemAlloc(sizeof(*prf2
));
1660 return E_OUTOFMEMORY
;
1661 *ppRegFilter2
= (BYTE
*)&prf2
;
1663 hr
= FM2_ReadFilterData(pData
, prf2
);
1666 CoTaskMemFree(prf2
);
1667 *ppRegFilter2
= NULL
;
1673 static HRESULT WINAPI
AMFilterData_CreateFilterData(IAMFilterData
* iface
,
1675 BYTE
**pRegFilterData
,
1678 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1680 TRACE("(%p/%p)->(%p, %p, %p)\n", This
, iface
, prf2
, pRegFilterData
, pcb
);
1682 return FM2_WriteFilterData(prf2
, pRegFilterData
, pcb
);
1685 static const IAMFilterDataVtbl AMFilterDataVtbl
= {
1686 AMFilterData_QueryInterface
,
1687 AMFilterData_AddRef
,
1688 AMFilterData_Release
,
1689 AMFilterData_ParseFilterData
,
1690 AMFilterData_CreateFilterData
1693 HRESULT
FilterMapper2_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
1695 FilterMapper3Impl
* pFM2impl
;
1697 TRACE("(%p, %p)\n", pUnkOuter
, ppObj
);
1699 pFM2impl
= CoTaskMemAlloc(sizeof(*pFM2impl
));
1701 return E_OUTOFMEMORY
;
1703 pFM2impl
->IUnknown_inner
.lpVtbl
= &IInner_VTable
;
1704 pFM2impl
->IFilterMapper3_iface
.lpVtbl
= &fm3vtbl
;
1705 pFM2impl
->IFilterMapper_iface
.lpVtbl
= &fmvtbl
;
1706 pFM2impl
->IAMFilterData_iface
.lpVtbl
= &AMFilterDataVtbl
;
1710 pFM2impl
->outer_unk
= pUnkOuter
;
1712 pFM2impl
->outer_unk
= &pFM2impl
->IUnknown_inner
;
1714 *ppObj
= &pFM2impl
->IUnknown_inner
;
1716 TRACE("-- created at %p\n", pFM2impl
);
1721 HRESULT
FilterMapper_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
1723 FilterMapper3Impl
*pFM2impl
;
1726 TRACE("(%p, %p)\n", pUnkOuter
, ppObj
);
1728 hr
= FilterMapper2_create(pUnkOuter
, (LPVOID
*)&pFM2impl
);
1732 *ppObj
= &pFM2impl
->IFilterMapper_iface
;