windowscodecs: Add support for 32-bit TGA images.
[wine] / dlls / quartz / filtermapper.c
1 /*
2  * IFilterMapper & IFilterMapper2 Implementations
3  *
4  * Copyright 2003 Robert Shearman
5  * Copyright 2004 Christian Costa
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "winerror.h"
31
32 #include "quartz_private.h"
33
34 #include "ole2.h"
35 #include "olectl.h"
36 #include "strmif.h"
37 #include "wine/unicode.h"
38 #include "uuids.h"
39
40 #include "wine/debug.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
43
44 #define ARRAYSIZE(array) (sizeof(array)/sizeof((array)[0]))
45
46 /* Unexposed IAMFilterData interface */
47 typedef struct IAMFilterData IAMFilterData;
48
49 typedef struct IAMFilterDataVtbl
50 {
51     BEGIN_INTERFACE
52
53     /*** IUnknown methods ***/
54     HRESULT (STDMETHODCALLTYPE *QueryInterface)(
55         IAMFilterData *This,
56         REFIID riid,
57         void **ppvObject);
58
59     ULONG (STDMETHODCALLTYPE *AddRef)(
60         IAMFilterData *This);
61
62     ULONG (STDMETHODCALLTYPE *Release)(
63         IAMFilterData *This);
64
65     /*** IAMFilterData methods ***/
66     HRESULT (STDMETHODCALLTYPE *ParseFilterData)(
67         IAMFilterData *This,
68         BYTE *pData,
69         ULONG cb,
70         BYTE **ppRegFilter2);
71
72     HRESULT (STDMETHODCALLTYPE *CreateFilterData)(
73         IAMFilterData* This,
74         REGFILTER2 *prf2,
75         BYTE **pRegFilterData,
76         ULONG *pcb);
77
78     END_INTERFACE
79 } IAMFilterDataVtbl;
80 struct IAMFilterData
81 {
82     const IAMFilterDataVtbl *lpVtbl;
83 };
84 static const GUID IID_IAMFilterData = {
85  0x97f7c4d4, 0x547b, 0x4a5f, { 0x83,0x32, 0x53,0x64,0x30,0xad,0x2e,0x4d }
86 };
87
88
89 typedef struct FilterMapper2Impl
90 {
91     const IFilterMapper2Vtbl *lpVtbl;
92     const IFilterMapperVtbl  *lpVtblFilterMapper;
93     const IAMFilterDataVtbl  *lpVtblAMFilterData;
94     const IUnknownVtbl *IInner_vtbl;
95     LONG refCount;
96     IUnknown * pUnkOuter;
97     BOOL bUnkOuterValid;
98     BOOL bAggregatable;
99 } FilterMapper2Impl;
100
101 static const IUnknownVtbl IInner_VTable;
102 static const IFilterMapper2Vtbl fm2vtbl;
103 static const IFilterMapperVtbl fmvtbl;
104 static const IAMFilterDataVtbl AMFilterDataVtbl;
105
106 static inline FilterMapper2Impl *impl_from_IFilterMapper( IFilterMapper *iface )
107 {
108     return (FilterMapper2Impl *)((char*)iface - FIELD_OFFSET(FilterMapper2Impl, lpVtblFilterMapper));
109 }
110
111 static inline FilterMapper2Impl *impl_from_IAMFilterData( IAMFilterData *iface )
112 {
113     return (FilterMapper2Impl *)((char*)iface - FIELD_OFFSET(FilterMapper2Impl, lpVtblAMFilterData));
114 }
115
116 static inline FilterMapper2Impl *impl_from_inner_IUnknown( IUnknown *iface )
117 {
118     return (FilterMapper2Impl *)((char*)iface - FIELD_OFFSET(FilterMapper2Impl, IInner_vtbl));
119 }
120
121 static const WCHAR wszClsidSlash[] = {'C','L','S','I','D','\\',0};
122 static const WCHAR wszSlashInstance[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
123 static const WCHAR wszSlash[] = {'\\',0};
124
125 /* CLSID property in media category Moniker */
126 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
127 /* FriendlyName property in media category Moniker */
128 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
129 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
130 static const WCHAR wszMeritName[] = {'M','e','r','i','t',0};
131 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
132 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
133 /* For filters registered with IFilterMapper */
134 static const WCHAR wszFilterSlash[] = {'F','i','l','t','e','r','\\',0};
135 static const WCHAR wszFilter[] = {'F','i','l','t','e','r',0};
136 /* For pins registered with IFilterMapper */
137 static const WCHAR wszPins[] = {'P','i','n','s',0};
138 static const WCHAR wszAllowedMany[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
139 static const WCHAR wszAllowedZero[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
140 static const WCHAR wszDirection[] = {'D','i','r','e','c','t','i','o','n',0};
141 static const WCHAR wszIsRendered[] = {'I','s','R','e','n','d','e','r','e','d',0};
142 /* For types registered with IFilterMapper */
143 static const WCHAR wszTypes[] = {'T','y','p','e','s',0};
144
145
146 /* registry format for REGFILTER2 */
147 struct REG_RF
148 {
149     DWORD dwVersion;
150     DWORD dwMerit;
151     DWORD dwPins;
152     DWORD dwUnused;
153 };
154
155 struct REG_RFP
156 {
157     BYTE signature[4]; /* e.g. "0pi3" */
158     DWORD dwFlags;
159     DWORD dwInstances;
160     DWORD dwMediaTypes;
161     DWORD dwMediums;
162     DWORD bCategory; /* is there a category clsid? */
163     /* optional: dwOffsetCategoryClsid */
164 };
165
166 struct REG_TYPE
167 {
168     BYTE signature[4]; /* e.g. "0ty3" */
169     DWORD dwUnused;
170     DWORD dwOffsetMajor;
171     DWORD dwOffsetMinor;
172 };
173
174 struct MONIKER_MERIT
175 {
176     IMoniker * pMoniker;
177     DWORD dwMerit;
178 };
179
180 struct Vector
181 {
182     LPBYTE pData;
183     int capacity; /* in bytes */
184     int current; /* pointer to next free byte */
185 };
186
187 /* returns the position it was added at */
188 static int add_data(struct Vector * v, const BYTE * pData, int size)
189 {
190     int index = v->current;
191     if (v->current + size > v->capacity)
192     {
193         LPBYTE pOldData = v->pData;
194         v->capacity = (v->capacity + size) * 2;
195         v->pData = CoTaskMemAlloc(v->capacity);
196         memcpy(v->pData, pOldData, v->current);
197         CoTaskMemFree(pOldData);
198     }
199     memcpy(v->pData + v->current, pData, size);
200     v->current += size;
201     return index;
202 }
203
204 static int find_data(const struct Vector * v, const BYTE * pData, int size)
205 {
206     int index;
207     for (index = 0; index < v->current; index++)
208         if (!memcmp(v->pData + index, pData, size))
209             return index;
210     /* not found */
211     return -1;
212 }
213
214 static void delete_vector(struct Vector * v)
215 {
216     CoTaskMemFree(v->pData);
217     v->current = 0;
218     v->capacity = 0;
219 }
220
221 HRESULT FilterMapper2_create(IUnknown *pUnkOuter, LPVOID *ppObj)
222 {
223     FilterMapper2Impl * pFM2impl;
224
225     TRACE("(%p, %p)\n", pUnkOuter, ppObj);
226
227     pFM2impl = CoTaskMemAlloc(sizeof(*pFM2impl));
228     if (!pFM2impl)
229         return E_OUTOFMEMORY;
230
231     pFM2impl->pUnkOuter = pUnkOuter;
232     pFM2impl->bUnkOuterValid = FALSE;
233     pFM2impl->bAggregatable = FALSE;
234     pFM2impl->IInner_vtbl = &IInner_VTable;
235     pFM2impl->lpVtbl = &fm2vtbl;
236     pFM2impl->lpVtblFilterMapper = &fmvtbl;
237     pFM2impl->lpVtblAMFilterData = &AMFilterDataVtbl;
238     pFM2impl->refCount = 1;
239
240     *ppObj = pFM2impl;
241
242     TRACE("-- created at %p\n", pFM2impl);
243
244     return S_OK;
245 }
246
247 HRESULT FilterMapper_create(IUnknown *pUnkOuter, LPVOID *ppObj)
248 {
249     FilterMapper2Impl *pFM2impl;
250     HRESULT hr;
251
252     TRACE("(%p, %p)\n", pUnkOuter, ppObj);
253
254     hr = FilterMapper2_create(pUnkOuter, (LPVOID*)&pFM2impl);
255     if (FAILED(hr))
256         return hr;
257
258     *ppObj = &pFM2impl->lpVtblFilterMapper;
259
260     return hr;
261 }
262
263 /*** IUnknown (inner) methods ***/
264
265 static HRESULT WINAPI Inner_QueryInterface(IUnknown * iface, REFIID riid, LPVOID * ppv)
266 {
267     FilterMapper2Impl *This = impl_from_inner_IUnknown(iface);
268     TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
269
270     if (This->bAggregatable)
271         This->bUnkOuterValid = TRUE;
272
273     *ppv = NULL;
274
275     if (IsEqualIID(riid, &IID_IUnknown))
276         *ppv = &This->IInner_vtbl;
277     else if (IsEqualIID(riid, &IID_IFilterMapper2))
278         *ppv = This;
279     else if (IsEqualIID(riid, &IID_IFilterMapper))
280         *ppv = &This->lpVtblFilterMapper;
281     else if (IsEqualIID(riid, &IID_IAMFilterData))
282         *ppv = &This->lpVtblAMFilterData;
283
284     if (*ppv != NULL)
285     {
286         IUnknown_AddRef((IUnknown *)*ppv);
287         return S_OK;
288     }
289
290     FIXME("No interface for %s\n", debugstr_guid(riid));
291     return E_NOINTERFACE;
292 }
293
294 static ULONG WINAPI Inner_AddRef(IUnknown * iface)
295 {
296     FilterMapper2Impl *This = impl_from_inner_IUnknown(iface);
297     ULONG refCount = InterlockedIncrement(&This->refCount);
298
299     TRACE("(%p)->() AddRef from %d\n", This, refCount - 1);
300
301     return refCount;
302 }
303
304 static ULONG WINAPI Inner_Release(IUnknown * iface)
305 {
306     FilterMapper2Impl *This = impl_from_inner_IUnknown(iface);
307     ULONG refCount = InterlockedDecrement(&This->refCount);
308
309     TRACE("(%p)->() Release from %d\n", This, refCount + 1);
310
311     if (refCount == 0)
312     {
313         CoTaskMemFree(This);
314         return 0;
315     }
316     return refCount;
317 }
318
319 static const IUnknownVtbl IInner_VTable =
320 {
321     Inner_QueryInterface,
322     Inner_AddRef,
323     Inner_Release
324 };
325
326 static HRESULT WINAPI FilterMapper2_QueryInterface(IFilterMapper2 * iface, REFIID riid, LPVOID *ppv)
327 {
328     FilterMapper2Impl *This = (FilterMapper2Impl *)iface;
329
330     if (This->bAggregatable)
331         This->bUnkOuterValid = TRUE;
332
333     if (This->pUnkOuter)
334     {
335         if (This->bAggregatable)
336             return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
337
338         if (IsEqualIID(riid, &IID_IUnknown))
339         {
340             HRESULT hr;
341
342             IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
343             hr = IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
344             IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
345             This->bAggregatable = TRUE;
346             return hr;
347         }
348
349         *ppv = NULL;
350         return E_NOINTERFACE;
351     }
352
353     return IUnknown_QueryInterface((IUnknown *)&(This->IInner_vtbl), riid, ppv);
354 }
355
356 static ULONG WINAPI FilterMapper2_AddRef(IFilterMapper2 * iface)
357 {
358     FilterMapper2Impl *This = (FilterMapper2Impl *)iface;
359
360     if (This->pUnkOuter && This->bUnkOuterValid)
361         return IUnknown_AddRef(This->pUnkOuter);
362     return IUnknown_AddRef((IUnknown *)&(This->IInner_vtbl));
363 }
364
365 static ULONG WINAPI FilterMapper2_Release(IFilterMapper2 * iface)
366 {
367     FilterMapper2Impl *This = (FilterMapper2Impl *)iface;
368
369     if (This->pUnkOuter && This->bUnkOuterValid)
370         return IUnknown_Release(This->pUnkOuter);
371     return IUnknown_Release((IUnknown *)&(This->IInner_vtbl));
372 }
373
374 /*** IFilterMapper2 methods ***/
375
376 static HRESULT WINAPI FilterMapper2_CreateCategory(
377     IFilterMapper2 * iface,
378     REFCLSID clsidCategory,
379     DWORD dwCategoryMerit,
380     LPCWSTR szDescription)
381 {
382     LPWSTR wClsidAMCat = NULL;
383     LPWSTR wClsidCategory = NULL;
384     WCHAR wszKeyName[ARRAYSIZE(wszClsidSlash)-1 + ARRAYSIZE(wszSlashInstance)-1 + (CHARS_IN_GUID-1) * 2 + 1];
385     HKEY hKey = NULL;
386     LONG lRet;
387     HRESULT hr;
388
389     TRACE("(%s, %x, %s)\n", debugstr_guid(clsidCategory), dwCategoryMerit, debugstr_w(szDescription));
390
391     hr = StringFromCLSID(&CLSID_ActiveMovieCategories, &wClsidAMCat);
392
393     if (SUCCEEDED(hr))
394     {
395         hr = StringFromCLSID(clsidCategory, &wClsidCategory);
396     }
397
398     if (SUCCEEDED(hr))
399     {
400         strcpyW(wszKeyName, wszClsidSlash);
401         strcatW(wszKeyName, wClsidAMCat);
402         strcatW(wszKeyName, wszSlashInstance);
403         strcatW(wszKeyName, wClsidCategory);
404
405         lRet = RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
406         hr = HRESULT_FROM_WIN32(lRet);
407     }
408
409     if (SUCCEEDED(hr))
410     {
411         lRet = RegSetValueExW(hKey, wszFriendlyName, 0, REG_SZ, (const BYTE*)szDescription, (strlenW(szDescription) + 1) * sizeof(WCHAR));
412         hr = HRESULT_FROM_WIN32(lRet);
413     }
414
415     if (SUCCEEDED(hr))
416     {
417         lRet = RegSetValueExW(hKey, wszClsidName, 0, REG_SZ, (LPBYTE)wClsidCategory, (strlenW(wClsidCategory) + 1) * sizeof(WCHAR));
418         hr = HRESULT_FROM_WIN32(lRet);
419     }
420
421     if (SUCCEEDED(hr))
422     {
423         lRet = RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwCategoryMerit, sizeof(dwCategoryMerit));
424         hr = HRESULT_FROM_WIN32(lRet);
425     }
426
427     CloseHandle(hKey);
428     CoTaskMemFree(wClsidCategory);
429     CoTaskMemFree(wClsidAMCat);
430
431     return hr;
432 }
433
434 static HRESULT WINAPI FilterMapper2_UnregisterFilter(
435     IFilterMapper2 * iface,
436     const CLSID *pclsidCategory,
437     const OLECHAR *szInstance,
438     REFCLSID Filter)
439 {
440     WCHAR wszKeyName[MAX_PATH];
441     LPWSTR wClsidCategory = NULL;
442     LPWSTR wFilter = NULL;
443     HRESULT hr;
444
445     TRACE("(%p, %s, %s)\n", pclsidCategory, debugstr_w(szInstance), debugstr_guid(Filter));
446
447     if (!pclsidCategory)
448         pclsidCategory = &CLSID_LegacyAmFilterCategory;
449
450     hr = StringFromCLSID(pclsidCategory, &wClsidCategory);
451
452     if (SUCCEEDED(hr))
453     {
454         strcpyW(wszKeyName, wszClsidSlash);
455         strcatW(wszKeyName, wClsidCategory);
456         strcatW(wszKeyName, wszSlashInstance);
457         if (szInstance)
458             strcatW(wszKeyName, szInstance);
459         else
460         {
461             hr = StringFromCLSID(Filter, &wFilter);
462             if (SUCCEEDED(hr))
463                 strcatW(wszKeyName, wFilter);
464         }
465     }
466
467     if (SUCCEEDED(hr))
468     {
469         LONG lRet = RegDeleteKeyW(HKEY_CLASSES_ROOT, wszKeyName);
470         hr = HRESULT_FROM_WIN32(lRet);
471     }
472
473     CoTaskMemFree(wClsidCategory);
474     CoTaskMemFree(wFilter);
475
476     return hr;
477 }
478
479 static HRESULT FM2_WriteFriendlyName(IPropertyBag * pPropBag, LPCWSTR szName)
480 {
481     VARIANT var;
482     HRESULT ret;
483     BSTR value;
484
485     V_VT(&var) = VT_BSTR;
486     V_UNION(&var, bstrVal) = value = SysAllocString(szName);
487
488     ret = IPropertyBag_Write(pPropBag, wszFriendlyName, &var);
489     SysFreeString(value);
490
491     return ret;
492 }
493
494 static HRESULT FM2_WriteClsid(IPropertyBag * pPropBag, REFCLSID clsid)
495 {
496     LPWSTR wszClsid = NULL;
497     VARIANT var;
498     HRESULT hr;
499
500     hr = StringFromCLSID(clsid, &wszClsid);
501
502     if (SUCCEEDED(hr))
503     {
504         V_VT(&var) = VT_BSTR;
505         V_UNION(&var, bstrVal) = wszClsid;
506         hr = IPropertyBag_Write(pPropBag, wszClsidName, &var);
507     }
508     CoTaskMemFree(wszClsid);
509     return hr;
510 }
511
512 static HRESULT FM2_WriteFilterData(const REGFILTER2 * prf2, BYTE **ppData, ULONG *pcbData)
513 {
514     int size = sizeof(struct REG_RF);
515     unsigned int i;
516     struct Vector mainStore = {NULL, 0, 0};
517     struct Vector clsidStore = {NULL, 0, 0};
518     struct REG_RF rrf;
519     HRESULT hr = S_OK;
520
521     rrf.dwVersion = prf2->dwVersion;
522     rrf.dwMerit = prf2->dwMerit;
523     rrf.dwPins = prf2->u.s1.cPins2;
524     rrf.dwUnused = 0;
525
526     add_data(&mainStore, (LPBYTE)&rrf, sizeof(rrf));
527
528     for (i = 0; i < prf2->u.s1.cPins2; i++)
529     {
530         size += sizeof(struct REG_RFP);
531         if (prf2->u.s1.rgPins2[i].clsPinCategory)
532             size += sizeof(DWORD);
533         size += prf2->u.s1.rgPins2[i].nMediaTypes * sizeof(struct REG_TYPE);
534         size += prf2->u.s1.rgPins2[i].nMediums * sizeof(DWORD);
535     }
536
537     for (i = 0; i < prf2->u.s1.cPins2; i++)
538     {
539         struct REG_RFP rrfp;
540         REGFILTERPINS2 rgPin2 = prf2->u.s1.rgPins2[i];
541         unsigned int j;
542
543         rrfp.signature[0] = '0';
544         rrfp.signature[1] = 'p';
545         rrfp.signature[2] = 'i';
546         rrfp.signature[3] = '3';
547         rrfp.signature[0] += i;
548         rrfp.dwFlags = rgPin2.dwFlags;
549         rrfp.dwInstances = rgPin2.cInstances;
550         rrfp.dwMediaTypes = rgPin2.nMediaTypes;
551         rrfp.dwMediums = rgPin2.nMediums;
552         rrfp.bCategory = rgPin2.clsPinCategory ? 1 : 0;
553
554         add_data(&mainStore, (LPBYTE)&rrfp, sizeof(rrfp));
555         if (rrfp.bCategory)
556         {
557             DWORD index = find_data(&clsidStore, (const BYTE*)rgPin2.clsPinCategory, sizeof(CLSID));
558             if (index == -1)
559                 index = add_data(&clsidStore, (const BYTE*)rgPin2.clsPinCategory, sizeof(CLSID));
560             index += size;
561
562             add_data(&mainStore, (LPBYTE)&index, sizeof(index));
563         }
564
565         for (j = 0; j < rgPin2.nMediaTypes; j++)
566         {
567             struct REG_TYPE rt;
568             const CLSID * clsMinorType = rgPin2.lpMediaType[j].clsMinorType ? rgPin2.lpMediaType[j].clsMinorType : &MEDIASUBTYPE_NULL;
569             rt.signature[0] = '0';
570             rt.signature[1] = 't';
571             rt.signature[2] = 'y';
572             rt.signature[3] = '3';
573             rt.signature[0] += j;
574             rt.dwUnused = 0;
575             rt.dwOffsetMajor = find_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
576             if (rt.dwOffsetMajor == -1)
577                 rt.dwOffsetMajor = add_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
578             rt.dwOffsetMajor += size;
579             rt.dwOffsetMinor = find_data(&clsidStore, (const BYTE*)clsMinorType, sizeof(CLSID));
580             if (rt.dwOffsetMinor == -1)
581                 rt.dwOffsetMinor = add_data(&clsidStore, (const BYTE*)clsMinorType, sizeof(CLSID));
582             rt.dwOffsetMinor += size;
583
584             add_data(&mainStore, (LPBYTE)&rt, sizeof(rt));
585         }
586
587         for (j = 0; j < rgPin2.nMediums; j++)
588         {
589             DWORD index = find_data(&clsidStore, (const BYTE*)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
590             if (index == -1)
591                 index = add_data(&clsidStore, (const BYTE*)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
592             index += size;
593
594             add_data(&mainStore, (LPBYTE)&index, sizeof(index));
595         }
596     }
597
598     if (SUCCEEDED(hr))
599     {
600         *pcbData = mainStore.current + clsidStore.current;
601         *ppData = CoTaskMemAlloc(*pcbData);
602         if (!*ppData)
603             hr = E_OUTOFMEMORY;
604     }
605
606     if (SUCCEEDED(hr))
607     {
608         memcpy(*ppData, mainStore.pData, mainStore.current);
609         memcpy((*ppData) + mainStore.current, clsidStore.pData, clsidStore.current);
610     }
611
612     delete_vector(&mainStore);
613     delete_vector(&clsidStore);
614     return hr;
615 }
616
617 static HRESULT FM2_ReadFilterData(BYTE *pData, REGFILTER2 * prf2)
618 {
619     HRESULT hr = S_OK;
620     struct REG_RF * prrf;
621     LPBYTE pCurrent;
622     DWORD i;
623     REGFILTERPINS2 * rgPins2;
624
625     prrf = (struct REG_RF *)pData;
626     pCurrent = pData;
627
628     if (prrf->dwVersion != 2)
629     {
630         FIXME("Filter registry version %d not supported\n", prrf->dwVersion);
631         ZeroMemory(prf2, sizeof(*prf2));
632         hr = E_FAIL;
633     }
634
635     if (SUCCEEDED(hr))
636     {
637         TRACE("version = %d, merit = %x, #pins = %d, unused = %x\n",
638             prrf->dwVersion, prrf->dwMerit, prrf->dwPins, prrf->dwUnused);
639
640         prf2->dwVersion = prrf->dwVersion;
641         prf2->dwMerit = prrf->dwMerit;
642         prf2->u.s1.cPins2 = prrf->dwPins;
643         rgPins2 = CoTaskMemAlloc(prrf->dwPins * sizeof(*rgPins2));
644         prf2->u.s1.rgPins2 = rgPins2;
645         pCurrent += sizeof(struct REG_RF);
646
647         for (i = 0; i < prrf->dwPins; i++)
648         {
649             struct REG_RFP * prrfp = (struct REG_RFP *)pCurrent;
650             REGPINTYPES * lpMediaType;
651             REGPINMEDIUM * lpMedium;
652             UINT j;
653
654             /* FIXME: check signature */
655
656             TRACE("\tsignature = %s\n", debugstr_an((const char*)prrfp->signature, 4));
657
658             TRACE("\tpin[%d]: flags = %x, instances = %d, media types = %d, mediums = %d\n",
659                 i, prrfp->dwFlags, prrfp->dwInstances, prrfp->dwMediaTypes, prrfp->dwMediums);
660
661             rgPins2[i].dwFlags = prrfp->dwFlags;
662             rgPins2[i].cInstances = prrfp->dwInstances;
663             rgPins2[i].nMediaTypes = prrfp->dwMediaTypes;
664             rgPins2[i].nMediums = prrfp->dwMediums;
665             pCurrent += sizeof(struct REG_RFP);
666             if (prrfp->bCategory)
667             {
668                 CLSID * clsCat = CoTaskMemAlloc(sizeof(CLSID));
669                 memcpy(clsCat, pData + *(DWORD*)(pCurrent), sizeof(CLSID));
670                 pCurrent += sizeof(DWORD);
671                 rgPins2[i].clsPinCategory = clsCat;
672             }
673             else
674                 rgPins2[i].clsPinCategory = NULL;
675
676             if (rgPins2[i].nMediaTypes > 0)
677                 lpMediaType = CoTaskMemAlloc(rgPins2[i].nMediaTypes * sizeof(*lpMediaType));
678             else
679                 lpMediaType = NULL;
680
681             rgPins2[i].lpMediaType = lpMediaType;
682
683             for (j = 0; j < rgPins2[i].nMediaTypes; j++)
684             {
685                 struct REG_TYPE * prt = (struct REG_TYPE *)pCurrent;
686                 CLSID * clsMajor = CoTaskMemAlloc(sizeof(CLSID));
687                 CLSID * clsMinor = CoTaskMemAlloc(sizeof(CLSID));
688
689                 /* FIXME: check signature */
690                 TRACE("\t\tsignature = %s\n", debugstr_an((const char*)prt->signature, 4));
691
692                 memcpy(clsMajor, pData + prt->dwOffsetMajor, sizeof(CLSID));
693                 memcpy(clsMinor, pData + prt->dwOffsetMinor, sizeof(CLSID));
694
695                 lpMediaType[j].clsMajorType = clsMajor;
696                 lpMediaType[j].clsMinorType = clsMinor;
697
698                 pCurrent += sizeof(*prt);
699             }
700
701             if (rgPins2[i].nMediums > 0)
702                 lpMedium = CoTaskMemAlloc(rgPins2[i].nMediums * sizeof(*lpMedium));
703             else
704                 lpMedium = NULL;
705
706             rgPins2[i].lpMedium = lpMedium;
707
708             for (j = 0; j < rgPins2[i].nMediums; j++)
709             {
710                 DWORD dwOffset = *(DWORD *)pCurrent;
711
712                 memcpy(lpMedium + j, pData + dwOffset, sizeof(REGPINMEDIUM));
713
714                 pCurrent += sizeof(dwOffset);
715             }
716         }
717
718     }
719
720     return hr;
721 }
722
723 static void FM2_DeleteRegFilter(REGFILTER2 * prf2)
724 {
725     UINT i;
726     for (i = 0; i < prf2->u.s1.cPins2; i++)
727     {
728         UINT j;
729         if (prf2->u.s1.rgPins2[i].clsPinCategory)
730             CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].clsPinCategory);
731
732         for (j = 0; j < prf2->u.s1.rgPins2[i].nMediaTypes; j++)
733         {
734             CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMajorType);
735             CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMinorType);
736         }
737         CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType);
738         CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMedium);
739     }
740     CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2);
741 }
742
743 static HRESULT WINAPI FilterMapper2_RegisterFilter(
744     IFilterMapper2 * iface,
745     REFCLSID clsidFilter,
746     LPCWSTR szName,
747     IMoniker **ppMoniker,
748     const CLSID *pclsidCategory,
749     const OLECHAR *szInstance,
750     const REGFILTER2 *prf2)
751 {
752     IParseDisplayName * pParser = NULL;
753     IBindCtx * pBindCtx = NULL;
754     IMoniker * pMoniker = NULL;
755     IPropertyBag * pPropBag = NULL;
756     HRESULT hr;
757     LPWSTR pwszParseName = NULL;
758     LPWSTR pCurrent;
759     static const WCHAR wszDevice[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
760     int nameLen;
761     ULONG ulEaten;
762     LPWSTR szClsidTemp = NULL;
763     REGFILTER2 regfilter2;
764     REGFILTERPINS2* pregfp2 = NULL;
765
766     TRACE("(%s, %s, %p, %s, %s, %p)\n",
767         debugstr_guid(clsidFilter),
768         debugstr_w(szName),
769         ppMoniker,
770         debugstr_guid(pclsidCategory),
771         debugstr_w(szInstance),
772         prf2);
773
774     if (prf2->dwVersion == 2)
775     {
776         regfilter2 = *prf2;
777     }
778     else if (prf2->dwVersion == 1)
779     {
780         ULONG i;
781         DWORD flags;
782         /* REGFILTER2 structure is converted from version 1 to 2. Tested on Win2k. */
783         regfilter2.dwVersion = 2;
784         regfilter2.dwMerit = prf2->dwMerit;
785         regfilter2.u.s1.cPins2 = prf2->u.s.cPins;
786         pregfp2 = CoTaskMemAlloc(prf2->u.s.cPins * sizeof(REGFILTERPINS2));
787         regfilter2.u.s1.rgPins2 = pregfp2;
788         for (i = 0; i < prf2->u.s.cPins; i++)
789         {
790             flags = 0;
791             if (prf2->u.s.rgPins[i].bRendered)
792                 flags |= REG_PINFLAG_B_RENDERER;
793             if (prf2->u.s.rgPins[i].bOutput)
794                 flags |= REG_PINFLAG_B_OUTPUT;
795             if (prf2->u.s.rgPins[i].bZero)
796                 flags |= REG_PINFLAG_B_ZERO;
797             if (prf2->u.s.rgPins[i].bMany)
798                 flags |= REG_PINFLAG_B_MANY;
799             pregfp2[i].dwFlags = flags;
800             pregfp2[i].cInstances = 1;
801             pregfp2[i].nMediaTypes = prf2->u.s.rgPins[i].nMediaTypes;
802             pregfp2[i].lpMediaType = prf2->u.s.rgPins[i].lpMediaType;
803             pregfp2[i].nMediums = 0;
804             pregfp2[i].lpMedium = NULL;
805             pregfp2[i].clsPinCategory = NULL;
806         }
807     }
808     else
809     {
810         FIXME("dwVersion other that 1 or 2 not supported at the moment\n");
811         return E_NOTIMPL;
812     }
813
814     if (ppMoniker)
815         *ppMoniker = NULL;
816
817     if (!pclsidCategory)
818         /* MSDN mentions the inexistent CLSID_ActiveMovieFilters GUID.
819          * In fact this is the CLSID_LegacyAmFilterCategory one */
820         pclsidCategory = &CLSID_LegacyAmFilterCategory;
821
822     /* sizeof... will include the null terminator and
823      * the + 1 is for the separator ('\\'). The -1 is
824      * because CHARS_IN_GUID includes the null terminator
825      */
826     nameLen = sizeof(wszDevice)/sizeof(wszDevice[0]) + CHARS_IN_GUID - 1 + 1;
827
828     if (szInstance)
829         nameLen += strlenW(szInstance);
830     else
831         nameLen += CHARS_IN_GUID - 1; /* CHARS_IN_GUID includes null terminator */
832
833     pCurrent = pwszParseName = CoTaskMemAlloc(nameLen*sizeof(WCHAR));
834     if (!pwszParseName)
835         return E_OUTOFMEMORY;
836
837     strcpyW(pwszParseName, wszDevice);
838     pCurrent += strlenW(wszDevice);
839
840     hr = StringFromCLSID(pclsidCategory, &szClsidTemp);
841
842     if (SUCCEEDED(hr))
843     {
844         memcpy(pCurrent, szClsidTemp, CHARS_IN_GUID * sizeof(WCHAR));
845         pCurrent += CHARS_IN_GUID - 1;
846         pCurrent[0] = '\\';
847
848         if (szInstance)
849             strcpyW(pCurrent+1, szInstance);
850         else
851         {
852             CoTaskMemFree(szClsidTemp);
853             szClsidTemp = NULL;
854
855             hr = StringFromCLSID(clsidFilter, &szClsidTemp);
856             if (SUCCEEDED(hr))
857                 strcpyW(pCurrent+1, szClsidTemp);
858         }
859     }
860
861     if (SUCCEEDED(hr))
862         hr = CoCreateInstance(&CLSID_CDeviceMoniker, NULL, CLSCTX_INPROC, &IID_IParseDisplayName, (LPVOID *)&pParser);
863
864     if (SUCCEEDED(hr))
865         hr = CreateBindCtx(0, &pBindCtx);
866
867     if (SUCCEEDED(hr))
868         hr = IParseDisplayName_ParseDisplayName(pParser, pBindCtx, pwszParseName, &ulEaten, &pMoniker);
869
870     if (pBindCtx)
871         IBindCtx_Release(pBindCtx);
872     if (pParser)
873         IParseDisplayName_Release(pParser);
874
875     if (SUCCEEDED(hr))
876         hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID)&pPropBag);
877
878     if (SUCCEEDED(hr))
879         hr = FM2_WriteFriendlyName(pPropBag, szName);
880
881     if (SUCCEEDED(hr))
882         hr = FM2_WriteClsid(pPropBag, clsidFilter);
883
884     if (SUCCEEDED(hr))
885     {
886         BYTE *pData;
887         ULONG cbData;
888
889         hr = FM2_WriteFilterData(&regfilter2, &pData, &cbData);
890         if (SUCCEEDED(hr))
891         {
892             VARIANT var;
893             SAFEARRAY *psa;
894             SAFEARRAYBOUND saBound;
895
896             saBound.lLbound = 0;
897             saBound.cElements = cbData;
898             psa = SafeArrayCreate(VT_UI1, 1, &saBound);
899             if (!psa)
900             {
901                 ERR("Couldn't create SAFEARRAY\n");
902                 hr = E_FAIL;
903             }
904
905             if (SUCCEEDED(hr))
906             {
907                 LPBYTE pbSAData;
908                 hr = SafeArrayAccessData(psa, (LPVOID *)&pbSAData);
909                 if (SUCCEEDED(hr))
910                 {
911                     memcpy(pbSAData, pData, cbData);
912                     hr = SafeArrayUnaccessData(psa);
913                 }
914             }
915
916             V_VT(&var) = VT_ARRAY | VT_UI1;
917             V_UNION(&var, parray) = psa;
918
919             if (SUCCEEDED(hr))
920                 hr = IPropertyBag_Write(pPropBag, wszFilterDataName, &var);
921
922             if (psa)
923                 SafeArrayDestroy(psa);
924             CoTaskMemFree(pData);
925         }
926     }
927
928     if (pPropBag)
929         IPropertyBag_Release(pPropBag);
930     CoTaskMemFree(szClsidTemp);
931     CoTaskMemFree(pwszParseName);
932
933     if (SUCCEEDED(hr) && ppMoniker)
934         *ppMoniker = pMoniker;
935     else if (pMoniker)
936         IMoniker_Release(pMoniker);
937
938     CoTaskMemFree(pregfp2);
939
940     TRACE("-- returning %x\n", hr);
941
942     return hr;
943 }
944
945 /* internal helper function */
946 static BOOL MatchTypes(
947     BOOL bExactMatch,
948     DWORD nPinTypes,
949     const REGPINTYPES * pPinTypes,
950     DWORD nMatchTypes,
951     const GUID * pMatchTypes)
952 {
953     BOOL bMatch = FALSE;
954     DWORD j;
955
956     if ((nMatchTypes == 0) && (nPinTypes > 0))
957         bMatch = TRUE;
958
959     for (j = 0; j < nPinTypes; j++)
960     {
961         DWORD i;
962         for (i = 0; i < nMatchTypes*2; i+=2)
963         {
964             if (((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMajorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMajorType, &pMatchTypes[i])) &&
965                 ((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMinorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i+1], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMinorType, &pMatchTypes[i+1])))
966             {
967                 bMatch = TRUE;
968                 break;
969             }
970         }
971     }
972     return bMatch;
973 }
974
975 /* internal helper function for qsort of MONIKER_MERIT array */
976 static int mm_compare(const void * left, const void * right)
977 {
978     const struct MONIKER_MERIT * mmLeft = left;
979     const struct MONIKER_MERIT * mmRight = right;
980
981     if (mmLeft->dwMerit == mmRight->dwMerit)
982         return 0;
983     if (mmLeft->dwMerit > mmRight->dwMerit)
984         return -1;
985     return 1;
986 }
987
988 /* NOTES:
989  *   Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
990  *    (GUID_NULL's in input to function automatically treated as wild cards)
991  *   Input/Output needed means match only on criteria if TRUE (with zero input types
992  *    meaning match any input/output pin as long as one exists), otherwise match any
993  *    filter that meets the rest of the requirements.
994  */
995 static HRESULT WINAPI FilterMapper2_EnumMatchingFilters(
996     IFilterMapper2 * iface,
997     IEnumMoniker **ppEnum,
998     DWORD dwFlags,
999     BOOL bExactMatch,
1000     DWORD dwMerit,
1001     BOOL bInputNeeded,
1002     DWORD cInputTypes,
1003     const GUID *pInputTypes,
1004     const REGPINMEDIUM *pMedIn,
1005     const CLSID *pPinCategoryIn,
1006     BOOL bRender,
1007     BOOL bOutputNeeded,
1008     DWORD cOutputTypes,
1009     const GUID *pOutputTypes,
1010     const REGPINMEDIUM *pMedOut,
1011     const CLSID *pPinCategoryOut)
1012 {
1013     ICreateDevEnum * pCreateDevEnum;
1014     IMoniker * pMonikerCat;
1015     IEnumMoniker * pEnumCat;
1016     HRESULT hr;
1017     struct Vector monikers = {NULL, 0, 0};
1018
1019     TRACE("(%p, %x, %s, %x, %s, %d, %p, %p, %p, %s, %s, %p, %p, %p)\n",
1020         ppEnum,
1021         dwFlags,
1022         bExactMatch ? "true" : "false",
1023         dwMerit,
1024         bInputNeeded ? "true" : "false",
1025         cInputTypes,
1026         pInputTypes,
1027         pMedIn,
1028         pPinCategoryIn,
1029         bRender ? "true" : "false",
1030         bOutputNeeded ? "true" : "false",
1031         pOutputTypes,
1032         pMedOut,
1033         pPinCategoryOut);
1034
1035     if (dwFlags != 0)
1036     {
1037         FIXME("dwFlags = %x not implemented\n", dwFlags);
1038     }
1039
1040     *ppEnum = NULL;
1041
1042     hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, &IID_ICreateDevEnum, (LPVOID*)&pCreateDevEnum);
1043     if (FAILED(hr))
1044         return hr;
1045
1046     hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEnumCat, 0);
1047     if (FAILED(hr)) {
1048         ICreateDevEnum_Release(pCreateDevEnum);
1049         return hr;
1050     }
1051
1052     while (IEnumMoniker_Next(pEnumCat, 1, &pMonikerCat, NULL) == S_OK)
1053     {
1054         IPropertyBag * pPropBagCat = NULL;
1055         VARIANT var;
1056         HRESULT hrSub; /* this is so that one buggy filter
1057                           doesn't make the whole lot fail */
1058
1059         VariantInit(&var);
1060
1061         hrSub = IMoniker_BindToStorage(pMonikerCat, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
1062
1063         if (SUCCEEDED(hrSub))
1064             hrSub = IPropertyBag_Read(pPropBagCat, wszMeritName, &var, NULL);
1065
1066         if (SUCCEEDED(hrSub) && (V_UNION(&var, ulVal) >= dwMerit))
1067         {
1068             CLSID clsidCat;
1069             IEnumMoniker * pEnum;
1070             IMoniker * pMoniker;
1071
1072             VariantClear(&var);
1073
1074             if (TRACE_ON(quartz))
1075             {
1076                 VARIANT temp;
1077                 V_VT(&temp) = VT_EMPTY;
1078                 IPropertyBag_Read(pPropBagCat, wszFriendlyName, &temp, NULL);
1079                 TRACE("Considering category %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
1080                 VariantClear(&temp);
1081             }
1082
1083             hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
1084
1085             if (SUCCEEDED(hrSub))
1086                 hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsidCat);
1087
1088             if (SUCCEEDED(hrSub))
1089                 hrSub = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
1090
1091             if (hrSub == S_OK)
1092             {
1093                 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
1094                 {
1095                     IPropertyBag * pPropBag = NULL;
1096                     VARIANT var;
1097                     BYTE *pData = NULL;
1098                     REGFILTER2 rf2;
1099                     DWORD i;
1100                     BOOL bInputMatch = !bInputNeeded;
1101                     BOOL bOutputMatch = !bOutputNeeded;
1102
1103                     ZeroMemory(&rf2, sizeof(rf2));
1104                     VariantInit(&var);
1105
1106                     hrSub = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBag);
1107
1108                     if (TRACE_ON(quartz))
1109                     {
1110                         VARIANT temp;
1111                         V_VT(&temp) = VT_EMPTY;
1112                         IPropertyBag_Read(pPropBag, wszFriendlyName, &temp, NULL);
1113                         TRACE("Considering filter %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
1114                         VariantClear(&temp);
1115                     }
1116
1117                     if (SUCCEEDED(hrSub))
1118                     {
1119                         hrSub = IPropertyBag_Read(pPropBag, wszFilterDataName, &var, NULL);
1120                     }
1121
1122                     if (SUCCEEDED(hrSub))
1123                         hrSub = SafeArrayAccessData(V_UNION(&var, parray), (LPVOID*)&pData);
1124
1125                     if (SUCCEEDED(hrSub))
1126                         hrSub = FM2_ReadFilterData(pData, &rf2);
1127
1128                     if (pData)
1129                         SafeArrayUnaccessData(V_UNION(&var, parray));
1130
1131                     VariantClear(&var);
1132
1133                     /* Logic used for bInputMatch expression:
1134                      * There exists some pin such that bInputNeeded implies (pin is an input and
1135                      * (bRender implies pin has render flag) and major/minor types members of
1136                      * pInputTypes )
1137                      * bOutputMatch is similar, but without the "bRender implies ..." part
1138                      * and substituting variables names containing input for output
1139                      */
1140
1141                     /* determine whether filter meets requirements */
1142                     if (SUCCEEDED(hrSub) && (rf2.dwMerit >= dwMerit))
1143                     {
1144                         for (i = 0; (i < rf2.u.s1.cPins2) && (!bInputMatch || !bOutputMatch); i++)
1145                         {
1146                             const REGFILTERPINS2 * rfp2 = rf2.u.s1.rgPins2 + i;
1147
1148                             bInputMatch = bInputMatch || (!(rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
1149                                 (!bRender || (rfp2->dwFlags & REG_PINFLAG_B_RENDERER)) &&
1150                                 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cInputTypes, pInputTypes));
1151                             bOutputMatch = bOutputMatch || ((rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
1152                                 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cOutputTypes, pOutputTypes));
1153                         }
1154
1155                         if (bInputMatch && bOutputMatch)
1156                         {
1157                             struct MONIKER_MERIT mm = {pMoniker, rf2.dwMerit};
1158                             IMoniker_AddRef(pMoniker);
1159                             add_data(&monikers, (LPBYTE)&mm, sizeof(mm));
1160                         }
1161                     }
1162
1163                     FM2_DeleteRegFilter(&rf2);
1164                     if (pPropBag)
1165                         IPropertyBag_Release(pPropBag);
1166                     IMoniker_Release(pMoniker);
1167                 }
1168                 IEnumMoniker_Release(pEnum);
1169             }
1170         }
1171
1172         VariantClear(&var);
1173         if (pPropBagCat)
1174             IPropertyBag_Release(pPropBagCat);
1175         IMoniker_Release(pMonikerCat);
1176     }
1177
1178     if (SUCCEEDED(hr))
1179     {
1180         IMoniker ** ppMoniker;
1181         unsigned int i;
1182         ULONG nMonikerCount = monikers.current / sizeof(struct MONIKER_MERIT);
1183
1184         /* sort the monikers in descending merit order */
1185         qsort(monikers.pData, nMonikerCount,
1186               sizeof(struct MONIKER_MERIT),
1187               mm_compare);
1188
1189         /* construct an IEnumMoniker interface */
1190         ppMoniker = CoTaskMemAlloc(nMonikerCount * sizeof(IMoniker *));
1191         for (i = 0; i < nMonikerCount; i++)
1192         {
1193             /* no need to AddRef here as already AddRef'd above */
1194             ppMoniker[i] = ((struct MONIKER_MERIT *)monikers.pData)[i].pMoniker;
1195         }
1196         hr = EnumMonikerImpl_Create(ppMoniker, nMonikerCount, ppEnum);
1197         CoTaskMemFree(ppMoniker);
1198     }
1199
1200     delete_vector(&monikers);
1201     IEnumMoniker_Release(pEnumCat);
1202     ICreateDevEnum_Release(pCreateDevEnum);
1203
1204     return hr;
1205 }
1206
1207 static const IFilterMapper2Vtbl fm2vtbl =
1208 {
1209
1210     FilterMapper2_QueryInterface,
1211     FilterMapper2_AddRef,
1212     FilterMapper2_Release,
1213
1214     FilterMapper2_CreateCategory,
1215     FilterMapper2_UnregisterFilter,
1216     FilterMapper2_RegisterFilter,
1217     FilterMapper2_EnumMatchingFilters
1218 };
1219
1220 /*** IUnknown methods ***/
1221
1222 static HRESULT WINAPI FilterMapper_QueryInterface(IFilterMapper * iface, REFIID riid, LPVOID *ppv)
1223 {
1224     FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1225
1226     TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
1227
1228     return FilterMapper2_QueryInterface((IFilterMapper2*)&This->lpVtbl, riid, ppv);
1229 }
1230
1231 static ULONG WINAPI FilterMapper_AddRef(IFilterMapper * iface)
1232 {
1233     FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1234
1235     return FilterMapper2_AddRef((IFilterMapper2*)This);
1236 }
1237
1238 static ULONG WINAPI FilterMapper_Release(IFilterMapper * iface)
1239 {
1240     FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1241
1242     return FilterMapper2_Release((IFilterMapper2*)This);
1243 }
1244
1245 /*** IFilterMapper methods ***/
1246
1247 static HRESULT WINAPI FilterMapper_EnumMatchingFilters(
1248     IFilterMapper * iface,
1249     IEnumRegFilters **ppEnum,
1250     DWORD dwMerit,
1251     BOOL bInputNeeded,
1252     CLSID clsInMaj,
1253     CLSID clsInSub,
1254     BOOL bRender,
1255     BOOL bOutputNeeded,
1256     CLSID clsOutMaj,
1257     CLSID clsOutSub)
1258 {
1259     FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1260     GUID InputType[2];
1261     GUID OutputType[2];
1262     IEnumMoniker* ppEnumMoniker;
1263     IMoniker* IMon;
1264     ULONG nb;
1265     ULONG idx = 0, nb_mon = 0;
1266     REGFILTER* regfilters;
1267     HRESULT hr;
1268
1269     TRACE("(%p/%p)->(%p, %x, %s, %s, %s, %s, %s, %s, %s) stub!\n",
1270         iface,This,
1271         ppEnum,
1272         dwMerit,
1273         bInputNeeded ? "true" : "false",
1274         debugstr_guid(&clsInMaj),
1275         debugstr_guid(&clsInSub),
1276         bRender ? "true" : "false",
1277         bOutputNeeded ? "true" : "false",
1278         debugstr_guid(&clsOutMaj),
1279         debugstr_guid(&clsOutSub));
1280
1281     InputType[0] = clsInMaj;
1282     InputType[1] = clsInSub;
1283     OutputType[0] = clsOutMaj;
1284     OutputType[1] = clsOutSub;
1285
1286     *ppEnum = NULL;
1287
1288     hr = IFilterMapper2_EnumMatchingFilters((IFilterMapper2*)This,
1289                                        &ppEnumMoniker,
1290                                        0,
1291                                        TRUE,
1292                                        dwMerit,
1293                                        bInputNeeded,
1294                                        1,
1295                                        InputType,
1296                                        NULL,
1297                                        &GUID_NULL,
1298                                        bRender,
1299                                        bOutputNeeded,
1300                                        1,
1301                                        OutputType,
1302                                        NULL,
1303                                        &GUID_NULL);
1304
1305     if (FAILED(hr))
1306         return hr;
1307     
1308     while(IEnumMoniker_Next(ppEnumMoniker, 1, &IMon, &nb) == S_OK)
1309     {
1310         IMoniker_Release(IMon);
1311         nb_mon++;
1312     }
1313
1314     if (!nb_mon)
1315     {
1316         IEnumMoniker_Release(ppEnumMoniker);
1317         return IEnumRegFiltersImpl_Construct(NULL, 0, ppEnum);
1318     }
1319
1320     regfilters = CoTaskMemAlloc(nb_mon * sizeof(REGFILTER));
1321     if (!regfilters)
1322     {
1323         IEnumMoniker_Release(ppEnumMoniker);
1324         return E_OUTOFMEMORY;
1325     }
1326     ZeroMemory(regfilters, nb_mon * sizeof(REGFILTER)); /* will prevent bad free of Name in case of error. */
1327     
1328     IEnumMoniker_Reset(ppEnumMoniker);
1329     while(IEnumMoniker_Next(ppEnumMoniker, 1, &IMon, &nb) == S_OK)
1330     {
1331         IPropertyBag * pPropBagCat = NULL;
1332         VARIANT var;
1333         HRESULT hrSub;
1334         GUID clsid;
1335         int len;
1336
1337         VariantInit(&var);
1338
1339         hrSub = IMoniker_BindToStorage(IMon, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
1340
1341         if (SUCCEEDED(hrSub))
1342             hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
1343
1344         if (SUCCEEDED(hrSub))
1345             hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsid);
1346
1347         VariantClear(&var);
1348
1349         if (SUCCEEDED(hrSub))
1350             hrSub = IPropertyBag_Read(pPropBagCat, wszFriendlyName, &var, NULL);
1351
1352         if (SUCCEEDED(hrSub))
1353         {
1354             len = (strlenW(V_UNION(&var, bstrVal))+1) * sizeof(WCHAR);
1355             if (!(regfilters[idx].Name = CoTaskMemAlloc(len*2)))
1356                 hr = E_OUTOFMEMORY;
1357         }
1358
1359         if (SUCCEEDED(hrSub) && regfilters[idx].Name)
1360         {
1361             memcpy(regfilters[idx].Name, V_UNION(&var, bstrVal), len);
1362             regfilters[idx].Clsid = clsid;
1363             idx++;
1364         }
1365
1366         if (pPropBagCat)
1367             IPropertyBag_Release(pPropBagCat);
1368         IMoniker_Release(IMon);
1369         VariantClear(&var);
1370     }
1371
1372     if (SUCCEEDED(hr))
1373     {
1374         hr = IEnumRegFiltersImpl_Construct(regfilters, nb_mon, ppEnum);
1375     }
1376
1377     for (idx = 0; idx < nb_mon; idx++)
1378         CoTaskMemFree(regfilters[idx].Name);
1379     CoTaskMemFree(regfilters);
1380     IEnumMoniker_Release(ppEnumMoniker);
1381     
1382     return hr;
1383 }
1384
1385
1386 static HRESULT WINAPI FilterMapper_RegisterFilter(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, DWORD dwMerit)
1387 {
1388     HRESULT hr;
1389     LPWSTR wszClsid = NULL;
1390     HKEY hKey;
1391     LONG lRet;
1392     WCHAR wszKeyName[ARRAYSIZE(wszFilterSlash)-1 + (CHARS_IN_GUID-1) + 1];
1393
1394     TRACE("(%p)->(%s, %s, %x)\n", iface, debugstr_guid(&clsid), debugstr_w(szName), dwMerit);
1395
1396     hr = StringFromCLSID(&clsid, &wszClsid);
1397
1398     if (SUCCEEDED(hr))
1399     {
1400         strcpyW(wszKeyName, wszFilterSlash);
1401         strcatW(wszKeyName, wszClsid);
1402     
1403         lRet = RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
1404         hr = HRESULT_FROM_WIN32(lRet);
1405     }
1406
1407     if (SUCCEEDED(hr))
1408     {
1409         lRet = RegSetValueExW(hKey, NULL, 0, REG_SZ, (const BYTE*)szName, (strlenW(szName) + 1) * sizeof(WCHAR));
1410         hr = HRESULT_FROM_WIN32(lRet);
1411         CloseHandle(hKey);
1412     }
1413
1414     if (SUCCEEDED(hr))
1415     {
1416         strcpyW(wszKeyName, wszClsidSlash);
1417         strcatW(wszKeyName, wszClsid);
1418     
1419         lRet = RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
1420         hr = HRESULT_FROM_WIN32(lRet);
1421     }
1422
1423     if (SUCCEEDED(hr))
1424     {
1425         lRet = RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwMerit, sizeof(dwMerit));
1426         hr = HRESULT_FROM_WIN32(lRet);
1427         CloseHandle(hKey);
1428     }
1429     
1430     CoTaskMemFree(wszClsid);
1431
1432     return hr;
1433 }
1434
1435 static HRESULT WINAPI FilterMapper_RegisterFilterInstance(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, CLSID *MRId)
1436 {
1437     TRACE("(%p)->(%s, %s, %p)\n", iface, debugstr_guid(&clsid), debugstr_w(szName), MRId);
1438
1439     /* Not implemented in Windows (tested on Win2k) */
1440
1441     return E_NOTIMPL;
1442 }
1443
1444 static HRESULT WINAPI FilterMapper_RegisterPin(
1445     IFilterMapper * iface,
1446     CLSID Filter,
1447     LPCWSTR szName,
1448     BOOL bRendered,
1449     BOOL bOutput,
1450     BOOL bZero,
1451     BOOL bMany,
1452     CLSID ConnectsToFilter,
1453     LPCWSTR ConnectsToPin)
1454 {
1455     HRESULT hr;
1456     LONG lRet;
1457     LPWSTR wszClsid = NULL;
1458     HKEY hKey = NULL;
1459     HKEY hPinsKey = NULL;
1460     WCHAR * wszPinsKeyName;
1461     WCHAR wszKeyName[ARRAYSIZE(wszClsidSlash)-1 + (CHARS_IN_GUID-1) + 1];
1462
1463     TRACE("(%p)->(%s, %s, %d, %d, %d, %d, %s, %s)\n", iface, debugstr_guid(&Filter), debugstr_w(szName), bRendered,
1464                 bOutput, bZero, bMany, debugstr_guid(&ConnectsToFilter), debugstr_w(ConnectsToPin));
1465
1466     hr = StringFromCLSID(&Filter, &wszClsid);
1467
1468     if (SUCCEEDED(hr))
1469     {
1470         strcpyW(wszKeyName, wszClsidSlash);
1471         strcatW(wszKeyName, wszClsid);
1472
1473         lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1474         hr = HRESULT_FROM_WIN32(lRet);
1475     }
1476
1477     if (SUCCEEDED(hr))
1478     {
1479         wszPinsKeyName = CoTaskMemAlloc((strlenW(wszPins) + 1 + strlenW(szName) + 1) * 2);
1480         if (!wszPinsKeyName)
1481              hr = E_OUTOFMEMORY;
1482     }
1483
1484     if (SUCCEEDED(hr))
1485     {
1486         strcpyW(wszPinsKeyName, wszPins);
1487         strcatW(wszPinsKeyName, wszSlash);
1488         strcatW(wszPinsKeyName, szName);
1489     
1490         lRet = RegCreateKeyExW(hKey, wszPinsKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hPinsKey, NULL);
1491         hr = HRESULT_FROM_WIN32(lRet);
1492         CoTaskMemFree(wszPinsKeyName);
1493     }
1494
1495     if (SUCCEEDED(hr))
1496     {
1497         lRet = RegSetValueExW(hPinsKey, wszAllowedMany, 0, REG_DWORD, (LPBYTE)&bMany, sizeof(bMany));
1498         hr = HRESULT_FROM_WIN32(lRet);
1499     }
1500
1501     if (SUCCEEDED(hr))
1502     {
1503         lRet = RegSetValueExW(hPinsKey, wszAllowedZero, 0, REG_DWORD, (LPBYTE)&bZero, sizeof(bZero));
1504         hr = HRESULT_FROM_WIN32(lRet);
1505     }
1506
1507     if (SUCCEEDED(hr))
1508     {
1509         lRet = RegSetValueExW(hPinsKey, wszDirection, 0, REG_DWORD, (LPBYTE)&bOutput, sizeof(bOutput));
1510         hr = HRESULT_FROM_WIN32(lRet);
1511     }
1512
1513     if (SUCCEEDED(hr))
1514     {
1515         lRet = RegSetValueExW(hPinsKey, wszIsRendered, 0, REG_DWORD, (LPBYTE)&bRendered, sizeof(bRendered));
1516         hr = HRESULT_FROM_WIN32(lRet);
1517     }
1518
1519     if (SUCCEEDED(hr))
1520     {
1521         HKEY hkeyDummy = NULL;
1522
1523         lRet = RegCreateKeyExW(hPinsKey, wszTypes, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkeyDummy, NULL);
1524         hr = HRESULT_FROM_WIN32(lRet);
1525
1526         if (hkeyDummy) RegCloseKey(hkeyDummy);
1527     }
1528
1529     CoTaskMemFree(wszClsid);
1530     if (hKey)
1531         CloseHandle(hKey);
1532     if (hPinsKey)
1533         CloseHandle(hPinsKey);
1534
1535     return hr;
1536 }
1537
1538
1539 static HRESULT WINAPI FilterMapper_RegisterPinType(
1540     IFilterMapper * iface,
1541     CLSID clsFilter,
1542     LPCWSTR szName,
1543     CLSID clsMajorType,
1544     CLSID clsSubType)
1545 {
1546     HRESULT hr;
1547     LONG lRet;
1548     LPWSTR wszClsid = NULL;
1549     LPWSTR wszClsidMajorType = NULL;
1550     LPWSTR wszClsidSubType = NULL;
1551     HKEY hKey = NULL;
1552     WCHAR * wszTypesKey;
1553     WCHAR wszKeyName[MAX_PATH];
1554
1555     TRACE("(%p)->(%s, %s, %s, %s)\n", iface, debugstr_guid(&clsFilter), debugstr_w(szName),
1556                     debugstr_guid(&clsMajorType), debugstr_guid(&clsSubType));
1557
1558     hr = StringFromCLSID(&clsFilter, &wszClsid);
1559
1560     if (SUCCEEDED(hr))
1561     {
1562         hr = StringFromCLSID(&clsMajorType, &wszClsidMajorType);
1563     }
1564
1565     if (SUCCEEDED(hr))
1566     {
1567         hr = StringFromCLSID(&clsSubType, &wszClsidSubType);
1568     }
1569
1570     if (SUCCEEDED(hr))
1571     {
1572         wszTypesKey = CoTaskMemAlloc((strlenW(wszClsidSlash) + strlenW(wszClsid) + strlenW(wszPins) +
1573                         strlenW(szName) + strlenW(wszTypes) + 3 + 1) * 2);
1574         if (!wszTypesKey)
1575             hr = E_OUTOFMEMORY;
1576     }
1577
1578     if (SUCCEEDED(hr))
1579     {
1580         strcpyW(wszTypesKey, wszClsidSlash);
1581         strcatW(wszTypesKey, wszClsid);
1582         strcatW(wszTypesKey, wszSlash);
1583         strcatW(wszTypesKey, wszPins);
1584         strcatW(wszTypesKey, wszSlash);
1585         strcatW(wszTypesKey, szName);
1586         strcatW(wszTypesKey, wszSlash);
1587         strcatW(wszTypesKey, wszTypes);
1588
1589         lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszTypesKey, 0, KEY_WRITE, &hKey);
1590         hr = HRESULT_FROM_WIN32(lRet);
1591         CoTaskMemFree(wszTypesKey);
1592     }
1593
1594     if (SUCCEEDED(hr))
1595     {
1596         HKEY hkeyDummy = NULL;
1597
1598         strcpyW(wszKeyName, wszClsidMajorType);
1599         strcatW(wszKeyName, wszSlash);
1600         strcatW(wszKeyName, wszClsidSubType);
1601
1602         lRet = RegCreateKeyExW(hKey, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkeyDummy, NULL);
1603         hr = HRESULT_FROM_WIN32(lRet);
1604         CloseHandle(hKey);
1605
1606         if (hkeyDummy) RegCloseKey(hkeyDummy);
1607     }
1608
1609     CoTaskMemFree(wszClsid);
1610     CoTaskMemFree(wszClsidMajorType);
1611     CoTaskMemFree(wszClsidSubType);
1612
1613     return hr;
1614 }
1615
1616 static HRESULT WINAPI FilterMapper_UnregisterFilter(IFilterMapper * iface, CLSID Filter)
1617 {
1618     HRESULT hr;
1619     LONG lRet;
1620     LPWSTR wszClsid = NULL;
1621     HKEY hKey;
1622     WCHAR wszKeyName[ARRAYSIZE(wszClsidSlash)-1 + (CHARS_IN_GUID-1) + 1];
1623
1624     TRACE("(%p)->(%s)\n", iface, debugstr_guid(&Filter));
1625
1626     hr = StringFromCLSID(&Filter, &wszClsid);
1627
1628     if (SUCCEEDED(hr))
1629     {
1630         lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszFilter, 0, KEY_WRITE, &hKey);
1631         hr = HRESULT_FROM_WIN32(lRet);
1632     }
1633
1634     if (SUCCEEDED(hr))
1635     {
1636         lRet = RegDeleteKeyW(hKey, wszClsid);
1637         hr = HRESULT_FROM_WIN32(lRet);
1638         CloseHandle(hKey);
1639     }
1640
1641     if (SUCCEEDED(hr))
1642     {
1643         strcpyW(wszKeyName, wszClsidSlash);
1644         strcatW(wszKeyName, wszClsid);
1645
1646         lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1647         hr = HRESULT_FROM_WIN32(lRet);
1648     }
1649
1650     if (SUCCEEDED(hr))
1651     {
1652         lRet = RegDeleteValueW(hKey, wszMeritName);
1653         if (lRet != ERROR_SUCCESS)
1654             hr = HRESULT_FROM_WIN32(lRet);
1655
1656         lRet = RegDeleteTreeW(hKey, wszPins);
1657         if (lRet != ERROR_SUCCESS)
1658             hr = HRESULT_FROM_WIN32(lRet);
1659
1660         CloseHandle(hKey);
1661     }
1662
1663     CoTaskMemFree(wszClsid);
1664
1665     return hr;
1666 }
1667
1668 static HRESULT WINAPI FilterMapper_UnregisterFilterInstance(IFilterMapper * iface, CLSID MRId)
1669 {
1670     TRACE("(%p)->(%s)\n", iface, debugstr_guid(&MRId));
1671
1672     /* Not implemented in Windows (tested on Win2k) */
1673
1674     return E_NOTIMPL;
1675 }
1676
1677 static HRESULT WINAPI FilterMapper_UnregisterPin(IFilterMapper * iface, CLSID Filter, LPCWSTR Name)
1678 {
1679     HRESULT hr;
1680     LONG lRet;
1681     LPWSTR wszClsid = NULL;
1682     HKEY hKey = NULL;
1683     WCHAR * wszPinNameKey;
1684     WCHAR wszKeyName[ARRAYSIZE(wszClsidSlash)-1 + (CHARS_IN_GUID-1) + 1];
1685
1686     TRACE("(%p)->(%s, %s)\n", iface, debugstr_guid(&Filter), debugstr_w(Name));
1687
1688     if (!Name)
1689         return E_INVALIDARG;
1690
1691     hr = StringFromCLSID(&Filter, &wszClsid);
1692
1693     if (SUCCEEDED(hr))
1694     {
1695         strcpyW(wszKeyName, wszClsidSlash);
1696         strcatW(wszKeyName, wszClsid);
1697
1698         lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1699         hr = HRESULT_FROM_WIN32(lRet);
1700     }
1701
1702     if (SUCCEEDED(hr))
1703     {
1704         wszPinNameKey = CoTaskMemAlloc((strlenW(wszPins) + 1 + strlenW(Name) + 1) * 2);
1705         if (!wszPinNameKey)
1706             hr = E_OUTOFMEMORY;
1707     }
1708
1709     if (SUCCEEDED(hr))
1710     {
1711         strcpyW(wszPinNameKey, wszPins);
1712         strcatW(wszPinNameKey, wszSlash);
1713         strcatW(wszPinNameKey, Name);
1714
1715         lRet = RegDeleteTreeW(hKey, wszPinNameKey);
1716         hr = HRESULT_FROM_WIN32(lRet);
1717         CoTaskMemFree(wszPinNameKey);
1718     }
1719
1720     CoTaskMemFree(wszClsid);
1721     if (hKey)
1722         CloseHandle(hKey);
1723
1724     return hr;
1725 }
1726
1727 static const IFilterMapperVtbl fmvtbl =
1728 {
1729
1730     FilterMapper_QueryInterface,
1731     FilterMapper_AddRef,
1732     FilterMapper_Release,
1733
1734     FilterMapper_RegisterFilter,
1735     FilterMapper_RegisterFilterInstance,
1736     FilterMapper_RegisterPin,
1737     FilterMapper_RegisterPinType,
1738     FilterMapper_UnregisterFilter,
1739     FilterMapper_UnregisterFilterInstance,
1740     FilterMapper_UnregisterPin,
1741     FilterMapper_EnumMatchingFilters
1742 };
1743
1744
1745 /*** IUnknown methods ***/
1746 static HRESULT WINAPI AMFilterData_QueryInterface(IAMFilterData * iface, REFIID riid, LPVOID *ppv)
1747 {
1748     FilterMapper2Impl *This = impl_from_IAMFilterData(iface);
1749
1750     return FilterMapper2_QueryInterface((IFilterMapper2*)This, riid, ppv);
1751 }
1752
1753 static ULONG WINAPI AMFilterData_AddRef(IAMFilterData * iface)
1754 {
1755     FilterMapper2Impl *This = impl_from_IAMFilterData(iface);
1756
1757     return FilterMapper2_AddRef((IFilterMapper2*)This);
1758 }
1759
1760 static ULONG WINAPI AMFilterData_Release(IAMFilterData * iface)
1761 {
1762     FilterMapper2Impl *This = impl_from_IAMFilterData(iface);
1763
1764     return FilterMapper2_Release((IFilterMapper2*)This);
1765 }
1766
1767 /*** IAMFilterData methods ***/
1768 static HRESULT WINAPI AMFilterData_ParseFilterData(IAMFilterData* iface,
1769                                                    BYTE *pData, ULONG cb,
1770                                                    BYTE **ppRegFilter2)
1771 {
1772     FilterMapper2Impl *This = impl_from_IAMFilterData(iface);
1773     HRESULT hr = S_OK;
1774     REGFILTER2 *prf2;
1775
1776     TRACE("(%p/%p)->(%p, %d, %p)\n", This, iface, pData, cb, ppRegFilter2);
1777
1778     prf2 = CoTaskMemAlloc(sizeof(*prf2));
1779     if (!prf2)
1780         return E_OUTOFMEMORY;
1781     *ppRegFilter2 = (BYTE *)prf2;
1782
1783     hr = FM2_ReadFilterData(pData, prf2);
1784     if (FAILED(hr))
1785     {
1786         CoTaskMemFree(prf2);
1787         *ppRegFilter2 = NULL;
1788     }
1789
1790     return hr;
1791 }
1792
1793 static HRESULT WINAPI AMFilterData_CreateFilterData(IAMFilterData* iface,
1794                                                     REGFILTER2 *prf2,
1795                                                     BYTE **pRegFilterData,
1796                                                     ULONG *pcb)
1797 {
1798     FilterMapper2Impl *This = impl_from_IAMFilterData(iface);
1799
1800     TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, prf2, pRegFilterData, pcb);
1801
1802     return FM2_WriteFilterData(prf2, pRegFilterData, pcb);
1803 }
1804
1805 static const IAMFilterDataVtbl AMFilterDataVtbl = {
1806     AMFilterData_QueryInterface,
1807     AMFilterData_AddRef,
1808     AMFilterData_Release,
1809     AMFilterData_ParseFilterData,
1810     AMFilterData_CreateFilterData
1811 };