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 CoTaskMemFree((void*)prf2
->u
.s2
.rgPins2
[i
].clsPinCategory
);
614 for (j
= 0; j
< prf2
->u
.s2
.rgPins2
[i
].nMediaTypes
; j
++)
616 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
[j
].clsMajorType
);
617 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
[j
].clsMinorType
);
619 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
);
620 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMedium
);
622 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
);
625 static HRESULT WINAPI
FilterMapper3_RegisterFilter(
626 IFilterMapper3
* iface
,
627 REFCLSID clsidFilter
,
629 IMoniker
**ppMoniker
,
630 const CLSID
*pclsidCategory
,
631 const OLECHAR
*szInstance
,
632 const REGFILTER2
*prf2
)
634 IParseDisplayName
* pParser
= NULL
;
635 IBindCtx
* pBindCtx
= NULL
;
636 IMoniker
* pMoniker
= NULL
;
637 IPropertyBag
* pPropBag
= NULL
;
639 LPWSTR pwszParseName
= NULL
;
641 static const WCHAR wszDevice
[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
644 LPWSTR szClsidTemp
= NULL
;
645 REGFILTER2 regfilter2
;
646 REGFILTERPINS2
* pregfp2
= NULL
;
648 TRACE("(%s, %s, %p, %s, %s, %p)\n",
649 debugstr_guid(clsidFilter
),
652 debugstr_guid(pclsidCategory
),
653 debugstr_w(szInstance
),
656 if (prf2
->dwVersion
== 2)
660 else if (prf2
->dwVersion
== 1)
664 /* REGFILTER2 structure is converted from version 1 to 2. Tested on Win2k. */
665 regfilter2
.dwVersion
= 2;
666 regfilter2
.dwMerit
= prf2
->dwMerit
;
667 regfilter2
.u
.s2
.cPins2
= prf2
->u
.s1
.cPins
;
668 pregfp2
= CoTaskMemAlloc(prf2
->u
.s1
.cPins
* sizeof(REGFILTERPINS2
));
669 regfilter2
.u
.s2
.rgPins2
= pregfp2
;
670 for (i
= 0; i
< prf2
->u
.s1
.cPins
; i
++)
673 if (prf2
->u
.s1
.rgPins
[i
].bRendered
)
674 flags
|= REG_PINFLAG_B_RENDERER
;
675 if (prf2
->u
.s1
.rgPins
[i
].bOutput
)
676 flags
|= REG_PINFLAG_B_OUTPUT
;
677 if (prf2
->u
.s1
.rgPins
[i
].bZero
)
678 flags
|= REG_PINFLAG_B_ZERO
;
679 if (prf2
->u
.s1
.rgPins
[i
].bMany
)
680 flags
|= REG_PINFLAG_B_MANY
;
681 pregfp2
[i
].dwFlags
= flags
;
682 pregfp2
[i
].cInstances
= 1;
683 pregfp2
[i
].nMediaTypes
= prf2
->u
.s1
.rgPins
[i
].nMediaTypes
;
684 pregfp2
[i
].lpMediaType
= prf2
->u
.s1
.rgPins
[i
].lpMediaType
;
685 pregfp2
[i
].nMediums
= 0;
686 pregfp2
[i
].lpMedium
= NULL
;
687 pregfp2
[i
].clsPinCategory
= NULL
;
692 FIXME("dwVersion other that 1 or 2 not supported at the moment\n");
700 /* MSDN mentions the inexistent CLSID_ActiveMovieFilters GUID.
701 * In fact this is the CLSID_LegacyAmFilterCategory one */
702 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
704 /* sizeof... will include the null terminator and
705 * the + 1 is for the separator ('\\'). The -1 is
706 * because CHARS_IN_GUID includes the null terminator
708 nameLen
= sizeof(wszDevice
)/sizeof(wszDevice
[0]) + CHARS_IN_GUID
- 1 + 1;
711 nameLen
+= strlenW(szInstance
);
713 nameLen
+= CHARS_IN_GUID
- 1; /* CHARS_IN_GUID includes null terminator */
715 pCurrent
= pwszParseName
= CoTaskMemAlloc(nameLen
*sizeof(WCHAR
));
717 return E_OUTOFMEMORY
;
719 strcpyW(pwszParseName
, wszDevice
);
720 pCurrent
+= strlenW(wszDevice
);
722 hr
= StringFromCLSID(pclsidCategory
, &szClsidTemp
);
726 memcpy(pCurrent
, szClsidTemp
, CHARS_IN_GUID
* sizeof(WCHAR
));
727 pCurrent
+= CHARS_IN_GUID
- 1;
731 strcpyW(pCurrent
+1, szInstance
);
734 CoTaskMemFree(szClsidTemp
);
737 hr
= StringFromCLSID(clsidFilter
, &szClsidTemp
);
739 strcpyW(pCurrent
+1, szClsidTemp
);
744 hr
= CoCreateInstance(&CLSID_CDeviceMoniker
, NULL
, CLSCTX_INPROC
, &IID_IParseDisplayName
, (LPVOID
*)&pParser
);
747 hr
= CreateBindCtx(0, &pBindCtx
);
750 hr
= IParseDisplayName_ParseDisplayName(pParser
, pBindCtx
, pwszParseName
, &ulEaten
, &pMoniker
);
753 IBindCtx_Release(pBindCtx
);
755 IParseDisplayName_Release(pParser
);
758 hr
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
761 hr
= FM2_WriteFriendlyName(pPropBag
, szName
);
764 hr
= FM2_WriteClsid(pPropBag
, clsidFilter
);
771 hr
= FM2_WriteFilterData(®filter2
, &pData
, &cbData
);
776 SAFEARRAYBOUND saBound
;
779 saBound
.cElements
= cbData
;
780 psa
= SafeArrayCreate(VT_UI1
, 1, &saBound
);
783 ERR("Couldn't create SAFEARRAY\n");
790 hr
= SafeArrayAccessData(psa
, (LPVOID
*)&pbSAData
);
793 memcpy(pbSAData
, pData
, cbData
);
794 hr
= SafeArrayUnaccessData(psa
);
798 V_VT(&var
) = VT_ARRAY
| VT_UI1
;
802 hr
= IPropertyBag_Write(pPropBag
, wszFilterDataName
, &var
);
805 SafeArrayDestroy(psa
);
806 CoTaskMemFree(pData
);
811 IPropertyBag_Release(pPropBag
);
812 CoTaskMemFree(szClsidTemp
);
813 CoTaskMemFree(pwszParseName
);
815 if (SUCCEEDED(hr
) && ppMoniker
)
816 *ppMoniker
= pMoniker
;
818 IMoniker_Release(pMoniker
);
820 CoTaskMemFree(pregfp2
);
822 TRACE("-- returning %x\n", hr
);
827 /* internal helper function */
828 static BOOL
MatchTypes(
831 const REGPINTYPES
* pPinTypes
,
833 const GUID
* pMatchTypes
)
838 if ((nMatchTypes
== 0) && (nPinTypes
> 0))
841 for (j
= 0; j
< nPinTypes
; j
++)
844 for (i
= 0; i
< nMatchTypes
*2; i
+=2)
846 if (((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMajorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMajorType
, &pMatchTypes
[i
])) &&
847 ((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMinorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
+1], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMinorType
, &pMatchTypes
[i
+1])))
857 /* internal helper function for qsort of MONIKER_MERIT array */
858 static int mm_compare(const void * left
, const void * right
)
860 const struct MONIKER_MERIT
* mmLeft
= left
;
861 const struct MONIKER_MERIT
* mmRight
= right
;
863 if (mmLeft
->dwMerit
== mmRight
->dwMerit
)
865 if (mmLeft
->dwMerit
> mmRight
->dwMerit
)
871 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
872 * (GUID_NULL's in input to function automatically treated as wild cards)
873 * Input/Output needed means match only on criteria if TRUE (with zero input types
874 * meaning match any input/output pin as long as one exists), otherwise match any
875 * filter that meets the rest of the requirements.
877 static HRESULT WINAPI
FilterMapper3_EnumMatchingFilters(
878 IFilterMapper3
* iface
,
879 IEnumMoniker
**ppEnum
,
885 const GUID
*pInputTypes
,
886 const REGPINMEDIUM
*pMedIn
,
887 const CLSID
*pPinCategoryIn
,
891 const GUID
*pOutputTypes
,
892 const REGPINMEDIUM
*pMedOut
,
893 const CLSID
*pPinCategoryOut
)
895 ICreateDevEnum
* pCreateDevEnum
;
896 IMoniker
* pMonikerCat
;
897 IEnumMoniker
* pEnumCat
;
899 struct Vector monikers
= {NULL
, 0, 0};
901 TRACE("(%p, %x, %s, %x, %s, %d, %p, %p, %p, %s, %s, %p, %p, %p)\n",
904 bExactMatch
? "true" : "false",
906 bInputNeeded
? "true" : "false",
911 bRender
? "true" : "false",
912 bOutputNeeded
? "true" : "false",
919 FIXME("dwFlags = %x not implemented\n", dwFlags
);
924 hr
= CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (LPVOID
*)&pCreateDevEnum
);
928 hr
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &CLSID_ActiveMovieCategories
, &pEnumCat
, 0);
930 ICreateDevEnum_Release(pCreateDevEnum
);
934 while (IEnumMoniker_Next(pEnumCat
, 1, &pMonikerCat
, NULL
) == S_OK
)
936 IPropertyBag
* pPropBagCat
= NULL
;
938 HRESULT hrSub
; /* this is so that one buggy filter
939 doesn't make the whole lot fail */
943 hrSub
= IMoniker_BindToStorage(pMonikerCat
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
945 if (SUCCEEDED(hrSub
))
946 hrSub
= IPropertyBag_Read(pPropBagCat
, wszMeritName
, &var
, NULL
);
948 if (SUCCEEDED(hrSub
) && (V_UI4(&var
) >= dwMerit
))
951 IEnumMoniker
* pEnum
;
956 if (TRACE_ON(quartz
))
959 V_VT(&temp
) = VT_EMPTY
;
960 IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &temp
, NULL
);
961 TRACE("Considering category %s\n", debugstr_w(V_BSTR(&temp
)));
965 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
967 if (SUCCEEDED(hrSub
))
968 hrSub
= CLSIDFromString(V_BSTR(&var
), &clsidCat
);
970 if (SUCCEEDED(hrSub
))
971 hrSub
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &clsidCat
, &pEnum
, 0);
975 while (IEnumMoniker_Next(pEnum
, 1, &pMoniker
, NULL
) == S_OK
)
977 IPropertyBag
* pPropBag
= NULL
;
982 BOOL bInputMatch
= !bInputNeeded
;
983 BOOL bOutputMatch
= !bOutputNeeded
;
985 ZeroMemory(&rf2
, sizeof(rf2
));
988 hrSub
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBag
);
990 if (TRACE_ON(quartz
))
993 V_VT(&temp
) = VT_EMPTY
;
994 IPropertyBag_Read(pPropBag
, wszFriendlyName
, &temp
, NULL
);
995 TRACE("Considering filter %s\n", debugstr_w(V_BSTR(&temp
)));
999 if (SUCCEEDED(hrSub
))
1001 hrSub
= IPropertyBag_Read(pPropBag
, wszFilterDataName
, &var
, NULL
);
1004 if (SUCCEEDED(hrSub
))
1005 hrSub
= SafeArrayAccessData(V_ARRAY(&var
), (LPVOID
*)&pData
);
1007 if (SUCCEEDED(hrSub
))
1008 hrSub
= FM2_ReadFilterData(pData
, &rf2
);
1011 SafeArrayUnaccessData(V_ARRAY(&var
));
1015 /* Logic used for bInputMatch expression:
1016 * There exists some pin such that bInputNeeded implies (pin is an input and
1017 * (bRender implies pin has render flag) and major/minor types members of
1019 * bOutputMatch is similar, but without the "bRender implies ..." part
1020 * and substituting variables names containing input for output
1023 /* determine whether filter meets requirements */
1024 if (SUCCEEDED(hrSub
) && (rf2
.dwMerit
>= dwMerit
))
1026 for (i
= 0; (i
< rf2
.u
.s2
.cPins2
) && (!bInputMatch
|| !bOutputMatch
); i
++)
1028 const REGFILTERPINS2
* rfp2
= rf2
.u
.s2
.rgPins2
+ i
;
1030 bInputMatch
= bInputMatch
|| (!(rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1031 (!bRender
|| (rfp2
->dwFlags
& REG_PINFLAG_B_RENDERER
)) &&
1032 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cInputTypes
, pInputTypes
));
1033 bOutputMatch
= bOutputMatch
|| ((rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1034 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cOutputTypes
, pOutputTypes
));
1037 if (bInputMatch
&& bOutputMatch
)
1039 struct MONIKER_MERIT mm
= {pMoniker
, rf2
.dwMerit
};
1040 IMoniker_AddRef(pMoniker
);
1041 add_data(&monikers
, (LPBYTE
)&mm
, sizeof(mm
));
1045 FM2_DeleteRegFilter(&rf2
);
1047 IPropertyBag_Release(pPropBag
);
1048 IMoniker_Release(pMoniker
);
1050 IEnumMoniker_Release(pEnum
);
1056 IPropertyBag_Release(pPropBagCat
);
1057 IMoniker_Release(pMonikerCat
);
1062 IMoniker
** ppMoniker
;
1064 ULONG nMonikerCount
= monikers
.current
/ sizeof(struct MONIKER_MERIT
);
1066 /* sort the monikers in descending merit order */
1067 qsort(monikers
.pData
, nMonikerCount
,
1068 sizeof(struct MONIKER_MERIT
),
1071 /* construct an IEnumMoniker interface */
1072 ppMoniker
= CoTaskMemAlloc(nMonikerCount
* sizeof(IMoniker
*));
1073 for (i
= 0; i
< nMonikerCount
; i
++)
1075 /* no need to AddRef here as already AddRef'd above */
1076 ppMoniker
[i
] = ((struct MONIKER_MERIT
*)monikers
.pData
)[i
].pMoniker
;
1078 hr
= EnumMonikerImpl_Create(ppMoniker
, nMonikerCount
, ppEnum
);
1079 CoTaskMemFree(ppMoniker
);
1082 delete_vector(&monikers
);
1083 IEnumMoniker_Release(pEnumCat
);
1084 ICreateDevEnum_Release(pCreateDevEnum
);
1089 static HRESULT WINAPI
FilterMapper3_GetICreateDevEnum(IFilterMapper3
*iface
, ICreateDevEnum
**ppEnum
)
1091 TRACE("(%p, %p)\n", iface
, ppEnum
);
1094 return CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (void**)ppEnum
);
1097 static const IFilterMapper3Vtbl fm3vtbl
=
1100 FilterMapper3_QueryInterface
,
1101 FilterMapper3_AddRef
,
1102 FilterMapper3_Release
,
1104 FilterMapper3_CreateCategory
,
1105 FilterMapper3_UnregisterFilter
,
1106 FilterMapper3_RegisterFilter
,
1107 FilterMapper3_EnumMatchingFilters
,
1108 FilterMapper3_GetICreateDevEnum
1111 /*** IUnknown methods ***/
1113 static HRESULT WINAPI
FilterMapper_QueryInterface(IFilterMapper
* iface
, REFIID riid
, LPVOID
*ppv
)
1115 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1117 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1119 return FilterMapper3_QueryInterface(&This
->IFilterMapper3_iface
, riid
, ppv
);
1122 static ULONG WINAPI
FilterMapper_AddRef(IFilterMapper
* iface
)
1124 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1126 return IUnknown_AddRef(This
->outer_unk
);
1129 static ULONG WINAPI
FilterMapper_Release(IFilterMapper
* iface
)
1131 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1133 return IUnknown_Release(This
->outer_unk
);
1136 /*** IFilterMapper methods ***/
1138 static HRESULT WINAPI
FilterMapper_EnumMatchingFilters(
1139 IFilterMapper
* iface
,
1140 IEnumRegFilters
**ppEnum
,
1150 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1153 IEnumMoniker
* ppEnumMoniker
;
1156 ULONG idx
= 0, nb_mon
= 0;
1157 REGFILTER
* regfilters
;
1160 TRACE("(%p/%p)->(%p, %x, %s, %s, %s, %s, %s, %s, %s)\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
;