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 IUnknown IUnknown_inner
;
51 IFilterMapper3 IFilterMapper3_iface
;
52 IFilterMapper IFilterMapper_iface
;
53 IAMFilterData IAMFilterData_iface
;
58 static inline FilterMapper3Impl
*impl_from_IFilterMapper3( IFilterMapper3
*iface
)
60 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IFilterMapper3_iface
);
63 static inline FilterMapper3Impl
*impl_from_IFilterMapper( IFilterMapper
*iface
)
65 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IFilterMapper_iface
);
68 static inline FilterMapper3Impl
*impl_from_IAMFilterData( IAMFilterData
*iface
)
70 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IAMFilterData_iface
);
73 static inline FilterMapper3Impl
*impl_from_IUnknown( IUnknown
*iface
)
75 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IUnknown_inner
);
78 static const WCHAR wszClsidSlash
[] = {'C','L','S','I','D','\\',0};
79 static const WCHAR wszSlashInstance
[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
80 static const WCHAR wszSlash
[] = {'\\',0};
82 /* CLSID property in media category Moniker */
83 static const WCHAR wszClsidName
[] = {'C','L','S','I','D',0};
84 /* FriendlyName property in media category Moniker */
85 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
86 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
87 static const WCHAR wszMeritName
[] = {'M','e','r','i','t',0};
88 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
89 static const WCHAR wszFilterDataName
[] = {'F','i','l','t','e','r','D','a','t','a',0};
90 /* For filters registered with IFilterMapper */
91 static const WCHAR wszFilterSlash
[] = {'F','i','l','t','e','r','\\',0};
92 static const WCHAR wszFilter
[] = {'F','i','l','t','e','r',0};
93 /* For pins registered with IFilterMapper */
94 static const WCHAR wszPins
[] = {'P','i','n','s',0};
95 static const WCHAR wszAllowedMany
[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
96 static const WCHAR wszAllowedZero
[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
97 static const WCHAR wszDirection
[] = {'D','i','r','e','c','t','i','o','n',0};
98 static const WCHAR wszIsRendered
[] = {'I','s','R','e','n','d','e','r','e','d',0};
99 /* For types registered with IFilterMapper */
100 static const WCHAR wszTypes
[] = {'T','y','p','e','s',0};
103 /* registry format for REGFILTER2 */
114 BYTE signature
[4]; /* e.g. "0pi3" */
119 DWORD bCategory
; /* is there a category clsid? */
120 /* optional: dwOffsetCategoryClsid */
125 BYTE signature
[4]; /* e.g. "0ty3" */
140 int capacity
; /* in bytes */
141 int current
; /* pointer to next free byte */
144 /* returns the position it was added at */
145 static int add_data(struct Vector
* v
, const BYTE
* pData
, int size
)
147 int index
= v
->current
;
148 if (v
->current
+ size
> v
->capacity
)
150 LPBYTE pOldData
= v
->pData
;
151 v
->capacity
= (v
->capacity
+ size
) * 2;
152 v
->pData
= CoTaskMemAlloc(v
->capacity
);
153 memcpy(v
->pData
, pOldData
, v
->current
);
154 CoTaskMemFree(pOldData
);
156 memcpy(v
->pData
+ v
->current
, pData
, size
);
161 static int find_data(const struct Vector
* v
, const BYTE
* pData
, int size
)
164 for (index
= 0; index
< v
->current
; index
++)
165 if (!memcmp(v
->pData
+ index
, pData
, size
))
171 static void delete_vector(struct Vector
* v
)
173 CoTaskMemFree(v
->pData
);
178 /*** IUnknown (inner) methods ***/
180 static HRESULT WINAPI
Inner_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
182 FilterMapper3Impl
*This
= impl_from_IUnknown(iface
);
184 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
187 if (IsEqualIID(riid
, &IID_IUnknown
))
188 *ppv
= &This
->IUnknown_inner
;
189 else if (IsEqualIID(riid
, &IID_IFilterMapper2
) || IsEqualIID(riid
, &IID_IFilterMapper3
))
190 *ppv
= &This
->IFilterMapper3_iface
;
191 else if (IsEqualIID(riid
, &IID_IFilterMapper
))
192 *ppv
= &This
->IFilterMapper_iface
;
193 else if (IsEqualIID(riid
, &IID_IAMFilterData
))
194 *ppv
= &This
->IAMFilterData_iface
;
198 IUnknown_AddRef((IUnknown
*)*ppv
);
202 FIXME("No interface for %s\n", debugstr_guid(riid
));
203 return E_NOINTERFACE
;
206 static ULONG WINAPI
Inner_AddRef(IUnknown
*iface
)
208 FilterMapper3Impl
*This
= impl_from_IUnknown(iface
);
209 ULONG ref
= InterlockedIncrement(&This
->ref
);
211 TRACE("(%p)->(): new ref = %d\n", This
, ref
);
216 static ULONG WINAPI
Inner_Release(IUnknown
*iface
)
218 FilterMapper3Impl
*This
= impl_from_IUnknown(iface
);
219 ULONG ref
= InterlockedDecrement(&This
->ref
);
221 TRACE("(%p)->(): new ref = %d\n", This
, ref
);
229 static const IUnknownVtbl IInner_VTable
=
231 Inner_QueryInterface
,
236 static HRESULT WINAPI
FilterMapper3_QueryInterface(IFilterMapper3
* iface
, REFIID riid
, LPVOID
*ppv
)
238 FilterMapper3Impl
*This
= impl_from_IFilterMapper3(iface
);
240 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
243 static ULONG WINAPI
FilterMapper3_AddRef(IFilterMapper3
* iface
)
245 FilterMapper3Impl
*This
= impl_from_IFilterMapper3(iface
);
247 return IUnknown_AddRef(This
->outer_unk
);
250 static ULONG WINAPI
FilterMapper3_Release(IFilterMapper3
* iface
)
252 FilterMapper3Impl
*This
= impl_from_IFilterMapper3(iface
);
254 return IUnknown_Release(This
->outer_unk
);
257 /*** IFilterMapper3 methods ***/
259 static HRESULT WINAPI
FilterMapper3_CreateCategory(
260 IFilterMapper3
* iface
,
261 REFCLSID clsidCategory
,
262 DWORD dwCategoryMerit
,
263 LPCWSTR szDescription
)
265 LPWSTR wClsidAMCat
= NULL
;
266 LPWSTR wClsidCategory
= NULL
;
267 WCHAR wszKeyName
[ARRAYSIZE(wszClsidSlash
)-1 + ARRAYSIZE(wszSlashInstance
)-1 + (CHARS_IN_GUID
-1) * 2 + 1];
272 TRACE("(%s, %x, %s)\n", debugstr_guid(clsidCategory
), dwCategoryMerit
, debugstr_w(szDescription
));
274 hr
= StringFromCLSID(&CLSID_ActiveMovieCategories
, &wClsidAMCat
);
278 hr
= StringFromCLSID(clsidCategory
, &wClsidCategory
);
283 strcpyW(wszKeyName
, wszClsidSlash
);
284 strcatW(wszKeyName
, wClsidAMCat
);
285 strcatW(wszKeyName
, wszSlashInstance
);
286 strcatW(wszKeyName
, wClsidCategory
);
288 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
289 hr
= HRESULT_FROM_WIN32(lRet
);
294 lRet
= RegSetValueExW(hKey
, wszFriendlyName
, 0, REG_SZ
, (const BYTE
*)szDescription
, (strlenW(szDescription
) + 1) * sizeof(WCHAR
));
295 hr
= HRESULT_FROM_WIN32(lRet
);
300 lRet
= RegSetValueExW(hKey
, wszClsidName
, 0, REG_SZ
, (LPBYTE
)wClsidCategory
, (strlenW(wClsidCategory
) + 1) * sizeof(WCHAR
));
301 hr
= HRESULT_FROM_WIN32(lRet
);
306 lRet
= RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwCategoryMerit
, sizeof(dwCategoryMerit
));
307 hr
= HRESULT_FROM_WIN32(lRet
);
311 CoTaskMemFree(wClsidCategory
);
312 CoTaskMemFree(wClsidAMCat
);
317 static HRESULT WINAPI
FilterMapper3_UnregisterFilter(
318 IFilterMapper3
* iface
,
319 const CLSID
*pclsidCategory
,
320 const OLECHAR
*szInstance
,
323 WCHAR wszKeyName
[MAX_PATH
];
324 LPWSTR wClsidCategory
= NULL
;
325 LPWSTR wFilter
= NULL
;
328 TRACE("(%p, %s, %s)\n", pclsidCategory
, debugstr_w(szInstance
), debugstr_guid(Filter
));
331 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
333 hr
= StringFromCLSID(pclsidCategory
, &wClsidCategory
);
337 strcpyW(wszKeyName
, wszClsidSlash
);
338 strcatW(wszKeyName
, wClsidCategory
);
339 strcatW(wszKeyName
, wszSlashInstance
);
341 strcatW(wszKeyName
, szInstance
);
344 hr
= StringFromCLSID(Filter
, &wFilter
);
346 strcatW(wszKeyName
, wFilter
);
352 LONG lRet
= RegDeleteKeyW(HKEY_CLASSES_ROOT
, wszKeyName
);
353 hr
= HRESULT_FROM_WIN32(lRet
);
356 CoTaskMemFree(wClsidCategory
);
357 CoTaskMemFree(wFilter
);
362 static HRESULT
FM2_WriteFriendlyName(IPropertyBag
* pPropBag
, LPCWSTR szName
)
368 V_VT(&var
) = VT_BSTR
;
369 V_BSTR(&var
) = value
= SysAllocString(szName
);
371 ret
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
372 SysFreeString(value
);
377 static HRESULT
FM2_WriteClsid(IPropertyBag
* pPropBag
, REFCLSID clsid
)
379 LPWSTR wszClsid
= NULL
;
383 hr
= StringFromCLSID(clsid
, &wszClsid
);
387 V_VT(&var
) = VT_BSTR
;
388 V_BSTR(&var
) = wszClsid
;
389 hr
= IPropertyBag_Write(pPropBag
, wszClsidName
, &var
);
391 CoTaskMemFree(wszClsid
);
395 static HRESULT
FM2_WriteFilterData(const REGFILTER2
* prf2
, BYTE
**ppData
, ULONG
*pcbData
)
397 int size
= sizeof(struct REG_RF
);
399 struct Vector mainStore
= {NULL
, 0, 0};
400 struct Vector clsidStore
= {NULL
, 0, 0};
404 rrf
.dwVersion
= prf2
->dwVersion
;
405 rrf
.dwMerit
= prf2
->dwMerit
;
406 rrf
.dwPins
= prf2
->u
.s2
.cPins2
;
409 add_data(&mainStore
, (LPBYTE
)&rrf
, sizeof(rrf
));
411 for (i
= 0; i
< prf2
->u
.s2
.cPins2
; i
++)
413 size
+= sizeof(struct REG_RFP
);
414 if (prf2
->u
.s2
.rgPins2
[i
].clsPinCategory
)
415 size
+= sizeof(DWORD
);
416 size
+= prf2
->u
.s2
.rgPins2
[i
].nMediaTypes
* sizeof(struct REG_TYPE
);
417 size
+= prf2
->u
.s2
.rgPins2
[i
].nMediums
* sizeof(DWORD
);
420 for (i
= 0; i
< prf2
->u
.s2
.cPins2
; i
++)
423 REGFILTERPINS2 rgPin2
= prf2
->u
.s2
.rgPins2
[i
];
426 rrfp
.signature
[0] = '0';
427 rrfp
.signature
[1] = 'p';
428 rrfp
.signature
[2] = 'i';
429 rrfp
.signature
[3] = '3';
430 rrfp
.signature
[0] += i
;
431 rrfp
.dwFlags
= rgPin2
.dwFlags
;
432 rrfp
.dwInstances
= rgPin2
.cInstances
;
433 rrfp
.dwMediaTypes
= rgPin2
.nMediaTypes
;
434 rrfp
.dwMediums
= rgPin2
.nMediums
;
435 rrfp
.bCategory
= rgPin2
.clsPinCategory
? 1 : 0;
437 add_data(&mainStore
, (LPBYTE
)&rrfp
, sizeof(rrfp
));
440 DWORD index
= find_data(&clsidStore
, (const BYTE
*)rgPin2
.clsPinCategory
, sizeof(CLSID
));
442 index
= add_data(&clsidStore
, (const BYTE
*)rgPin2
.clsPinCategory
, sizeof(CLSID
));
445 add_data(&mainStore
, (LPBYTE
)&index
, sizeof(index
));
448 for (j
= 0; j
< rgPin2
.nMediaTypes
; j
++)
451 const CLSID
* clsMinorType
= rgPin2
.lpMediaType
[j
].clsMinorType
? rgPin2
.lpMediaType
[j
].clsMinorType
: &MEDIASUBTYPE_NULL
;
452 rt
.signature
[0] = '0';
453 rt
.signature
[1] = 't';
454 rt
.signature
[2] = 'y';
455 rt
.signature
[3] = '3';
456 rt
.signature
[0] += j
;
458 rt
.dwOffsetMajor
= find_data(&clsidStore
, (const BYTE
*)rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
459 if (rt
.dwOffsetMajor
== -1)
460 rt
.dwOffsetMajor
= add_data(&clsidStore
, (const BYTE
*)rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
461 rt
.dwOffsetMajor
+= size
;
462 rt
.dwOffsetMinor
= find_data(&clsidStore
, (const BYTE
*)clsMinorType
, sizeof(CLSID
));
463 if (rt
.dwOffsetMinor
== -1)
464 rt
.dwOffsetMinor
= add_data(&clsidStore
, (const BYTE
*)clsMinorType
, sizeof(CLSID
));
465 rt
.dwOffsetMinor
+= size
;
467 add_data(&mainStore
, (LPBYTE
)&rt
, sizeof(rt
));
470 for (j
= 0; j
< rgPin2
.nMediums
; j
++)
472 DWORD index
= find_data(&clsidStore
, (const BYTE
*)(rgPin2
.lpMedium
+ j
), sizeof(REGPINMEDIUM
));
474 index
= add_data(&clsidStore
, (const BYTE
*)(rgPin2
.lpMedium
+ j
), sizeof(REGPINMEDIUM
));
477 add_data(&mainStore
, (LPBYTE
)&index
, sizeof(index
));
483 *pcbData
= mainStore
.current
+ clsidStore
.current
;
484 *ppData
= CoTaskMemAlloc(*pcbData
);
491 memcpy(*ppData
, mainStore
.pData
, mainStore
.current
);
492 memcpy((*ppData
) + mainStore
.current
, clsidStore
.pData
, clsidStore
.current
);
495 delete_vector(&mainStore
);
496 delete_vector(&clsidStore
);
500 static HRESULT
FM2_ReadFilterData(BYTE
*pData
, REGFILTER2
* prf2
)
503 struct REG_RF
* prrf
;
506 REGFILTERPINS2
* rgPins2
;
508 prrf
= (struct REG_RF
*)pData
;
511 if (prrf
->dwVersion
!= 2)
513 FIXME("Filter registry version %d not supported\n", prrf
->dwVersion
);
514 ZeroMemory(prf2
, sizeof(*prf2
));
520 TRACE("version = %d, merit = %x, #pins = %d, unused = %x\n",
521 prrf
->dwVersion
, prrf
->dwMerit
, prrf
->dwPins
, prrf
->dwUnused
);
523 prf2
->dwVersion
= prrf
->dwVersion
;
524 prf2
->dwMerit
= prrf
->dwMerit
;
525 prf2
->u
.s2
.cPins2
= prrf
->dwPins
;
526 rgPins2
= CoTaskMemAlloc(prrf
->dwPins
* sizeof(*rgPins2
));
527 prf2
->u
.s2
.rgPins2
= rgPins2
;
528 pCurrent
+= sizeof(struct REG_RF
);
530 for (i
= 0; i
< prrf
->dwPins
; i
++)
532 struct REG_RFP
* prrfp
= (struct REG_RFP
*)pCurrent
;
533 REGPINTYPES
* lpMediaType
;
534 REGPINMEDIUM
* lpMedium
;
537 /* FIXME: check signature */
539 TRACE("\tsignature = %s\n", debugstr_an((const char*)prrfp
->signature
, 4));
541 TRACE("\tpin[%d]: flags = %x, instances = %d, media types = %d, mediums = %d\n",
542 i
, prrfp
->dwFlags
, prrfp
->dwInstances
, prrfp
->dwMediaTypes
, prrfp
->dwMediums
);
544 rgPins2
[i
].dwFlags
= prrfp
->dwFlags
;
545 rgPins2
[i
].cInstances
= prrfp
->dwInstances
;
546 rgPins2
[i
].nMediaTypes
= prrfp
->dwMediaTypes
;
547 rgPins2
[i
].nMediums
= prrfp
->dwMediums
;
548 pCurrent
+= sizeof(struct REG_RFP
);
549 if (prrfp
->bCategory
)
551 CLSID
* clsCat
= CoTaskMemAlloc(sizeof(CLSID
));
552 memcpy(clsCat
, pData
+ *(DWORD
*)(pCurrent
), sizeof(CLSID
));
553 pCurrent
+= sizeof(DWORD
);
554 rgPins2
[i
].clsPinCategory
= clsCat
;
557 rgPins2
[i
].clsPinCategory
= NULL
;
559 if (rgPins2
[i
].nMediaTypes
> 0)
560 lpMediaType
= CoTaskMemAlloc(rgPins2
[i
].nMediaTypes
* sizeof(*lpMediaType
));
564 rgPins2
[i
].lpMediaType
= lpMediaType
;
566 for (j
= 0; j
< rgPins2
[i
].nMediaTypes
; j
++)
568 struct REG_TYPE
* prt
= (struct REG_TYPE
*)pCurrent
;
569 CLSID
* clsMajor
= CoTaskMemAlloc(sizeof(CLSID
));
570 CLSID
* clsMinor
= CoTaskMemAlloc(sizeof(CLSID
));
572 /* FIXME: check signature */
573 TRACE("\t\tsignature = %s\n", debugstr_an((const char*)prt
->signature
, 4));
575 memcpy(clsMajor
, pData
+ prt
->dwOffsetMajor
, sizeof(CLSID
));
576 memcpy(clsMinor
, pData
+ prt
->dwOffsetMinor
, sizeof(CLSID
));
578 lpMediaType
[j
].clsMajorType
= clsMajor
;
579 lpMediaType
[j
].clsMinorType
= clsMinor
;
581 pCurrent
+= sizeof(*prt
);
584 if (rgPins2
[i
].nMediums
> 0)
585 lpMedium
= CoTaskMemAlloc(rgPins2
[i
].nMediums
* sizeof(*lpMedium
));
589 rgPins2
[i
].lpMedium
= lpMedium
;
591 for (j
= 0; j
< rgPins2
[i
].nMediums
; j
++)
593 DWORD dwOffset
= *(DWORD
*)pCurrent
;
595 memcpy(lpMedium
+ j
, pData
+ dwOffset
, sizeof(REGPINMEDIUM
));
597 pCurrent
+= sizeof(dwOffset
);
606 static void FM2_DeleteRegFilter(REGFILTER2
* prf2
)
609 for (i
= 0; i
< prf2
->u
.s2
.cPins2
; i
++)
612 if (prf2
->u
.s2
.rgPins2
[i
].clsPinCategory
)
613 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].clsPinCategory
);
615 for (j
= 0; j
< prf2
->u
.s2
.rgPins2
[i
].nMediaTypes
; j
++)
617 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
[j
].clsMajorType
);
618 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
[j
].clsMinorType
);
620 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
);
621 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMedium
);
623 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
);
626 static HRESULT WINAPI
FilterMapper3_RegisterFilter(
627 IFilterMapper3
* iface
,
628 REFCLSID clsidFilter
,
630 IMoniker
**ppMoniker
,
631 const CLSID
*pclsidCategory
,
632 const OLECHAR
*szInstance
,
633 const REGFILTER2
*prf2
)
635 IParseDisplayName
* pParser
= NULL
;
636 IBindCtx
* pBindCtx
= NULL
;
637 IMoniker
* pMoniker
= NULL
;
638 IPropertyBag
* pPropBag
= NULL
;
640 LPWSTR pwszParseName
= NULL
;
642 static const WCHAR wszDevice
[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
645 LPWSTR szClsidTemp
= NULL
;
646 REGFILTER2 regfilter2
;
647 REGFILTERPINS2
* pregfp2
= NULL
;
649 TRACE("(%s, %s, %p, %s, %s, %p)\n",
650 debugstr_guid(clsidFilter
),
653 debugstr_guid(pclsidCategory
),
654 debugstr_w(szInstance
),
657 if (prf2
->dwVersion
== 2)
661 else if (prf2
->dwVersion
== 1)
665 /* REGFILTER2 structure is converted from version 1 to 2. Tested on Win2k. */
666 regfilter2
.dwVersion
= 2;
667 regfilter2
.dwMerit
= prf2
->dwMerit
;
668 regfilter2
.u
.s2
.cPins2
= prf2
->u
.s1
.cPins
;
669 pregfp2
= CoTaskMemAlloc(prf2
->u
.s1
.cPins
* sizeof(REGFILTERPINS2
));
670 regfilter2
.u
.s2
.rgPins2
= pregfp2
;
671 for (i
= 0; i
< prf2
->u
.s1
.cPins
; i
++)
674 if (prf2
->u
.s1
.rgPins
[i
].bRendered
)
675 flags
|= REG_PINFLAG_B_RENDERER
;
676 if (prf2
->u
.s1
.rgPins
[i
].bOutput
)
677 flags
|= REG_PINFLAG_B_OUTPUT
;
678 if (prf2
->u
.s1
.rgPins
[i
].bZero
)
679 flags
|= REG_PINFLAG_B_ZERO
;
680 if (prf2
->u
.s1
.rgPins
[i
].bMany
)
681 flags
|= REG_PINFLAG_B_MANY
;
682 pregfp2
[i
].dwFlags
= flags
;
683 pregfp2
[i
].cInstances
= 1;
684 pregfp2
[i
].nMediaTypes
= prf2
->u
.s1
.rgPins
[i
].nMediaTypes
;
685 pregfp2
[i
].lpMediaType
= prf2
->u
.s1
.rgPins
[i
].lpMediaType
;
686 pregfp2
[i
].nMediums
= 0;
687 pregfp2
[i
].lpMedium
= NULL
;
688 pregfp2
[i
].clsPinCategory
= NULL
;
693 FIXME("dwVersion other that 1 or 2 not supported at the moment\n");
701 /* MSDN mentions the inexistent CLSID_ActiveMovieFilters GUID.
702 * In fact this is the CLSID_LegacyAmFilterCategory one */
703 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
705 /* sizeof... will include the null terminator and
706 * the + 1 is for the separator ('\\'). The -1 is
707 * because CHARS_IN_GUID includes the null terminator
709 nameLen
= sizeof(wszDevice
)/sizeof(wszDevice
[0]) + CHARS_IN_GUID
- 1 + 1;
712 nameLen
+= strlenW(szInstance
);
714 nameLen
+= CHARS_IN_GUID
- 1; /* CHARS_IN_GUID includes null terminator */
716 pCurrent
= pwszParseName
= CoTaskMemAlloc(nameLen
*sizeof(WCHAR
));
718 return E_OUTOFMEMORY
;
720 strcpyW(pwszParseName
, wszDevice
);
721 pCurrent
+= strlenW(wszDevice
);
723 hr
= StringFromCLSID(pclsidCategory
, &szClsidTemp
);
727 memcpy(pCurrent
, szClsidTemp
, CHARS_IN_GUID
* sizeof(WCHAR
));
728 pCurrent
+= CHARS_IN_GUID
- 1;
732 strcpyW(pCurrent
+1, szInstance
);
735 CoTaskMemFree(szClsidTemp
);
738 hr
= StringFromCLSID(clsidFilter
, &szClsidTemp
);
740 strcpyW(pCurrent
+1, szClsidTemp
);
745 hr
= CoCreateInstance(&CLSID_CDeviceMoniker
, NULL
, CLSCTX_INPROC
, &IID_IParseDisplayName
, (LPVOID
*)&pParser
);
748 hr
= CreateBindCtx(0, &pBindCtx
);
751 hr
= IParseDisplayName_ParseDisplayName(pParser
, pBindCtx
, pwszParseName
, &ulEaten
, &pMoniker
);
754 IBindCtx_Release(pBindCtx
);
756 IParseDisplayName_Release(pParser
);
759 hr
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
762 hr
= FM2_WriteFriendlyName(pPropBag
, szName
);
765 hr
= FM2_WriteClsid(pPropBag
, clsidFilter
);
772 hr
= FM2_WriteFilterData(®filter2
, &pData
, &cbData
);
777 SAFEARRAYBOUND saBound
;
780 saBound
.cElements
= cbData
;
781 psa
= SafeArrayCreate(VT_UI1
, 1, &saBound
);
784 ERR("Couldn't create SAFEARRAY\n");
791 hr
= SafeArrayAccessData(psa
, (LPVOID
*)&pbSAData
);
794 memcpy(pbSAData
, pData
, cbData
);
795 hr
= SafeArrayUnaccessData(psa
);
799 V_VT(&var
) = VT_ARRAY
| VT_UI1
;
803 hr
= IPropertyBag_Write(pPropBag
, wszFilterDataName
, &var
);
806 SafeArrayDestroy(psa
);
807 CoTaskMemFree(pData
);
812 IPropertyBag_Release(pPropBag
);
813 CoTaskMemFree(szClsidTemp
);
814 CoTaskMemFree(pwszParseName
);
816 if (SUCCEEDED(hr
) && ppMoniker
)
817 *ppMoniker
= pMoniker
;
819 IMoniker_Release(pMoniker
);
821 CoTaskMemFree(pregfp2
);
823 TRACE("-- returning %x\n", hr
);
828 /* internal helper function */
829 static BOOL
MatchTypes(
832 const REGPINTYPES
* pPinTypes
,
834 const GUID
* pMatchTypes
)
839 if ((nMatchTypes
== 0) && (nPinTypes
> 0))
842 for (j
= 0; j
< nPinTypes
; j
++)
845 for (i
= 0; i
< nMatchTypes
*2; i
+=2)
847 if (((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMajorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMajorType
, &pMatchTypes
[i
])) &&
848 ((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMinorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
+1], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMinorType
, &pMatchTypes
[i
+1])))
858 /* internal helper function for qsort of MONIKER_MERIT array */
859 static int mm_compare(const void * left
, const void * right
)
861 const struct MONIKER_MERIT
* mmLeft
= left
;
862 const struct MONIKER_MERIT
* mmRight
= right
;
864 if (mmLeft
->dwMerit
== mmRight
->dwMerit
)
866 if (mmLeft
->dwMerit
> mmRight
->dwMerit
)
872 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
873 * (GUID_NULL's in input to function automatically treated as wild cards)
874 * Input/Output needed means match only on criteria if TRUE (with zero input types
875 * meaning match any input/output pin as long as one exists), otherwise match any
876 * filter that meets the rest of the requirements.
878 static HRESULT WINAPI
FilterMapper3_EnumMatchingFilters(
879 IFilterMapper3
* iface
,
880 IEnumMoniker
**ppEnum
,
886 const GUID
*pInputTypes
,
887 const REGPINMEDIUM
*pMedIn
,
888 const CLSID
*pPinCategoryIn
,
892 const GUID
*pOutputTypes
,
893 const REGPINMEDIUM
*pMedOut
,
894 const CLSID
*pPinCategoryOut
)
896 ICreateDevEnum
* pCreateDevEnum
;
897 IMoniker
* pMonikerCat
;
898 IEnumMoniker
* pEnumCat
;
900 struct Vector monikers
= {NULL
, 0, 0};
902 TRACE("(%p, %x, %s, %x, %s, %d, %p, %p, %p, %s, %s, %p, %p, %p)\n",
905 bExactMatch
? "true" : "false",
907 bInputNeeded
? "true" : "false",
912 bRender
? "true" : "false",
913 bOutputNeeded
? "true" : "false",
920 FIXME("dwFlags = %x not implemented\n", dwFlags
);
925 hr
= CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (LPVOID
*)&pCreateDevEnum
);
929 hr
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &CLSID_ActiveMovieCategories
, &pEnumCat
, 0);
931 ICreateDevEnum_Release(pCreateDevEnum
);
935 while (IEnumMoniker_Next(pEnumCat
, 1, &pMonikerCat
, NULL
) == S_OK
)
937 IPropertyBag
* pPropBagCat
= NULL
;
939 HRESULT hrSub
; /* this is so that one buggy filter
940 doesn't make the whole lot fail */
944 hrSub
= IMoniker_BindToStorage(pMonikerCat
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
946 if (SUCCEEDED(hrSub
))
947 hrSub
= IPropertyBag_Read(pPropBagCat
, wszMeritName
, &var
, NULL
);
949 if (SUCCEEDED(hrSub
) && (V_UI4(&var
) >= dwMerit
))
952 IEnumMoniker
* pEnum
;
957 if (TRACE_ON(quartz
))
960 V_VT(&temp
) = VT_EMPTY
;
961 IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &temp
, NULL
);
962 TRACE("Considering category %s\n", debugstr_w(V_BSTR(&temp
)));
966 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
968 if (SUCCEEDED(hrSub
))
969 hrSub
= CLSIDFromString(V_BSTR(&var
), &clsidCat
);
971 if (SUCCEEDED(hrSub
))
972 hrSub
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &clsidCat
, &pEnum
, 0);
976 while (IEnumMoniker_Next(pEnum
, 1, &pMoniker
, NULL
) == S_OK
)
978 IPropertyBag
* pPropBag
= NULL
;
983 BOOL bInputMatch
= !bInputNeeded
;
984 BOOL bOutputMatch
= !bOutputNeeded
;
986 ZeroMemory(&rf2
, sizeof(rf2
));
989 hrSub
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBag
);
991 if (TRACE_ON(quartz
))
994 V_VT(&temp
) = VT_EMPTY
;
995 IPropertyBag_Read(pPropBag
, wszFriendlyName
, &temp
, NULL
);
996 TRACE("Considering filter %s\n", debugstr_w(V_BSTR(&temp
)));
1000 if (SUCCEEDED(hrSub
))
1002 hrSub
= IPropertyBag_Read(pPropBag
, wszFilterDataName
, &var
, NULL
);
1005 if (SUCCEEDED(hrSub
))
1006 hrSub
= SafeArrayAccessData(V_ARRAY(&var
), (LPVOID
*)&pData
);
1008 if (SUCCEEDED(hrSub
))
1009 hrSub
= FM2_ReadFilterData(pData
, &rf2
);
1012 SafeArrayUnaccessData(V_ARRAY(&var
));
1016 /* Logic used for bInputMatch expression:
1017 * There exists some pin such that bInputNeeded implies (pin is an input and
1018 * (bRender implies pin has render flag) and major/minor types members of
1020 * bOutputMatch is similar, but without the "bRender implies ..." part
1021 * and substituting variables names containing input for output
1024 /* determine whether filter meets requirements */
1025 if (SUCCEEDED(hrSub
) && (rf2
.dwMerit
>= dwMerit
))
1027 for (i
= 0; (i
< rf2
.u
.s2
.cPins2
) && (!bInputMatch
|| !bOutputMatch
); i
++)
1029 const REGFILTERPINS2
* rfp2
= rf2
.u
.s2
.rgPins2
+ i
;
1031 bInputMatch
= bInputMatch
|| (!(rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1032 (!bRender
|| (rfp2
->dwFlags
& REG_PINFLAG_B_RENDERER
)) &&
1033 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cInputTypes
, pInputTypes
));
1034 bOutputMatch
= bOutputMatch
|| ((rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1035 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cOutputTypes
, pOutputTypes
));
1038 if (bInputMatch
&& bOutputMatch
)
1040 struct MONIKER_MERIT mm
= {pMoniker
, rf2
.dwMerit
};
1041 IMoniker_AddRef(pMoniker
);
1042 add_data(&monikers
, (LPBYTE
)&mm
, sizeof(mm
));
1046 FM2_DeleteRegFilter(&rf2
);
1048 IPropertyBag_Release(pPropBag
);
1049 IMoniker_Release(pMoniker
);
1051 IEnumMoniker_Release(pEnum
);
1057 IPropertyBag_Release(pPropBagCat
);
1058 IMoniker_Release(pMonikerCat
);
1063 IMoniker
** ppMoniker
;
1065 ULONG nMonikerCount
= monikers
.current
/ sizeof(struct MONIKER_MERIT
);
1067 /* sort the monikers in descending merit order */
1068 qsort(monikers
.pData
, nMonikerCount
,
1069 sizeof(struct MONIKER_MERIT
),
1072 /* construct an IEnumMoniker interface */
1073 ppMoniker
= CoTaskMemAlloc(nMonikerCount
* sizeof(IMoniker
*));
1074 for (i
= 0; i
< nMonikerCount
; i
++)
1076 /* no need to AddRef here as already AddRef'd above */
1077 ppMoniker
[i
] = ((struct MONIKER_MERIT
*)monikers
.pData
)[i
].pMoniker
;
1079 hr
= EnumMonikerImpl_Create(ppMoniker
, nMonikerCount
, ppEnum
);
1080 CoTaskMemFree(ppMoniker
);
1083 delete_vector(&monikers
);
1084 IEnumMoniker_Release(pEnumCat
);
1085 ICreateDevEnum_Release(pCreateDevEnum
);
1090 static HRESULT WINAPI
FilterMapper3_GetICreateDevEnum(IFilterMapper3
*iface
, ICreateDevEnum
**ppEnum
)
1092 TRACE("(%p, %p)\n", iface
, ppEnum
);
1095 return CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (void**)ppEnum
);
1098 static const IFilterMapper3Vtbl fm3vtbl
=
1101 FilterMapper3_QueryInterface
,
1102 FilterMapper3_AddRef
,
1103 FilterMapper3_Release
,
1105 FilterMapper3_CreateCategory
,
1106 FilterMapper3_UnregisterFilter
,
1107 FilterMapper3_RegisterFilter
,
1108 FilterMapper3_EnumMatchingFilters
,
1109 FilterMapper3_GetICreateDevEnum
1112 /*** IUnknown methods ***/
1114 static HRESULT WINAPI
FilterMapper_QueryInterface(IFilterMapper
* iface
, REFIID riid
, LPVOID
*ppv
)
1116 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1118 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1120 return FilterMapper3_QueryInterface(&This
->IFilterMapper3_iface
, riid
, ppv
);
1123 static ULONG WINAPI
FilterMapper_AddRef(IFilterMapper
* iface
)
1125 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1127 return IUnknown_AddRef(This
->outer_unk
);
1130 static ULONG WINAPI
FilterMapper_Release(IFilterMapper
* iface
)
1132 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1134 return IUnknown_Release(This
->outer_unk
);
1137 /*** IFilterMapper methods ***/
1139 static HRESULT WINAPI
FilterMapper_EnumMatchingFilters(
1140 IFilterMapper
* iface
,
1141 IEnumRegFilters
**ppEnum
,
1151 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1154 IEnumMoniker
* ppEnumMoniker
;
1157 ULONG idx
= 0, nb_mon
= 0;
1158 REGFILTER
* regfilters
;
1161 TRACE("(%p/%p)->(%p, %x, %s, %s, %s, %s, %s, %s, %s) stub!\n",
1165 bInputNeeded
? "true" : "false",
1166 debugstr_guid(&clsInMaj
),
1167 debugstr_guid(&clsInSub
),
1168 bRender
? "true" : "false",
1169 bOutputNeeded
? "true" : "false",
1170 debugstr_guid(&clsOutMaj
),
1171 debugstr_guid(&clsOutSub
));
1173 InputType
[0] = clsInMaj
;
1174 InputType
[1] = clsInSub
;
1175 OutputType
[0] = clsOutMaj
;
1176 OutputType
[1] = clsOutSub
;
1180 hr
= IFilterMapper3_EnumMatchingFilters(&This
->IFilterMapper3_iface
, &ppEnumMoniker
, 0, TRUE
,
1181 dwMerit
, bInputNeeded
, 1, InputType
, NULL
, &GUID_NULL
, bRender
, bOutputNeeded
, 1,
1182 OutputType
, NULL
, &GUID_NULL
);
1187 while(IEnumMoniker_Next(ppEnumMoniker
, 1, &IMon
, &nb
) == S_OK
)
1189 IMoniker_Release(IMon
);
1195 IEnumMoniker_Release(ppEnumMoniker
);
1196 return IEnumRegFiltersImpl_Construct(NULL
, 0, ppEnum
);
1199 regfilters
= CoTaskMemAlloc(nb_mon
* sizeof(REGFILTER
));
1202 IEnumMoniker_Release(ppEnumMoniker
);
1203 return E_OUTOFMEMORY
;
1205 ZeroMemory(regfilters
, nb_mon
* sizeof(REGFILTER
)); /* will prevent bad free of Name in case of error. */
1207 IEnumMoniker_Reset(ppEnumMoniker
);
1208 while(IEnumMoniker_Next(ppEnumMoniker
, 1, &IMon
, &nb
) == S_OK
)
1210 IPropertyBag
* pPropBagCat
= NULL
;
1218 hrSub
= IMoniker_BindToStorage(IMon
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
1220 if (SUCCEEDED(hrSub
))
1221 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
1223 if (SUCCEEDED(hrSub
))
1224 hrSub
= CLSIDFromString(V_BSTR(&var
), &clsid
);
1228 if (SUCCEEDED(hrSub
))
1229 hrSub
= IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &var
, NULL
);
1231 if (SUCCEEDED(hrSub
))
1233 len
= (strlenW(V_BSTR(&var
))+1) * sizeof(WCHAR
);
1234 if (!(regfilters
[idx
].Name
= CoTaskMemAlloc(len
*2)))
1238 if (SUCCEEDED(hrSub
) && regfilters
[idx
].Name
)
1240 memcpy(regfilters
[idx
].Name
, V_BSTR(&var
), len
);
1241 regfilters
[idx
].Clsid
= clsid
;
1246 IPropertyBag_Release(pPropBagCat
);
1247 IMoniker_Release(IMon
);
1253 hr
= IEnumRegFiltersImpl_Construct(regfilters
, nb_mon
, ppEnum
);
1256 for (idx
= 0; idx
< nb_mon
; idx
++)
1257 CoTaskMemFree(regfilters
[idx
].Name
);
1258 CoTaskMemFree(regfilters
);
1259 IEnumMoniker_Release(ppEnumMoniker
);
1265 static HRESULT WINAPI
FilterMapper_RegisterFilter(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, DWORD dwMerit
)
1268 LPWSTR wszClsid
= NULL
;
1271 WCHAR wszKeyName
[ARRAYSIZE(wszFilterSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1273 TRACE("(%p)->(%s, %s, %x)\n", iface
, debugstr_guid(&clsid
), debugstr_w(szName
), dwMerit
);
1275 hr
= StringFromCLSID(&clsid
, &wszClsid
);
1279 strcpyW(wszKeyName
, wszFilterSlash
);
1280 strcatW(wszKeyName
, wszClsid
);
1282 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
1283 hr
= HRESULT_FROM_WIN32(lRet
);
1288 lRet
= RegSetValueExW(hKey
, NULL
, 0, REG_SZ
, (const BYTE
*)szName
, (strlenW(szName
) + 1) * sizeof(WCHAR
));
1289 hr
= HRESULT_FROM_WIN32(lRet
);
1295 strcpyW(wszKeyName
, wszClsidSlash
);
1296 strcatW(wszKeyName
, wszClsid
);
1298 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
1299 hr
= HRESULT_FROM_WIN32(lRet
);
1304 lRet
= RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwMerit
, sizeof(dwMerit
));
1305 hr
= HRESULT_FROM_WIN32(lRet
);
1309 CoTaskMemFree(wszClsid
);
1314 static HRESULT WINAPI
FilterMapper_RegisterFilterInstance(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, CLSID
*MRId
)
1316 TRACE("(%p)->(%s, %s, %p)\n", iface
, debugstr_guid(&clsid
), debugstr_w(szName
), MRId
);
1318 /* Not implemented in Windows (tested on Win2k) */
1323 static HRESULT WINAPI
FilterMapper_RegisterPin(
1324 IFilterMapper
* iface
,
1331 CLSID ConnectsToFilter
,
1332 LPCWSTR ConnectsToPin
)
1336 LPWSTR wszClsid
= NULL
;
1338 HKEY hPinsKey
= NULL
;
1339 WCHAR
* wszPinsKeyName
;
1340 WCHAR wszKeyName
[ARRAYSIZE(wszClsidSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1342 TRACE("(%p)->(%s, %s, %d, %d, %d, %d, %s, %s)\n", iface
, debugstr_guid(&Filter
), debugstr_w(szName
), bRendered
,
1343 bOutput
, bZero
, bMany
, debugstr_guid(&ConnectsToFilter
), debugstr_w(ConnectsToPin
));
1345 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1349 strcpyW(wszKeyName
, wszClsidSlash
);
1350 strcatW(wszKeyName
, wszClsid
);
1352 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1353 hr
= HRESULT_FROM_WIN32(lRet
);
1358 wszPinsKeyName
= CoTaskMemAlloc((strlenW(wszPins
) + 1 + strlenW(szName
) + 1) * 2);
1359 if (!wszPinsKeyName
)
1365 strcpyW(wszPinsKeyName
, wszPins
);
1366 strcatW(wszPinsKeyName
, wszSlash
);
1367 strcatW(wszPinsKeyName
, szName
);
1369 lRet
= RegCreateKeyExW(hKey
, wszPinsKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hPinsKey
, NULL
);
1370 hr
= HRESULT_FROM_WIN32(lRet
);
1371 CoTaskMemFree(wszPinsKeyName
);
1376 lRet
= RegSetValueExW(hPinsKey
, wszAllowedMany
, 0, REG_DWORD
, (LPBYTE
)&bMany
, sizeof(bMany
));
1377 hr
= HRESULT_FROM_WIN32(lRet
);
1382 lRet
= RegSetValueExW(hPinsKey
, wszAllowedZero
, 0, REG_DWORD
, (LPBYTE
)&bZero
, sizeof(bZero
));
1383 hr
= HRESULT_FROM_WIN32(lRet
);
1388 lRet
= RegSetValueExW(hPinsKey
, wszDirection
, 0, REG_DWORD
, (LPBYTE
)&bOutput
, sizeof(bOutput
));
1389 hr
= HRESULT_FROM_WIN32(lRet
);
1394 lRet
= RegSetValueExW(hPinsKey
, wszIsRendered
, 0, REG_DWORD
, (LPBYTE
)&bRendered
, sizeof(bRendered
));
1395 hr
= HRESULT_FROM_WIN32(lRet
);
1400 HKEY hkeyDummy
= NULL
;
1402 lRet
= RegCreateKeyExW(hPinsKey
, wszTypes
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkeyDummy
, NULL
);
1403 hr
= HRESULT_FROM_WIN32(lRet
);
1405 if (hkeyDummy
) RegCloseKey(hkeyDummy
);
1408 CoTaskMemFree(wszClsid
);
1412 RegCloseKey(hPinsKey
);
1418 static HRESULT WINAPI
FilterMapper_RegisterPinType(
1419 IFilterMapper
* iface
,
1427 LPWSTR wszClsid
= NULL
;
1428 LPWSTR wszClsidMajorType
= NULL
;
1429 LPWSTR wszClsidSubType
= NULL
;
1431 WCHAR
* wszTypesKey
;
1432 WCHAR wszKeyName
[MAX_PATH
];
1434 TRACE("(%p)->(%s, %s, %s, %s)\n", iface
, debugstr_guid(&clsFilter
), debugstr_w(szName
),
1435 debugstr_guid(&clsMajorType
), debugstr_guid(&clsSubType
));
1437 hr
= StringFromCLSID(&clsFilter
, &wszClsid
);
1441 hr
= StringFromCLSID(&clsMajorType
, &wszClsidMajorType
);
1446 hr
= StringFromCLSID(&clsSubType
, &wszClsidSubType
);
1451 wszTypesKey
= CoTaskMemAlloc((strlenW(wszClsidSlash
) + strlenW(wszClsid
) + strlenW(wszPins
) +
1452 strlenW(szName
) + strlenW(wszTypes
) + 3 + 1) * 2);
1459 strcpyW(wszTypesKey
, wszClsidSlash
);
1460 strcatW(wszTypesKey
, wszClsid
);
1461 strcatW(wszTypesKey
, wszSlash
);
1462 strcatW(wszTypesKey
, wszPins
);
1463 strcatW(wszTypesKey
, wszSlash
);
1464 strcatW(wszTypesKey
, szName
);
1465 strcatW(wszTypesKey
, wszSlash
);
1466 strcatW(wszTypesKey
, wszTypes
);
1468 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszTypesKey
, 0, KEY_WRITE
, &hKey
);
1469 hr
= HRESULT_FROM_WIN32(lRet
);
1470 CoTaskMemFree(wszTypesKey
);
1475 HKEY hkeyDummy
= NULL
;
1477 strcpyW(wszKeyName
, wszClsidMajorType
);
1478 strcatW(wszKeyName
, wszSlash
);
1479 strcatW(wszKeyName
, wszClsidSubType
);
1481 lRet
= RegCreateKeyExW(hKey
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkeyDummy
, NULL
);
1482 hr
= HRESULT_FROM_WIN32(lRet
);
1485 if (hkeyDummy
) RegCloseKey(hkeyDummy
);
1488 CoTaskMemFree(wszClsid
);
1489 CoTaskMemFree(wszClsidMajorType
);
1490 CoTaskMemFree(wszClsidSubType
);
1495 static HRESULT WINAPI
FilterMapper_UnregisterFilter(IFilterMapper
* iface
, CLSID Filter
)
1499 LPWSTR wszClsid
= NULL
;
1501 WCHAR wszKeyName
[ARRAYSIZE(wszClsidSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1503 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(&Filter
));
1505 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1509 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszFilter
, 0, KEY_WRITE
, &hKey
);
1510 hr
= HRESULT_FROM_WIN32(lRet
);
1515 lRet
= RegDeleteKeyW(hKey
, wszClsid
);
1516 hr
= HRESULT_FROM_WIN32(lRet
);
1522 strcpyW(wszKeyName
, wszClsidSlash
);
1523 strcatW(wszKeyName
, wszClsid
);
1525 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1526 hr
= HRESULT_FROM_WIN32(lRet
);
1531 lRet
= RegDeleteValueW(hKey
, wszMeritName
);
1532 if (lRet
!= ERROR_SUCCESS
)
1533 hr
= HRESULT_FROM_WIN32(lRet
);
1535 lRet
= RegDeleteTreeW(hKey
, wszPins
);
1536 if (lRet
!= ERROR_SUCCESS
)
1537 hr
= HRESULT_FROM_WIN32(lRet
);
1542 CoTaskMemFree(wszClsid
);
1547 static HRESULT WINAPI
FilterMapper_UnregisterFilterInstance(IFilterMapper
* iface
, CLSID MRId
)
1549 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(&MRId
));
1551 /* Not implemented in Windows (tested on Win2k) */
1556 static HRESULT WINAPI
FilterMapper_UnregisterPin(IFilterMapper
* iface
, CLSID Filter
, LPCWSTR Name
)
1560 LPWSTR wszClsid
= NULL
;
1562 WCHAR
* wszPinNameKey
;
1563 WCHAR wszKeyName
[ARRAYSIZE(wszClsidSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1565 TRACE("(%p)->(%s, %s)\n", iface
, debugstr_guid(&Filter
), debugstr_w(Name
));
1568 return E_INVALIDARG
;
1570 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1574 strcpyW(wszKeyName
, wszClsidSlash
);
1575 strcatW(wszKeyName
, wszClsid
);
1577 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1578 hr
= HRESULT_FROM_WIN32(lRet
);
1583 wszPinNameKey
= CoTaskMemAlloc((strlenW(wszPins
) + 1 + strlenW(Name
) + 1) * 2);
1590 strcpyW(wszPinNameKey
, wszPins
);
1591 strcatW(wszPinNameKey
, wszSlash
);
1592 strcatW(wszPinNameKey
, Name
);
1594 lRet
= RegDeleteTreeW(hKey
, wszPinNameKey
);
1595 hr
= HRESULT_FROM_WIN32(lRet
);
1596 CoTaskMemFree(wszPinNameKey
);
1599 CoTaskMemFree(wszClsid
);
1606 static const IFilterMapperVtbl fmvtbl
=
1609 FilterMapper_QueryInterface
,
1610 FilterMapper_AddRef
,
1611 FilterMapper_Release
,
1613 FilterMapper_RegisterFilter
,
1614 FilterMapper_RegisterFilterInstance
,
1615 FilterMapper_RegisterPin
,
1616 FilterMapper_RegisterPinType
,
1617 FilterMapper_UnregisterFilter
,
1618 FilterMapper_UnregisterFilterInstance
,
1619 FilterMapper_UnregisterPin
,
1620 FilterMapper_EnumMatchingFilters
1624 /*** IUnknown methods ***/
1625 static HRESULT WINAPI
AMFilterData_QueryInterface(IAMFilterData
* iface
, REFIID riid
, LPVOID
*ppv
)
1627 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1629 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
1632 static ULONG WINAPI
AMFilterData_AddRef(IAMFilterData
* iface
)
1634 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1636 return IUnknown_AddRef(This
->outer_unk
);
1639 static ULONG WINAPI
AMFilterData_Release(IAMFilterData
* iface
)
1641 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1643 return IUnknown_Release(This
->outer_unk
);
1646 /*** IAMFilterData methods ***/
1647 static HRESULT WINAPI
AMFilterData_ParseFilterData(IAMFilterData
* iface
,
1648 BYTE
*pData
, ULONG cb
,
1649 BYTE
**ppRegFilter2
)
1651 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1653 static REGFILTER2
*prf2
;
1655 TRACE("(%p/%p)->(%p, %d, %p)\n", This
, iface
, pData
, cb
, ppRegFilter2
);
1657 prf2
= CoTaskMemAlloc(sizeof(*prf2
));
1659 return E_OUTOFMEMORY
;
1660 *ppRegFilter2
= (BYTE
*)&prf2
;
1662 hr
= FM2_ReadFilterData(pData
, prf2
);
1665 CoTaskMemFree(prf2
);
1666 *ppRegFilter2
= NULL
;
1672 static HRESULT WINAPI
AMFilterData_CreateFilterData(IAMFilterData
* iface
,
1674 BYTE
**pRegFilterData
,
1677 FilterMapper3Impl
*This
= impl_from_IAMFilterData(iface
);
1679 TRACE("(%p/%p)->(%p, %p, %p)\n", This
, iface
, prf2
, pRegFilterData
, pcb
);
1681 return FM2_WriteFilterData(prf2
, pRegFilterData
, pcb
);
1684 static const IAMFilterDataVtbl AMFilterDataVtbl
= {
1685 AMFilterData_QueryInterface
,
1686 AMFilterData_AddRef
,
1687 AMFilterData_Release
,
1688 AMFilterData_ParseFilterData
,
1689 AMFilterData_CreateFilterData
1692 HRESULT
FilterMapper2_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
1694 FilterMapper3Impl
* pFM2impl
;
1696 TRACE("(%p, %p)\n", pUnkOuter
, ppObj
);
1698 pFM2impl
= CoTaskMemAlloc(sizeof(*pFM2impl
));
1700 return E_OUTOFMEMORY
;
1702 pFM2impl
->IUnknown_inner
.lpVtbl
= &IInner_VTable
;
1703 pFM2impl
->IFilterMapper3_iface
.lpVtbl
= &fm3vtbl
;
1704 pFM2impl
->IFilterMapper_iface
.lpVtbl
= &fmvtbl
;
1705 pFM2impl
->IAMFilterData_iface
.lpVtbl
= &AMFilterDataVtbl
;
1709 pFM2impl
->outer_unk
= pUnkOuter
;
1711 pFM2impl
->outer_unk
= &pFM2impl
->IUnknown_inner
;
1713 *ppObj
= &pFM2impl
->IUnknown_inner
;
1715 TRACE("-- created at %p\n", pFM2impl
);
1720 HRESULT
FilterMapper_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
1722 FilterMapper3Impl
*pFM2impl
;
1725 TRACE("(%p, %p)\n", pUnkOuter
, ppObj
);
1727 hr
= FilterMapper2_create(pUnkOuter
, (LPVOID
*)&pFM2impl
);
1731 *ppObj
= &pFM2impl
->IFilterMapper_iface
;