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"
39 #include "wine/fil_data.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
45 typedef struct FilterMapper3Impl
47 IUnknown IUnknown_inner
;
48 IFilterMapper3 IFilterMapper3_iface
;
49 IFilterMapper IFilterMapper_iface
;
50 IAMFilterData IAMFilterData_iface
;
55 static inline FilterMapper3Impl
*impl_from_IFilterMapper3( IFilterMapper3
*iface
)
57 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IFilterMapper3_iface
);
60 static inline FilterMapper3Impl
*impl_from_IFilterMapper( IFilterMapper
*iface
)
62 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IFilterMapper_iface
);
65 static inline FilterMapper3Impl
*impl_from_IAMFilterData( IAMFilterData
*iface
)
67 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IAMFilterData_iface
);
70 static inline FilterMapper3Impl
*impl_from_IUnknown( IUnknown
*iface
)
72 return CONTAINING_RECORD(iface
, FilterMapper3Impl
, IUnknown_inner
);
75 static const WCHAR wszClsidSlash
[] = {'C','L','S','I','D','\\',0};
76 static const WCHAR wszSlashInstance
[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
77 static const WCHAR wszSlash
[] = {'\\',0};
79 /* CLSID property in media category Moniker */
80 static const WCHAR wszClsidName
[] = {'C','L','S','I','D',0};
81 /* FriendlyName property in media category Moniker */
82 static const WCHAR wszFriendlyName
[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
83 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
84 static const WCHAR wszMeritName
[] = {'M','e','r','i','t',0};
85 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
86 static const WCHAR wszFilterDataName
[] = {'F','i','l','t','e','r','D','a','t','a',0};
87 /* For filters registered with IFilterMapper */
88 static const WCHAR wszFilterSlash
[] = {'F','i','l','t','e','r','\\',0};
89 static const WCHAR wszFilter
[] = {'F','i','l','t','e','r',0};
90 /* For pins registered with IFilterMapper */
91 static const WCHAR wszPins
[] = {'P','i','n','s',0};
92 static const WCHAR wszAllowedMany
[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
93 static const WCHAR wszAllowedZero
[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
94 static const WCHAR wszDirection
[] = {'D','i','r','e','c','t','i','o','n',0};
95 static const WCHAR wszIsRendered
[] = {'I','s','R','e','n','d','e','r','e','d',0};
96 /* For types registered with IFilterMapper */
97 static const WCHAR wszTypes
[] = {'T','y','p','e','s',0};
100 /* registry format for REGFILTER2 */
111 BYTE signature
[4]; /* e.g. "0pi3" */
116 DWORD bCategory
; /* is there a category clsid? */
117 /* optional: dwOffsetCategoryClsid */
122 BYTE signature
[4]; /* e.g. "0ty3" */
137 int capacity
; /* in bytes */
138 int current
; /* pointer to next free byte */
141 /* returns the position it was added at */
142 static int add_data(struct Vector
*v
, const void *pData
, int size
)
144 int index
= v
->current
;
145 if (v
->current
+ size
> v
->capacity
)
147 int new_capacity
= (v
->capacity
+ size
) * 2;
148 BYTE
*new_data
= CoTaskMemRealloc(v
->pData
, new_capacity
);
149 if (!new_data
) return -1;
150 v
->capacity
= new_capacity
;
153 memcpy(v
->pData
+ v
->current
, pData
, size
);
158 static int find_data(const struct Vector
*v
, const void *pData
, int size
)
161 for (index
= 0; index
< v
->current
; index
++)
162 if (!memcmp(v
->pData
+ index
, pData
, size
))
168 static void delete_vector(struct Vector
* v
)
170 CoTaskMemFree(v
->pData
);
175 /*** IUnknown (inner) methods ***/
177 static HRESULT WINAPI
Inner_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
179 FilterMapper3Impl
*This
= impl_from_IUnknown(iface
);
181 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
184 if (IsEqualIID(riid
, &IID_IUnknown
))
185 *ppv
= &This
->IUnknown_inner
;
186 else if (IsEqualIID(riid
, &IID_IFilterMapper2
) || IsEqualIID(riid
, &IID_IFilterMapper3
))
187 *ppv
= &This
->IFilterMapper3_iface
;
188 else if (IsEqualIID(riid
, &IID_IFilterMapper
))
189 *ppv
= &This
->IFilterMapper_iface
;
190 else if (IsEqualIID(riid
, &IID_IAMFilterData
))
191 *ppv
= &This
->IAMFilterData_iface
;
195 IUnknown_AddRef((IUnknown
*)*ppv
);
199 FIXME("No interface for %s\n", debugstr_guid(riid
));
200 return E_NOINTERFACE
;
203 static ULONG WINAPI
Inner_AddRef(IUnknown
*iface
)
205 FilterMapper3Impl
*This
= impl_from_IUnknown(iface
);
206 ULONG ref
= InterlockedIncrement(&This
->ref
);
208 TRACE("(%p)->(): new ref = %d\n", This
, ref
);
213 static ULONG WINAPI
Inner_Release(IUnknown
*iface
)
215 FilterMapper3Impl
*This
= impl_from_IUnknown(iface
);
216 ULONG ref
= InterlockedDecrement(&This
->ref
);
218 TRACE("(%p)->(): new ref = %d\n", This
, ref
);
226 static const IUnknownVtbl IInner_VTable
=
228 Inner_QueryInterface
,
233 static HRESULT WINAPI
FilterMapper3_QueryInterface(IFilterMapper3
* iface
, REFIID riid
, LPVOID
*ppv
)
235 FilterMapper3Impl
*This
= impl_from_IFilterMapper3(iface
);
237 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
240 static ULONG WINAPI
FilterMapper3_AddRef(IFilterMapper3
* iface
)
242 FilterMapper3Impl
*This
= impl_from_IFilterMapper3(iface
);
244 return IUnknown_AddRef(This
->outer_unk
);
247 static ULONG WINAPI
FilterMapper3_Release(IFilterMapper3
* iface
)
249 FilterMapper3Impl
*This
= impl_from_IFilterMapper3(iface
);
251 return IUnknown_Release(This
->outer_unk
);
254 /*** IFilterMapper3 methods ***/
256 static HRESULT WINAPI
FilterMapper3_CreateCategory(
257 IFilterMapper3
* iface
,
258 REFCLSID clsidCategory
,
259 DWORD dwCategoryMerit
,
260 LPCWSTR szDescription
)
262 LPWSTR wClsidAMCat
= NULL
;
263 LPWSTR wClsidCategory
= NULL
;
264 WCHAR wszKeyName
[ARRAY_SIZE(wszClsidSlash
)-1 + ARRAY_SIZE(wszSlashInstance
)-1 + (CHARS_IN_GUID
-1) * 2 + 1];
269 TRACE("(%s, %x, %s)\n", debugstr_guid(clsidCategory
), dwCategoryMerit
, debugstr_w(szDescription
));
271 hr
= StringFromCLSID(&CLSID_ActiveMovieCategories
, &wClsidAMCat
);
275 hr
= StringFromCLSID(clsidCategory
, &wClsidCategory
);
280 lstrcpyW(wszKeyName
, wszClsidSlash
);
281 lstrcatW(wszKeyName
, wClsidAMCat
);
282 lstrcatW(wszKeyName
, wszSlashInstance
);
283 lstrcatW(wszKeyName
, wClsidCategory
);
285 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
286 hr
= HRESULT_FROM_WIN32(lRet
);
291 lRet
= RegSetValueExW(hKey
, wszFriendlyName
, 0, REG_SZ
, (const BYTE
*)szDescription
, (lstrlenW(szDescription
) + 1) * sizeof(WCHAR
));
292 hr
= HRESULT_FROM_WIN32(lRet
);
297 lRet
= RegSetValueExW(hKey
, wszClsidName
, 0, REG_SZ
, (LPBYTE
)wClsidCategory
, (lstrlenW(wClsidCategory
) + 1) * sizeof(WCHAR
));
298 hr
= HRESULT_FROM_WIN32(lRet
);
303 lRet
= RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwCategoryMerit
, sizeof(dwCategoryMerit
));
304 hr
= HRESULT_FROM_WIN32(lRet
);
308 CoTaskMemFree(wClsidCategory
);
309 CoTaskMemFree(wClsidAMCat
);
314 static HRESULT WINAPI
FilterMapper3_UnregisterFilter(
315 IFilterMapper3
* iface
,
316 const CLSID
*pclsidCategory
,
317 const OLECHAR
*szInstance
,
320 WCHAR wszKeyName
[MAX_PATH
];
321 LPWSTR wClsidCategory
= NULL
;
322 LPWSTR wFilter
= NULL
;
325 TRACE("(%p, %s, %s)\n", pclsidCategory
, debugstr_w(szInstance
), debugstr_guid(Filter
));
328 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
330 hr
= StringFromCLSID(pclsidCategory
, &wClsidCategory
);
334 lstrcpyW(wszKeyName
, wszClsidSlash
);
335 lstrcatW(wszKeyName
, wClsidCategory
);
336 lstrcatW(wszKeyName
, wszSlashInstance
);
338 lstrcatW(wszKeyName
, szInstance
);
341 hr
= StringFromCLSID(Filter
, &wFilter
);
343 lstrcatW(wszKeyName
, wFilter
);
349 LONG lRet
= RegDeleteKeyW(HKEY_CLASSES_ROOT
, wszKeyName
);
350 hr
= HRESULT_FROM_WIN32(lRet
);
353 CoTaskMemFree(wClsidCategory
);
354 CoTaskMemFree(wFilter
);
359 static HRESULT
FM2_WriteFriendlyName(IPropertyBag
* pPropBag
, LPCWSTR szName
)
365 V_VT(&var
) = VT_BSTR
;
366 V_BSTR(&var
) = value
= SysAllocString(szName
);
368 ret
= IPropertyBag_Write(pPropBag
, wszFriendlyName
, &var
);
369 SysFreeString(value
);
374 static HRESULT
FM2_WriteClsid(IPropertyBag
* pPropBag
, REFCLSID clsid
)
376 LPWSTR wszClsid
= NULL
;
380 hr
= StringFromCLSID(clsid
, &wszClsid
);
384 V_VT(&var
) = VT_BSTR
;
385 V_BSTR(&var
) = wszClsid
;
386 hr
= IPropertyBag_Write(pPropBag
, wszClsidName
, &var
);
388 CoTaskMemFree(wszClsid
);
392 static HRESULT
FM2_WriteFilterData(const REGFILTER2
* prf2
, BYTE
**ppData
, ULONG
*pcbData
)
394 int size
= sizeof(struct REG_RF
);
396 struct Vector mainStore
= {NULL
, 0, 0};
397 struct Vector clsidStore
= {NULL
, 0, 0};
401 rrf
.dwVersion
= prf2
->dwVersion
;
402 rrf
.dwMerit
= prf2
->dwMerit
;
403 rrf
.dwPins
= prf2
->u
.s2
.cPins2
;
406 add_data(&mainStore
, &rrf
, sizeof(rrf
));
408 for (i
= 0; i
< prf2
->u
.s2
.cPins2
; i
++)
410 size
+= sizeof(struct REG_RFP
);
411 if (prf2
->u
.s2
.rgPins2
[i
].clsPinCategory
)
412 size
+= sizeof(DWORD
);
413 size
+= prf2
->u
.s2
.rgPins2
[i
].nMediaTypes
* sizeof(struct REG_TYPE
);
414 size
+= prf2
->u
.s2
.rgPins2
[i
].nMediums
* sizeof(DWORD
);
417 for (i
= 0; i
< prf2
->u
.s2
.cPins2
; i
++)
420 REGFILTERPINS2 rgPin2
= prf2
->u
.s2
.rgPins2
[i
];
423 rrfp
.signature
[0] = '0';
424 rrfp
.signature
[1] = 'p';
425 rrfp
.signature
[2] = 'i';
426 rrfp
.signature
[3] = '3';
427 rrfp
.signature
[0] += i
;
428 rrfp
.dwFlags
= rgPin2
.dwFlags
;
429 rrfp
.dwInstances
= rgPin2
.cInstances
;
430 rrfp
.dwMediaTypes
= rgPin2
.nMediaTypes
;
431 rrfp
.dwMediums
= rgPin2
.nMediums
;
432 rrfp
.bCategory
= rgPin2
.clsPinCategory
? 1 : 0;
434 add_data(&mainStore
, &rrfp
, sizeof(rrfp
));
437 DWORD index
= find_data(&clsidStore
, rgPin2
.clsPinCategory
, sizeof(CLSID
));
439 index
= add_data(&clsidStore
, rgPin2
.clsPinCategory
, sizeof(CLSID
));
442 add_data(&mainStore
, &index
, sizeof(index
));
445 for (j
= 0; j
< rgPin2
.nMediaTypes
; j
++)
448 const CLSID
* clsMinorType
= rgPin2
.lpMediaType
[j
].clsMinorType
? rgPin2
.lpMediaType
[j
].clsMinorType
: &MEDIASUBTYPE_NULL
;
449 rt
.signature
[0] = '0';
450 rt
.signature
[1] = 't';
451 rt
.signature
[2] = 'y';
452 rt
.signature
[3] = '3';
453 rt
.signature
[0] += j
;
455 rt
.dwOffsetMajor
= find_data(&clsidStore
, rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
456 if (rt
.dwOffsetMajor
== -1)
457 rt
.dwOffsetMajor
= add_data(&clsidStore
, rgPin2
.lpMediaType
[j
].clsMajorType
, sizeof(CLSID
));
458 rt
.dwOffsetMajor
+= size
;
459 rt
.dwOffsetMinor
= find_data(&clsidStore
, clsMinorType
, sizeof(CLSID
));
460 if (rt
.dwOffsetMinor
== -1)
461 rt
.dwOffsetMinor
= add_data(&clsidStore
, clsMinorType
, sizeof(CLSID
));
462 rt
.dwOffsetMinor
+= size
;
464 add_data(&mainStore
, &rt
, sizeof(rt
));
467 for (j
= 0; j
< rgPin2
.nMediums
; j
++)
469 DWORD index
= find_data(&clsidStore
, rgPin2
.lpMedium
+ j
, sizeof(REGPINMEDIUM
));
471 index
= add_data(&clsidStore
, rgPin2
.lpMedium
+ j
, sizeof(REGPINMEDIUM
));
474 add_data(&mainStore
, &index
, sizeof(index
));
480 *pcbData
= mainStore
.current
+ clsidStore
.current
;
481 *ppData
= CoTaskMemAlloc(*pcbData
);
488 memcpy(*ppData
, mainStore
.pData
, mainStore
.current
);
489 memcpy((*ppData
) + mainStore
.current
, clsidStore
.pData
, clsidStore
.current
);
492 delete_vector(&mainStore
);
493 delete_vector(&clsidStore
);
497 static HRESULT
FM2_ReadFilterData(BYTE
*pData
, REGFILTER2
* prf2
)
500 struct REG_RF
* prrf
;
503 REGFILTERPINS2
* rgPins2
;
505 prrf
= (struct REG_RF
*)pData
;
508 if (prrf
->dwVersion
!= 2)
510 FIXME("Filter registry version %d not supported\n", prrf
->dwVersion
);
511 ZeroMemory(prf2
, sizeof(*prf2
));
517 TRACE("version = %d, merit = %x, #pins = %d, unused = %x\n",
518 prrf
->dwVersion
, prrf
->dwMerit
, prrf
->dwPins
, prrf
->dwUnused
);
520 prf2
->dwVersion
= prrf
->dwVersion
;
521 prf2
->dwMerit
= prrf
->dwMerit
;
522 prf2
->u
.s2
.cPins2
= prrf
->dwPins
;
523 rgPins2
= CoTaskMemAlloc(prrf
->dwPins
* sizeof(*rgPins2
));
524 prf2
->u
.s2
.rgPins2
= rgPins2
;
525 pCurrent
+= sizeof(struct REG_RF
);
527 for (i
= 0; i
< prrf
->dwPins
; i
++)
529 struct REG_RFP
* prrfp
= (struct REG_RFP
*)pCurrent
;
530 REGPINTYPES
* lpMediaType
;
531 REGPINMEDIUM
* lpMedium
;
534 /* FIXME: check signature */
536 TRACE("\tsignature = %s\n", debugstr_an((const char*)prrfp
->signature
, 4));
538 TRACE("\tpin[%d]: flags = %x, instances = %d, media types = %d, mediums = %d\n",
539 i
, prrfp
->dwFlags
, prrfp
->dwInstances
, prrfp
->dwMediaTypes
, prrfp
->dwMediums
);
541 rgPins2
[i
].dwFlags
= prrfp
->dwFlags
;
542 rgPins2
[i
].cInstances
= prrfp
->dwInstances
;
543 rgPins2
[i
].nMediaTypes
= prrfp
->dwMediaTypes
;
544 rgPins2
[i
].nMediums
= prrfp
->dwMediums
;
545 pCurrent
+= sizeof(struct REG_RFP
);
546 if (prrfp
->bCategory
)
548 CLSID
* clsCat
= CoTaskMemAlloc(sizeof(CLSID
));
549 memcpy(clsCat
, pData
+ *(DWORD
*)(pCurrent
), sizeof(CLSID
));
550 pCurrent
+= sizeof(DWORD
);
551 rgPins2
[i
].clsPinCategory
= clsCat
;
554 rgPins2
[i
].clsPinCategory
= NULL
;
556 if (rgPins2
[i
].nMediaTypes
> 0)
557 lpMediaType
= CoTaskMemAlloc(rgPins2
[i
].nMediaTypes
* sizeof(*lpMediaType
));
561 rgPins2
[i
].lpMediaType
= lpMediaType
;
563 for (j
= 0; j
< rgPins2
[i
].nMediaTypes
; j
++)
565 struct REG_TYPE
* prt
= (struct REG_TYPE
*)pCurrent
;
566 CLSID
* clsMajor
= CoTaskMemAlloc(sizeof(CLSID
));
567 CLSID
* clsMinor
= CoTaskMemAlloc(sizeof(CLSID
));
569 /* FIXME: check signature */
570 TRACE("\t\tsignature = %s\n", debugstr_an((const char*)prt
->signature
, 4));
572 memcpy(clsMajor
, pData
+ prt
->dwOffsetMajor
, sizeof(CLSID
));
573 memcpy(clsMinor
, pData
+ prt
->dwOffsetMinor
, sizeof(CLSID
));
575 lpMediaType
[j
].clsMajorType
= clsMajor
;
576 lpMediaType
[j
].clsMinorType
= clsMinor
;
578 pCurrent
+= sizeof(*prt
);
581 if (rgPins2
[i
].nMediums
> 0)
582 lpMedium
= CoTaskMemAlloc(rgPins2
[i
].nMediums
* sizeof(*lpMedium
));
586 rgPins2
[i
].lpMedium
= lpMedium
;
588 for (j
= 0; j
< rgPins2
[i
].nMediums
; j
++)
590 DWORD dwOffset
= *(DWORD
*)pCurrent
;
592 memcpy(lpMedium
+ j
, pData
+ dwOffset
, sizeof(REGPINMEDIUM
));
594 pCurrent
+= sizeof(dwOffset
);
603 static void FM2_DeleteRegFilter(REGFILTER2
* prf2
)
606 for (i
= 0; i
< prf2
->u
.s2
.cPins2
; i
++)
609 CoTaskMemFree((void*)prf2
->u
.s2
.rgPins2
[i
].clsPinCategory
);
611 for (j
= 0; j
< prf2
->u
.s2
.rgPins2
[i
].nMediaTypes
; j
++)
613 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
[j
].clsMajorType
);
614 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
[j
].clsMinorType
);
616 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMediaType
);
617 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
[i
].lpMedium
);
619 CoTaskMemFree((LPVOID
)prf2
->u
.s2
.rgPins2
);
622 static HRESULT WINAPI
FilterMapper3_RegisterFilter(
623 IFilterMapper3
* iface
,
624 REFCLSID clsidFilter
,
626 IMoniker
**ppMoniker
,
627 const CLSID
*pclsidCategory
,
628 const OLECHAR
*szInstance
,
629 const REGFILTER2
*prf2
)
631 IParseDisplayName
* pParser
= NULL
;
632 IBindCtx
* pBindCtx
= NULL
;
633 IMoniker
* pMoniker
= NULL
;
634 IPropertyBag
* pPropBag
= NULL
;
636 LPWSTR pwszParseName
= NULL
;
638 static const WCHAR wszDevice
[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
641 LPWSTR szClsidTemp
= NULL
;
642 REGFILTER2 regfilter2
;
643 REGFILTERPINS2
* pregfp2
= NULL
;
645 TRACE("(%s, %s, %p, %s, %s, %p)\n",
646 debugstr_guid(clsidFilter
),
649 debugstr_guid(pclsidCategory
),
650 debugstr_w(szInstance
),
653 if (prf2
->dwVersion
== 2)
657 else if (prf2
->dwVersion
== 1)
661 /* REGFILTER2 structure is converted from version 1 to 2. Tested on Win2k. */
662 regfilter2
.dwVersion
= 2;
663 regfilter2
.dwMerit
= prf2
->dwMerit
;
664 regfilter2
.u
.s2
.cPins2
= prf2
->u
.s1
.cPins
;
665 pregfp2
= CoTaskMemAlloc(prf2
->u
.s1
.cPins
* sizeof(REGFILTERPINS2
));
666 regfilter2
.u
.s2
.rgPins2
= pregfp2
;
667 for (i
= 0; i
< prf2
->u
.s1
.cPins
; i
++)
670 if (prf2
->u
.s1
.rgPins
[i
].bRendered
)
671 flags
|= REG_PINFLAG_B_RENDERER
;
672 if (prf2
->u
.s1
.rgPins
[i
].bOutput
)
673 flags
|= REG_PINFLAG_B_OUTPUT
;
674 if (prf2
->u
.s1
.rgPins
[i
].bZero
)
675 flags
|= REG_PINFLAG_B_ZERO
;
676 if (prf2
->u
.s1
.rgPins
[i
].bMany
)
677 flags
|= REG_PINFLAG_B_MANY
;
678 pregfp2
[i
].dwFlags
= flags
;
679 pregfp2
[i
].cInstances
= 1;
680 pregfp2
[i
].nMediaTypes
= prf2
->u
.s1
.rgPins
[i
].nMediaTypes
;
681 pregfp2
[i
].lpMediaType
= prf2
->u
.s1
.rgPins
[i
].lpMediaType
;
682 pregfp2
[i
].nMediums
= 0;
683 pregfp2
[i
].lpMedium
= NULL
;
684 pregfp2
[i
].clsPinCategory
= NULL
;
689 FIXME("dwVersion other that 1 or 2 not supported at the moment\n");
697 /* MSDN mentions the inexistent CLSID_ActiveMovieFilters GUID.
698 * In fact this is the CLSID_LegacyAmFilterCategory one */
699 pclsidCategory
= &CLSID_LegacyAmFilterCategory
;
701 /* sizeof... will include the null terminator and
702 * the + 1 is for the separator ('\\'). The -1 is
703 * because CHARS_IN_GUID includes the null terminator
705 nameLen
= ARRAY_SIZE(wszDevice
) + CHARS_IN_GUID
- 1 + 1;
708 nameLen
+= lstrlenW(szInstance
);
710 nameLen
+= CHARS_IN_GUID
- 1; /* CHARS_IN_GUID includes null terminator */
712 pCurrent
= pwszParseName
= CoTaskMemAlloc(nameLen
*sizeof(WCHAR
));
714 return E_OUTOFMEMORY
;
716 lstrcpyW(pwszParseName
, wszDevice
);
717 pCurrent
+= lstrlenW(wszDevice
);
719 hr
= StringFromCLSID(pclsidCategory
, &szClsidTemp
);
723 memcpy(pCurrent
, szClsidTemp
, CHARS_IN_GUID
* sizeof(WCHAR
));
724 pCurrent
+= CHARS_IN_GUID
- 1;
728 lstrcpyW(pCurrent
+1, szInstance
);
731 CoTaskMemFree(szClsidTemp
);
734 hr
= StringFromCLSID(clsidFilter
, &szClsidTemp
);
736 lstrcpyW(pCurrent
+1, szClsidTemp
);
741 hr
= CoCreateInstance(&CLSID_CDeviceMoniker
, NULL
, CLSCTX_INPROC
, &IID_IParseDisplayName
, (LPVOID
*)&pParser
);
744 hr
= CreateBindCtx(0, &pBindCtx
);
747 hr
= IParseDisplayName_ParseDisplayName(pParser
, pBindCtx
, pwszParseName
, &ulEaten
, &pMoniker
);
750 IBindCtx_Release(pBindCtx
);
752 IParseDisplayName_Release(pParser
);
755 hr
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
)&pPropBag
);
758 hr
= FM2_WriteFriendlyName(pPropBag
, szName
);
761 hr
= FM2_WriteClsid(pPropBag
, clsidFilter
);
768 hr
= FM2_WriteFilterData(®filter2
, &pData
, &cbData
);
773 SAFEARRAYBOUND saBound
;
776 saBound
.cElements
= cbData
;
777 psa
= SafeArrayCreate(VT_UI1
, 1, &saBound
);
780 ERR("Couldn't create SAFEARRAY\n");
787 hr
= SafeArrayAccessData(psa
, (LPVOID
*)&pbSAData
);
790 memcpy(pbSAData
, pData
, cbData
);
791 hr
= SafeArrayUnaccessData(psa
);
795 V_VT(&var
) = VT_ARRAY
| VT_UI1
;
799 hr
= IPropertyBag_Write(pPropBag
, wszFilterDataName
, &var
);
802 SafeArrayDestroy(psa
);
803 CoTaskMemFree(pData
);
808 IPropertyBag_Release(pPropBag
);
809 CoTaskMemFree(szClsidTemp
);
810 CoTaskMemFree(pwszParseName
);
812 if (SUCCEEDED(hr
) && ppMoniker
)
813 *ppMoniker
= pMoniker
;
815 IMoniker_Release(pMoniker
);
817 CoTaskMemFree(pregfp2
);
819 TRACE("-- returning %x\n", hr
);
824 /* internal helper function */
825 static BOOL
MatchTypes(
828 const REGPINTYPES
* pPinTypes
,
830 const GUID
* pMatchTypes
)
835 if ((nMatchTypes
== 0) && (nPinTypes
> 0))
838 for (j
= 0; j
< nPinTypes
; j
++)
841 for (i
= 0; i
< nMatchTypes
*2; i
+=2)
843 if (((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMajorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMajorType
, &pMatchTypes
[i
])) &&
844 ((!bExactMatch
&& IsEqualGUID(pPinTypes
[j
].clsMinorType
, &GUID_NULL
)) || IsEqualGUID(&pMatchTypes
[i
+1], &GUID_NULL
) || IsEqualGUID(pPinTypes
[j
].clsMinorType
, &pMatchTypes
[i
+1])))
854 /* internal helper function for qsort of MONIKER_MERIT array */
855 static int __cdecl
mm_compare(const void * left
, const void * right
)
857 const struct MONIKER_MERIT
* mmLeft
= left
;
858 const struct MONIKER_MERIT
* mmRight
= right
;
860 if (mmLeft
->dwMerit
== mmRight
->dwMerit
)
862 if (mmLeft
->dwMerit
> mmRight
->dwMerit
)
868 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
869 * (GUID_NULL's in input to function automatically treated as wild cards)
870 * Input/Output needed means match only on criteria if TRUE (with zero input types
871 * meaning match any input/output pin as long as one exists), otherwise match any
872 * filter that meets the rest of the requirements.
874 static HRESULT WINAPI
FilterMapper3_EnumMatchingFilters(
875 IFilterMapper3
* iface
,
876 IEnumMoniker
**ppEnum
,
882 const GUID
*pInputTypes
,
883 const REGPINMEDIUM
*pMedIn
,
884 const CLSID
*pPinCategoryIn
,
888 const GUID
*pOutputTypes
,
889 const REGPINMEDIUM
*pMedOut
,
890 const CLSID
*pPinCategoryOut
)
892 ICreateDevEnum
* pCreateDevEnum
;
893 IMoniker
* pMonikerCat
;
894 IEnumMoniker
* pEnumCat
;
896 struct Vector monikers
= {NULL
, 0, 0};
898 TRACE("(%p, %x, %s, %x, %s, %d, %p, %p, %p, %s, %s, %p, %p, %p)\n",
901 bExactMatch
? "true" : "false",
903 bInputNeeded
? "true" : "false",
908 bRender
? "true" : "false",
909 bOutputNeeded
? "true" : "false",
916 FIXME("dwFlags = %x not implemented\n", dwFlags
);
921 hr
= CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (LPVOID
*)&pCreateDevEnum
);
925 hr
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &CLSID_ActiveMovieCategories
, &pEnumCat
, 0);
927 ICreateDevEnum_Release(pCreateDevEnum
);
931 while (IEnumMoniker_Next(pEnumCat
, 1, &pMonikerCat
, NULL
) == S_OK
)
933 IPropertyBag
* pPropBagCat
= NULL
;
935 HRESULT hrSub
; /* this is so that one buggy filter
936 doesn't make the whole lot fail */
940 hrSub
= IMoniker_BindToStorage(pMonikerCat
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
942 if (SUCCEEDED(hrSub
))
943 hrSub
= IPropertyBag_Read(pPropBagCat
, wszMeritName
, &var
, NULL
);
945 if (SUCCEEDED(hrSub
) && (V_UI4(&var
) >= dwMerit
))
948 IEnumMoniker
* pEnum
;
953 if (TRACE_ON(quartz
))
956 V_VT(&temp
) = VT_EMPTY
;
957 IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &temp
, NULL
);
958 TRACE("Considering category %s\n", debugstr_w(V_BSTR(&temp
)));
962 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
964 if (SUCCEEDED(hrSub
))
965 hrSub
= CLSIDFromString(V_BSTR(&var
), &clsidCat
);
967 if (SUCCEEDED(hrSub
))
968 hrSub
= ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum
, &clsidCat
, &pEnum
, 0);
972 while (IEnumMoniker_Next(pEnum
, 1, &pMoniker
, NULL
) == S_OK
)
974 IPropertyBag
* pPropBag
= NULL
;
979 BOOL bInputMatch
= !bInputNeeded
;
980 BOOL bOutputMatch
= !bOutputNeeded
;
982 ZeroMemory(&rf2
, sizeof(rf2
));
985 hrSub
= IMoniker_BindToStorage(pMoniker
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBag
);
987 if (TRACE_ON(quartz
))
990 V_VT(&temp
) = VT_EMPTY
;
991 IPropertyBag_Read(pPropBag
, wszFriendlyName
, &temp
, NULL
);
992 TRACE("Considering filter %s\n", debugstr_w(V_BSTR(&temp
)));
996 if (SUCCEEDED(hrSub
))
998 hrSub
= IPropertyBag_Read(pPropBag
, wszFilterDataName
, &var
, NULL
);
1001 if (SUCCEEDED(hrSub
))
1002 hrSub
= SafeArrayAccessData(V_ARRAY(&var
), (LPVOID
*)&pData
);
1004 if (SUCCEEDED(hrSub
))
1005 hrSub
= FM2_ReadFilterData(pData
, &rf2
);
1008 SafeArrayUnaccessData(V_ARRAY(&var
));
1012 /* Logic used for bInputMatch expression:
1013 * There exists some pin such that bInputNeeded implies (pin is an input and
1014 * (bRender implies pin has render flag) and major/minor types members of
1016 * bOutputMatch is similar, but without the "bRender implies ..." part
1017 * and substituting variables names containing input for output
1020 /* determine whether filter meets requirements */
1021 if (SUCCEEDED(hrSub
) && (rf2
.dwMerit
>= dwMerit
))
1023 for (i
= 0; (i
< rf2
.u
.s2
.cPins2
) && (!bInputMatch
|| !bOutputMatch
); i
++)
1025 const REGFILTERPINS2
* rfp2
= rf2
.u
.s2
.rgPins2
+ i
;
1027 bInputMatch
= bInputMatch
|| (!(rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1028 (!bRender
|| (rfp2
->dwFlags
& REG_PINFLAG_B_RENDERER
)) &&
1029 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cInputTypes
, pInputTypes
));
1030 bOutputMatch
= bOutputMatch
|| ((rfp2
->dwFlags
& REG_PINFLAG_B_OUTPUT
) &&
1031 MatchTypes(bExactMatch
, rfp2
->nMediaTypes
, rfp2
->lpMediaType
, cOutputTypes
, pOutputTypes
));
1034 if (bInputMatch
&& bOutputMatch
)
1036 struct MONIKER_MERIT mm
= {pMoniker
, rf2
.dwMerit
};
1037 IMoniker_AddRef(pMoniker
);
1038 add_data(&monikers
, &mm
, sizeof(mm
));
1042 FM2_DeleteRegFilter(&rf2
);
1044 IPropertyBag_Release(pPropBag
);
1045 IMoniker_Release(pMoniker
);
1047 IEnumMoniker_Release(pEnum
);
1053 IPropertyBag_Release(pPropBagCat
);
1054 IMoniker_Release(pMonikerCat
);
1059 IMoniker
** ppMoniker
;
1061 ULONG nMonikerCount
= monikers
.current
/ sizeof(struct MONIKER_MERIT
);
1063 /* sort the monikers in descending merit order */
1064 qsort(monikers
.pData
, nMonikerCount
,
1065 sizeof(struct MONIKER_MERIT
),
1068 /* construct an IEnumMoniker interface */
1069 ppMoniker
= CoTaskMemAlloc(nMonikerCount
* sizeof(IMoniker
*));
1070 for (i
= 0; i
< nMonikerCount
; i
++)
1072 /* no need to AddRef here as already AddRef'd above */
1073 ppMoniker
[i
] = ((struct MONIKER_MERIT
*)monikers
.pData
)[i
].pMoniker
;
1075 hr
= EnumMonikerImpl_Create(ppMoniker
, nMonikerCount
, ppEnum
);
1076 CoTaskMemFree(ppMoniker
);
1079 delete_vector(&monikers
);
1080 IEnumMoniker_Release(pEnumCat
);
1081 ICreateDevEnum_Release(pCreateDevEnum
);
1086 static HRESULT WINAPI
FilterMapper3_GetICreateDevEnum(IFilterMapper3
*iface
, ICreateDevEnum
**ppEnum
)
1088 TRACE("(%p, %p)\n", iface
, ppEnum
);
1091 return CoCreateInstance(&CLSID_SystemDeviceEnum
, NULL
, CLSCTX_INPROC
, &IID_ICreateDevEnum
, (void**)ppEnum
);
1094 static const IFilterMapper3Vtbl fm3vtbl
=
1097 FilterMapper3_QueryInterface
,
1098 FilterMapper3_AddRef
,
1099 FilterMapper3_Release
,
1101 FilterMapper3_CreateCategory
,
1102 FilterMapper3_UnregisterFilter
,
1103 FilterMapper3_RegisterFilter
,
1104 FilterMapper3_EnumMatchingFilters
,
1105 FilterMapper3_GetICreateDevEnum
1108 /*** IUnknown methods ***/
1110 static HRESULT WINAPI
FilterMapper_QueryInterface(IFilterMapper
* iface
, REFIID riid
, LPVOID
*ppv
)
1112 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1114 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
1116 return FilterMapper3_QueryInterface(&This
->IFilterMapper3_iface
, riid
, ppv
);
1119 static ULONG WINAPI
FilterMapper_AddRef(IFilterMapper
* iface
)
1121 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1123 return IUnknown_AddRef(This
->outer_unk
);
1126 static ULONG WINAPI
FilterMapper_Release(IFilterMapper
* iface
)
1128 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1130 return IUnknown_Release(This
->outer_unk
);
1133 /*** IFilterMapper methods ***/
1135 static HRESULT WINAPI
FilterMapper_EnumMatchingFilters(
1136 IFilterMapper
* iface
,
1137 IEnumRegFilters
**ppEnum
,
1147 FilterMapper3Impl
*This
= impl_from_IFilterMapper(iface
);
1150 IEnumMoniker
* ppEnumMoniker
;
1153 ULONG idx
= 0, nb_mon
= 0;
1154 REGFILTER
* regfilters
;
1157 TRACE("(%p/%p)->(%p, %x, %s, %s, %s, %s, %s, %s, %s)\n",
1162 bInputNeeded
? "true" : "false",
1163 debugstr_guid(&clsInMaj
),
1164 debugstr_guid(&clsInSub
),
1165 bRender
? "true" : "false",
1166 bOutputNeeded
? "true" : "false",
1167 debugstr_guid(&clsOutMaj
),
1168 debugstr_guid(&clsOutSub
));
1170 InputType
[0] = clsInMaj
;
1171 InputType
[1] = clsInSub
;
1172 OutputType
[0] = clsOutMaj
;
1173 OutputType
[1] = clsOutSub
;
1177 hr
= IFilterMapper3_EnumMatchingFilters(&This
->IFilterMapper3_iface
, &ppEnumMoniker
, 0, TRUE
,
1178 dwMerit
, bInputNeeded
, 1, InputType
, NULL
, &GUID_NULL
, bRender
, bOutputNeeded
, 1,
1179 OutputType
, NULL
, &GUID_NULL
);
1184 while(IEnumMoniker_Next(ppEnumMoniker
, 1, &IMon
, &nb
) == S_OK
)
1186 IMoniker_Release(IMon
);
1192 IEnumMoniker_Release(ppEnumMoniker
);
1193 return IEnumRegFiltersImpl_Construct(NULL
, 0, ppEnum
);
1196 regfilters
= CoTaskMemAlloc(nb_mon
* sizeof(REGFILTER
));
1199 IEnumMoniker_Release(ppEnumMoniker
);
1200 return E_OUTOFMEMORY
;
1202 ZeroMemory(regfilters
, nb_mon
* sizeof(REGFILTER
)); /* will prevent bad free of Name in case of error. */
1204 IEnumMoniker_Reset(ppEnumMoniker
);
1205 while(IEnumMoniker_Next(ppEnumMoniker
, 1, &IMon
, &nb
) == S_OK
)
1207 IPropertyBag
* pPropBagCat
= NULL
;
1215 hrSub
= IMoniker_BindToStorage(IMon
, NULL
, NULL
, &IID_IPropertyBag
, (LPVOID
*)&pPropBagCat
);
1217 if (SUCCEEDED(hrSub
))
1218 hrSub
= IPropertyBag_Read(pPropBagCat
, wszClsidName
, &var
, NULL
);
1220 if (SUCCEEDED(hrSub
))
1221 hrSub
= CLSIDFromString(V_BSTR(&var
), &clsid
);
1225 if (SUCCEEDED(hrSub
))
1226 hrSub
= IPropertyBag_Read(pPropBagCat
, wszFriendlyName
, &var
, NULL
);
1228 if (SUCCEEDED(hrSub
))
1230 len
= (lstrlenW(V_BSTR(&var
))+1) * sizeof(WCHAR
);
1231 if (!(regfilters
[idx
].Name
= CoTaskMemAlloc(len
*2)))
1235 if (SUCCEEDED(hrSub
) && regfilters
[idx
].Name
)
1237 memcpy(regfilters
[idx
].Name
, V_BSTR(&var
), len
);
1238 regfilters
[idx
].Clsid
= clsid
;
1243 IPropertyBag_Release(pPropBagCat
);
1244 IMoniker_Release(IMon
);
1250 hr
= IEnumRegFiltersImpl_Construct(regfilters
, nb_mon
, ppEnum
);
1253 for (idx
= 0; idx
< nb_mon
; idx
++)
1254 CoTaskMemFree(regfilters
[idx
].Name
);
1255 CoTaskMemFree(regfilters
);
1256 IEnumMoniker_Release(ppEnumMoniker
);
1262 static HRESULT WINAPI
FilterMapper_RegisterFilter(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, DWORD dwMerit
)
1265 LPWSTR wszClsid
= NULL
;
1268 WCHAR wszKeyName
[ARRAY_SIZE(wszFilterSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1270 TRACE("(%p)->(%s, %s, %x)\n", iface
, debugstr_guid(&clsid
), debugstr_w(szName
), dwMerit
);
1272 hr
= StringFromCLSID(&clsid
, &wszClsid
);
1276 lstrcpyW(wszKeyName
, wszFilterSlash
);
1277 lstrcatW(wszKeyName
, wszClsid
);
1279 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
1280 hr
= HRESULT_FROM_WIN32(lRet
);
1285 lRet
= RegSetValueExW(hKey
, NULL
, 0, REG_SZ
, (const BYTE
*)szName
, (lstrlenW(szName
) + 1) * sizeof(WCHAR
));
1286 hr
= HRESULT_FROM_WIN32(lRet
);
1292 lstrcpyW(wszKeyName
, wszClsidSlash
);
1293 lstrcatW(wszKeyName
, wszClsid
);
1295 lRet
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKey
, NULL
);
1296 hr
= HRESULT_FROM_WIN32(lRet
);
1301 lRet
= RegSetValueExW(hKey
, wszMeritName
, 0, REG_DWORD
, (LPBYTE
)&dwMerit
, sizeof(dwMerit
));
1302 hr
= HRESULT_FROM_WIN32(lRet
);
1306 CoTaskMemFree(wszClsid
);
1311 static HRESULT WINAPI
FilterMapper_RegisterFilterInstance(IFilterMapper
* iface
, CLSID clsid
, LPCWSTR szName
, CLSID
*MRId
)
1313 TRACE("(%p)->(%s, %s, %p)\n", iface
, debugstr_guid(&clsid
), debugstr_w(szName
), MRId
);
1315 /* Not implemented in Windows (tested on Win2k) */
1320 static HRESULT WINAPI
FilterMapper_RegisterPin(
1321 IFilterMapper
* iface
,
1328 CLSID ConnectsToFilter
,
1329 LPCWSTR ConnectsToPin
)
1333 LPWSTR wszClsid
= NULL
;
1335 HKEY hPinsKey
= NULL
;
1336 WCHAR
* wszPinsKeyName
;
1337 WCHAR wszKeyName
[ARRAY_SIZE(wszClsidSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1339 TRACE("(%p)->(%s, %s, %d, %d, %d, %d, %s, %s)\n", iface
, debugstr_guid(&Filter
), debugstr_w(szName
), bRendered
,
1340 bOutput
, bZero
, bMany
, debugstr_guid(&ConnectsToFilter
), debugstr_w(ConnectsToPin
));
1342 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1346 lstrcpyW(wszKeyName
, wszClsidSlash
);
1347 lstrcatW(wszKeyName
, wszClsid
);
1349 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1350 hr
= HRESULT_FROM_WIN32(lRet
);
1355 wszPinsKeyName
= CoTaskMemAlloc((lstrlenW(wszPins
) + 1 + lstrlenW(szName
) + 1) * 2);
1356 if (!wszPinsKeyName
)
1362 lstrcpyW(wszPinsKeyName
, wszPins
);
1363 lstrcatW(wszPinsKeyName
, wszSlash
);
1364 lstrcatW(wszPinsKeyName
, szName
);
1366 lRet
= RegCreateKeyExW(hKey
, wszPinsKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hPinsKey
, NULL
);
1367 hr
= HRESULT_FROM_WIN32(lRet
);
1368 CoTaskMemFree(wszPinsKeyName
);
1373 lRet
= RegSetValueExW(hPinsKey
, wszAllowedMany
, 0, REG_DWORD
, (LPBYTE
)&bMany
, sizeof(bMany
));
1374 hr
= HRESULT_FROM_WIN32(lRet
);
1379 lRet
= RegSetValueExW(hPinsKey
, wszAllowedZero
, 0, REG_DWORD
, (LPBYTE
)&bZero
, sizeof(bZero
));
1380 hr
= HRESULT_FROM_WIN32(lRet
);
1385 lRet
= RegSetValueExW(hPinsKey
, wszDirection
, 0, REG_DWORD
, (LPBYTE
)&bOutput
, sizeof(bOutput
));
1386 hr
= HRESULT_FROM_WIN32(lRet
);
1391 lRet
= RegSetValueExW(hPinsKey
, wszIsRendered
, 0, REG_DWORD
, (LPBYTE
)&bRendered
, sizeof(bRendered
));
1392 hr
= HRESULT_FROM_WIN32(lRet
);
1397 HKEY hkeyDummy
= NULL
;
1399 lRet
= RegCreateKeyExW(hPinsKey
, wszTypes
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkeyDummy
, NULL
);
1400 hr
= HRESULT_FROM_WIN32(lRet
);
1402 if (hkeyDummy
) RegCloseKey(hkeyDummy
);
1405 CoTaskMemFree(wszClsid
);
1409 RegCloseKey(hPinsKey
);
1415 static HRESULT WINAPI
FilterMapper_RegisterPinType(
1416 IFilterMapper
* iface
,
1424 LPWSTR wszClsid
= NULL
;
1425 LPWSTR wszClsidMajorType
= NULL
;
1426 LPWSTR wszClsidSubType
= NULL
;
1428 WCHAR
* wszTypesKey
;
1429 WCHAR wszKeyName
[MAX_PATH
];
1431 TRACE("(%p)->(%s, %s, %s, %s)\n", iface
, debugstr_guid(&clsFilter
), debugstr_w(szName
),
1432 debugstr_guid(&clsMajorType
), debugstr_guid(&clsSubType
));
1434 hr
= StringFromCLSID(&clsFilter
, &wszClsid
);
1438 hr
= StringFromCLSID(&clsMajorType
, &wszClsidMajorType
);
1443 hr
= StringFromCLSID(&clsSubType
, &wszClsidSubType
);
1448 wszTypesKey
= CoTaskMemAlloc((lstrlenW(wszClsidSlash
) + lstrlenW(wszClsid
) + lstrlenW(wszPins
) +
1449 lstrlenW(szName
) + lstrlenW(wszTypes
) + 3 + 1) * 2);
1456 lstrcpyW(wszTypesKey
, wszClsidSlash
);
1457 lstrcatW(wszTypesKey
, wszClsid
);
1458 lstrcatW(wszTypesKey
, wszSlash
);
1459 lstrcatW(wszTypesKey
, wszPins
);
1460 lstrcatW(wszTypesKey
, wszSlash
);
1461 lstrcatW(wszTypesKey
, szName
);
1462 lstrcatW(wszTypesKey
, wszSlash
);
1463 lstrcatW(wszTypesKey
, wszTypes
);
1465 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszTypesKey
, 0, KEY_WRITE
, &hKey
);
1466 hr
= HRESULT_FROM_WIN32(lRet
);
1467 CoTaskMemFree(wszTypesKey
);
1472 HKEY hkeyDummy
= NULL
;
1474 lstrcpyW(wszKeyName
, wszClsidMajorType
);
1475 lstrcatW(wszKeyName
, wszSlash
);
1476 lstrcatW(wszKeyName
, wszClsidSubType
);
1478 lRet
= RegCreateKeyExW(hKey
, wszKeyName
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkeyDummy
, NULL
);
1479 hr
= HRESULT_FROM_WIN32(lRet
);
1482 if (hkeyDummy
) RegCloseKey(hkeyDummy
);
1485 CoTaskMemFree(wszClsid
);
1486 CoTaskMemFree(wszClsidMajorType
);
1487 CoTaskMemFree(wszClsidSubType
);
1492 static HRESULT WINAPI
FilterMapper_UnregisterFilter(IFilterMapper
* iface
, CLSID Filter
)
1496 LPWSTR wszClsid
= NULL
;
1498 WCHAR wszKeyName
[ARRAY_SIZE(wszClsidSlash
)-1 + (CHARS_IN_GUID
-1) + 1];
1500 TRACE("(%p)->(%s)\n", iface
, debugstr_guid(&Filter
));
1502 hr
= StringFromCLSID(&Filter
, &wszClsid
);
1506 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszFilter
, 0, KEY_WRITE
, &hKey
);
1507 hr
= HRESULT_FROM_WIN32(lRet
);
1512 lRet
= RegDeleteKeyW(hKey
, wszClsid
);
1513 hr
= HRESULT_FROM_WIN32(lRet
);
1519 lstrcpyW(wszKeyName
, wszClsidSlash
);
1520 lstrcatW(wszKeyName
, wszClsid
);
1522 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1523 if (lRet
== ERROR_FILE_NOT_FOUND
)
1525 hr
= HRESULT_FROM_WIN32(lRet
);
1530 lRet
= RegDeleteValueW(hKey
, wszMeritName
);
1531 if (lRet
!= ERROR_SUCCESS
&& lRet
!= ERROR_FILE_NOT_FOUND
)
1532 hr
= HRESULT_FROM_WIN32(lRet
);
1534 lRet
= RegDeleteTreeW(hKey
, wszPins
);
1535 if (lRet
!= ERROR_SUCCESS
&& lRet
!= ERROR_FILE_NOT_FOUND
)
1536 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
[ARRAY_SIZE(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 lstrcpyW(wszKeyName
, wszClsidSlash
);
1575 lstrcatW(wszKeyName
, wszClsid
);
1577 lRet
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszKeyName
, 0, KEY_WRITE
, &hKey
);
1578 hr
= HRESULT_FROM_WIN32(lRet
);
1583 wszPinNameKey
= CoTaskMemAlloc((lstrlenW(wszPins
) + 1 + lstrlenW(Name
) + 1) * 2);
1590 lstrcpyW(wszPinNameKey
, wszPins
);
1591 lstrcatW(wszPinNameKey
, wszSlash
);
1592 lstrcatW(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
;