richedit: Removed an unnecessary call to GetScrollInfo.
[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
483     V_VT(&var) = VT_BSTR;
484     V_UNION(&var, bstrVal) = (BSTR)szName;
485
486     return IPropertyBag_Write(pPropBag, wszFriendlyName, &var);
487 }
488
489 static HRESULT FM2_WriteClsid(IPropertyBag * pPropBag, REFCLSID clsid)
490 {
491     LPWSTR wszClsid = NULL;
492     VARIANT var;
493     HRESULT hr;
494
495     hr = StringFromCLSID(clsid, &wszClsid);
496
497     if (SUCCEEDED(hr))
498     {
499         V_VT(&var) = VT_BSTR;
500         V_UNION(&var, bstrVal) = wszClsid;
501         hr = IPropertyBag_Write(pPropBag, wszClsidName, &var);
502     }
503     CoTaskMemFree(wszClsid);
504     return hr;
505 }
506
507 static HRESULT FM2_WriteFilterData(const REGFILTER2 * prf2, BYTE **ppData, ULONG *pcbData)
508 {
509     int size = sizeof(struct REG_RF);
510     unsigned int i;
511     struct Vector mainStore = {NULL, 0, 0};
512     struct Vector clsidStore = {NULL, 0, 0};
513     struct REG_RF rrf;
514     HRESULT hr = S_OK;
515
516     rrf.dwVersion = prf2->dwVersion;
517     rrf.dwMerit = prf2->dwMerit;
518     rrf.dwPins = prf2->u.s1.cPins2;
519     rrf.dwUnused = 0;
520
521     add_data(&mainStore, (LPBYTE)&rrf, sizeof(rrf));
522
523     for (i = 0; i < prf2->u.s1.cPins2; i++)
524     {
525         size += sizeof(struct REG_RFP);
526         if (prf2->u.s1.rgPins2[i].clsPinCategory)
527             size += sizeof(DWORD);
528         size += prf2->u.s1.rgPins2[i].nMediaTypes * sizeof(struct REG_TYPE);
529         size += prf2->u.s1.rgPins2[i].nMediums * sizeof(DWORD);
530     }
531
532     for (i = 0; i < prf2->u.s1.cPins2; i++)
533     {
534         struct REG_RFP rrfp;
535         REGFILTERPINS2 rgPin2 = prf2->u.s1.rgPins2[i];
536         unsigned int j;
537
538         rrfp.signature[0] = '0';
539         rrfp.signature[1] = 'p';
540         rrfp.signature[2] = 'i';
541         rrfp.signature[3] = '3';
542         rrfp.signature[0] += i;
543         rrfp.dwFlags = rgPin2.dwFlags;
544         rrfp.dwInstances = rgPin2.cInstances;
545         rrfp.dwMediaTypes = rgPin2.nMediaTypes;
546         rrfp.dwMediums = rgPin2.nMediums;
547         rrfp.bCategory = rgPin2.clsPinCategory ? 1 : 0;
548
549         add_data(&mainStore, (LPBYTE)&rrfp, sizeof(rrfp));
550         if (rrfp.bCategory)
551         {
552             DWORD index = find_data(&clsidStore, (const BYTE*)rgPin2.clsPinCategory, sizeof(CLSID));
553             if (index == -1)
554                 index = add_data(&clsidStore, (const BYTE*)rgPin2.clsPinCategory, sizeof(CLSID));
555             index += size;
556
557             add_data(&mainStore, (LPBYTE)&index, sizeof(index));
558         }
559
560         for (j = 0; j < rgPin2.nMediaTypes; j++)
561         {
562             struct REG_TYPE rt;
563             const CLSID * clsMinorType = rgPin2.lpMediaType[j].clsMinorType ? rgPin2.lpMediaType[j].clsMinorType : &MEDIASUBTYPE_NULL;
564             rt.signature[0] = '0';
565             rt.signature[1] = 't';
566             rt.signature[2] = 'y';
567             rt.signature[3] = '3';
568             rt.signature[0] += j;
569             rt.dwUnused = 0;
570             rt.dwOffsetMajor = find_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
571             if (rt.dwOffsetMajor == -1)
572                 rt.dwOffsetMajor = add_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
573             rt.dwOffsetMajor += size;
574             rt.dwOffsetMinor = find_data(&clsidStore, (const BYTE*)clsMinorType, sizeof(CLSID));
575             if (rt.dwOffsetMinor == -1)
576                 rt.dwOffsetMinor = add_data(&clsidStore, (const BYTE*)clsMinorType, sizeof(CLSID));
577             rt.dwOffsetMinor += size;
578
579             add_data(&mainStore, (LPBYTE)&rt, sizeof(rt));
580         }
581
582         for (j = 0; j < rgPin2.nMediums; j++)
583         {
584             DWORD index = find_data(&clsidStore, (const BYTE*)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
585             if (index == -1)
586                 index = add_data(&clsidStore, (const BYTE*)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
587             index += size;
588
589             add_data(&mainStore, (LPBYTE)&index, sizeof(index));
590         }
591     }
592
593     if (SUCCEEDED(hr))
594     {
595         *pcbData = mainStore.current + clsidStore.current;
596         *ppData = CoTaskMemAlloc(*pcbData);
597         if (!*ppData)
598             hr = E_OUTOFMEMORY;
599     }
600
601     if (SUCCEEDED(hr))
602     {
603         memcpy(*ppData, mainStore.pData, mainStore.current);
604         memcpy((*ppData) + mainStore.current, clsidStore.pData, clsidStore.current);
605     }
606
607     delete_vector(&mainStore);
608     delete_vector(&clsidStore);
609     return hr;
610 }
611
612 static HRESULT FM2_ReadFilterData(BYTE *pData, REGFILTER2 * prf2)
613 {
614     HRESULT hr = S_OK;
615     struct REG_RF * prrf;
616     LPBYTE pCurrent;
617     DWORD i;
618     REGFILTERPINS2 * rgPins2;
619
620     prrf = (struct REG_RF *)pData;
621     pCurrent = pData;
622
623     if (prrf->dwVersion != 2)
624     {
625         FIXME("Filter registry version %d not supported\n", prrf->dwVersion);
626         ZeroMemory(prf2, sizeof(*prf2));
627         hr = E_FAIL;
628     }
629
630     if (SUCCEEDED(hr))
631     {
632         TRACE("version = %d, merit = %x, #pins = %d, unused = %x\n",
633             prrf->dwVersion, prrf->dwMerit, prrf->dwPins, prrf->dwUnused);
634
635         prf2->dwVersion = prrf->dwVersion;
636         prf2->dwMerit = prrf->dwMerit;
637         prf2->u.s1.cPins2 = prrf->dwPins;
638         rgPins2 = CoTaskMemAlloc(prrf->dwPins * sizeof(*rgPins2));
639         prf2->u.s1.rgPins2 = rgPins2;
640         pCurrent += sizeof(struct REG_RF);
641
642         for (i = 0; i < prrf->dwPins; i++)
643         {
644             struct REG_RFP * prrfp = (struct REG_RFP *)pCurrent;
645             REGPINTYPES * lpMediaType;
646             REGPINMEDIUM * lpMedium;
647             UINT j;
648
649             /* FIXME: check signature */
650
651             TRACE("\tsignature = %s\n", debugstr_an((const char*)prrfp->signature, 4));
652
653             TRACE("\tpin[%d]: flags = %x, instances = %d, media types = %d, mediums = %d\n",
654                 i, prrfp->dwFlags, prrfp->dwInstances, prrfp->dwMediaTypes, prrfp->dwMediums);
655
656             rgPins2[i].dwFlags = prrfp->dwFlags;
657             rgPins2[i].cInstances = prrfp->dwInstances;
658             rgPins2[i].nMediaTypes = prrfp->dwMediaTypes;
659             rgPins2[i].nMediums = prrfp->dwMediums;
660             pCurrent += sizeof(struct REG_RFP);
661             if (prrfp->bCategory)
662             {
663                 CLSID * clsCat = CoTaskMemAlloc(sizeof(CLSID));
664                 memcpy(clsCat, pData + *(DWORD*)(pCurrent), sizeof(CLSID));
665                 pCurrent += sizeof(DWORD);
666                 rgPins2[i].clsPinCategory = clsCat;
667             }
668             else
669                 rgPins2[i].clsPinCategory = NULL;
670
671             if (rgPins2[i].nMediaTypes > 0)
672                 lpMediaType = CoTaskMemAlloc(rgPins2[i].nMediaTypes * sizeof(*lpMediaType));
673             else
674                 lpMediaType = NULL;
675
676             rgPins2[i].lpMediaType = lpMediaType;
677
678             for (j = 0; j < rgPins2[i].nMediaTypes; j++)
679             {
680                 struct REG_TYPE * prt = (struct REG_TYPE *)pCurrent;
681                 CLSID * clsMajor = CoTaskMemAlloc(sizeof(CLSID));
682                 CLSID * clsMinor = CoTaskMemAlloc(sizeof(CLSID));
683
684                 /* FIXME: check signature */
685                 TRACE("\t\tsignature = %s\n", debugstr_an((const char*)prt->signature, 4));
686
687                 memcpy(clsMajor, pData + prt->dwOffsetMajor, sizeof(CLSID));
688                 memcpy(clsMinor, pData + prt->dwOffsetMinor, sizeof(CLSID));
689
690                 lpMediaType[j].clsMajorType = clsMajor;
691                 lpMediaType[j].clsMinorType = clsMinor;
692
693                 pCurrent += sizeof(*prt);
694             }
695
696             if (rgPins2[i].nMediums > 0)
697                 lpMedium = CoTaskMemAlloc(rgPins2[i].nMediums * sizeof(*lpMedium));
698             else
699                 lpMedium = NULL;
700
701             rgPins2[i].lpMedium = lpMedium;
702
703             for (j = 0; j < rgPins2[i].nMediums; j++)
704             {
705                 DWORD dwOffset = *(DWORD *)pCurrent;
706
707                 memcpy(lpMedium + j, pData + dwOffset, sizeof(REGPINMEDIUM));
708
709                 pCurrent += sizeof(dwOffset);
710             }
711         }
712
713     }
714
715     return hr;
716 }
717
718 static void FM2_DeleteRegFilter(REGFILTER2 * prf2)
719 {
720     UINT i;
721     for (i = 0; i < prf2->u.s1.cPins2; i++)
722     {
723         UINT j;
724         if (prf2->u.s1.rgPins2[i].clsPinCategory)
725             CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].clsPinCategory);
726
727         for (j = 0; j < prf2->u.s1.rgPins2[i].nMediaTypes; j++)
728         {
729             CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMajorType);
730             CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMinorType);
731         }
732         CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType);
733         CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMedium);
734     }
735     CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2);
736 }
737
738 static HRESULT WINAPI FilterMapper2_RegisterFilter(
739     IFilterMapper2 * iface,
740     REFCLSID clsidFilter,
741     LPCWSTR szName,
742     IMoniker **ppMoniker,
743     const CLSID *pclsidCategory,
744     const OLECHAR *szInstance,
745     const REGFILTER2 *prf2)
746 {
747     IParseDisplayName * pParser = NULL;
748     IBindCtx * pBindCtx = NULL;
749     IMoniker * pMoniker = NULL;
750     IPropertyBag * pPropBag = NULL;
751     HRESULT hr;
752     LPWSTR pwszParseName = NULL;
753     LPWSTR pCurrent;
754     static const WCHAR wszDevice[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
755     int nameLen;
756     ULONG ulEaten;
757     LPWSTR szClsidTemp = NULL;
758     REGFILTER2 regfilter2;
759     REGFILTERPINS2* pregfp2 = NULL;
760
761     TRACE("(%s, %s, %p, %s, %s, %p)\n",
762         debugstr_guid(clsidFilter),
763         debugstr_w(szName),
764         ppMoniker,
765         debugstr_guid(pclsidCategory),
766         debugstr_w(szInstance),
767         prf2);
768
769     if (prf2->dwVersion == 2)
770     {
771         regfilter2 = *prf2;
772     }
773     else if (prf2->dwVersion == 1)
774     {
775         ULONG i;
776         DWORD flags;
777         /* REGFILTER2 structure is converted from version 1 to 2. Tested on Win2k. */
778         regfilter2.dwVersion = 2;
779         regfilter2.dwMerit = prf2->dwMerit;
780         regfilter2.u.s1.cPins2 = prf2->u.s.cPins;
781         pregfp2 = CoTaskMemAlloc(prf2->u.s.cPins * sizeof(REGFILTERPINS2));
782         regfilter2.u.s1.rgPins2 = pregfp2;
783         for (i = 0; i < prf2->u.s.cPins; i++)
784         {
785             flags = 0;
786             if (prf2->u.s.rgPins[i].bRendered)
787                 flags |= REG_PINFLAG_B_RENDERER;
788             if (prf2->u.s.rgPins[i].bOutput)
789                 flags |= REG_PINFLAG_B_OUTPUT;
790             if (prf2->u.s.rgPins[i].bZero)
791                 flags |= REG_PINFLAG_B_ZERO;
792             if (prf2->u.s.rgPins[i].bMany)
793                 flags |= REG_PINFLAG_B_MANY;
794             pregfp2[i].dwFlags = flags;
795             pregfp2[i].cInstances = 1;
796             pregfp2[i].nMediaTypes = prf2->u.s.rgPins[i].nMediaTypes;
797             pregfp2[i].lpMediaType = prf2->u.s.rgPins[i].lpMediaType;
798             pregfp2[i].nMediums = 0;
799             pregfp2[i].lpMedium = NULL;
800             pregfp2[i].clsPinCategory = NULL;
801         }
802     }
803     else
804     {
805         FIXME("dwVersion other that 1 or 2 not supported at the moment\n");
806         return E_NOTIMPL;
807     }
808
809     if (ppMoniker)
810         *ppMoniker = NULL;
811
812     if (!pclsidCategory)
813         /* MSDN mentions the inexistent CLSID_ActiveMovieFilters GUID.
814          * In fact this is the CLSID_LegacyAmFilterCategory one */
815         pclsidCategory = &CLSID_LegacyAmFilterCategory;
816
817     /* sizeof... will include the null terminator and
818      * the + 1 is for the separator ('\\'). The -1 is
819      * because CHARS_IN_GUID includes the null terminator
820      */
821     nameLen = sizeof(wszDevice)/sizeof(wszDevice[0]) + CHARS_IN_GUID - 1 + 1;
822
823     if (szInstance)
824         nameLen += strlenW(szInstance);
825     else
826         nameLen += CHARS_IN_GUID - 1; /* CHARS_IN_GUID includes null terminator */
827
828     pCurrent = pwszParseName = CoTaskMemAlloc(nameLen*sizeof(WCHAR));
829     if (!pwszParseName)
830         return E_OUTOFMEMORY;
831
832     strcpyW(pwszParseName, wszDevice);
833     pCurrent += strlenW(wszDevice);
834
835     hr = StringFromCLSID(pclsidCategory, &szClsidTemp);
836
837     if (SUCCEEDED(hr))
838     {
839         memcpy(pCurrent, szClsidTemp, CHARS_IN_GUID * sizeof(WCHAR));
840         pCurrent += CHARS_IN_GUID - 1;
841         pCurrent[0] = '\\';
842
843         if (szInstance)
844             strcpyW(pCurrent+1, szInstance);
845         else
846         {
847             CoTaskMemFree(szClsidTemp);
848             szClsidTemp = NULL;
849
850             hr = StringFromCLSID(clsidFilter, &szClsidTemp);
851             if (SUCCEEDED(hr))
852                 strcpyW(pCurrent+1, szClsidTemp);
853         }
854     }
855
856     if (SUCCEEDED(hr))
857         hr = CoCreateInstance(&CLSID_CDeviceMoniker, NULL, CLSCTX_INPROC, &IID_IParseDisplayName, (LPVOID *)&pParser);
858
859     if (SUCCEEDED(hr))
860         hr = CreateBindCtx(0, &pBindCtx);
861
862     if (SUCCEEDED(hr))
863         hr = IParseDisplayName_ParseDisplayName(pParser, pBindCtx, pwszParseName, &ulEaten, &pMoniker);
864
865     if (pBindCtx)
866         IBindCtx_Release(pBindCtx);
867     if (pParser)
868         IParseDisplayName_Release(pParser);
869
870     if (SUCCEEDED(hr))
871         hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID)&pPropBag);
872
873     if (SUCCEEDED(hr))
874         hr = FM2_WriteFriendlyName(pPropBag, szName);
875
876     if (SUCCEEDED(hr))
877         hr = FM2_WriteClsid(pPropBag, clsidFilter);
878
879     if (SUCCEEDED(hr))
880     {
881         BYTE *pData;
882         ULONG cbData;
883
884         hr = FM2_WriteFilterData(&regfilter2, &pData, &cbData);
885         if (SUCCEEDED(hr))
886         {
887             VARIANT var;
888             SAFEARRAY *psa;
889             SAFEARRAYBOUND saBound;
890
891             saBound.lLbound = 0;
892             saBound.cElements = cbData;
893             psa = SafeArrayCreate(VT_UI1, 1, &saBound);
894             if (!psa)
895             {
896                 ERR("Couldn't create SAFEARRAY\n");
897                 hr = E_FAIL;
898             }
899
900             if (SUCCEEDED(hr))
901             {
902                 LPBYTE pbSAData;
903                 hr = SafeArrayAccessData(psa, (LPVOID *)&pbSAData);
904                 if (SUCCEEDED(hr))
905                 {
906                     memcpy(pbSAData, pData, cbData);
907                     hr = SafeArrayUnaccessData(psa);
908                 }
909             }
910
911             V_VT(&var) = VT_ARRAY | VT_UI1;
912             V_UNION(&var, parray) = psa;
913
914             if (SUCCEEDED(hr))
915                 hr = IPropertyBag_Write(pPropBag, wszFilterDataName, &var);
916
917             if (psa)
918                 SafeArrayDestroy(psa);
919             CoTaskMemFree(pData);
920         }
921     }
922
923     if (pPropBag)
924         IPropertyBag_Release(pPropBag);
925     CoTaskMemFree(szClsidTemp);
926     CoTaskMemFree(pwszParseName);
927
928     if (SUCCEEDED(hr) && ppMoniker)
929         *ppMoniker = pMoniker;
930     else if (pMoniker)
931         IMoniker_Release(pMoniker);
932
933     CoTaskMemFree(pregfp2);
934
935     TRACE("-- returning %x\n", hr);
936
937     return hr;
938 }
939
940 /* internal helper function */
941 static BOOL MatchTypes(
942     BOOL bExactMatch,
943     DWORD nPinTypes,
944     const REGPINTYPES * pPinTypes,
945     DWORD nMatchTypes,
946     const GUID * pMatchTypes)
947 {
948     BOOL bMatch = FALSE;
949     DWORD j;
950
951     if ((nMatchTypes == 0) && (nPinTypes > 0))
952         bMatch = TRUE;
953
954     for (j = 0; j < nPinTypes; j++)
955     {
956         DWORD i;
957         for (i = 0; i < nMatchTypes*2; i+=2)
958         {
959             if (((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMajorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMajorType, &pMatchTypes[i])) &&
960                 ((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMinorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i+1], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMinorType, &pMatchTypes[i+1])))
961             {
962                 bMatch = TRUE;
963                 break;
964             }
965         }
966     }
967     return bMatch;
968 }
969
970 /* internal helper function for qsort of MONIKER_MERIT array */
971 static int mm_compare(const void * left, const void * right)
972 {
973     const struct MONIKER_MERIT * mmLeft = (const struct MONIKER_MERIT *)left;
974     const struct MONIKER_MERIT * mmRight = (const struct MONIKER_MERIT *)right;
975
976     if (mmLeft->dwMerit == mmRight->dwMerit)
977         return 0;
978     if (mmLeft->dwMerit > mmRight->dwMerit)
979         return -1;
980     return 1;
981 }
982
983 /* NOTES:
984  *   Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
985  *    (GUID_NULL's in input to function automatically treated as wild cards)
986  *   Input/Output needed means match only on criteria if TRUE (with zero input types
987  *    meaning match any input/output pin as long as one exists), otherwise match any
988  *    filter that meets the rest of the requirements.
989  */
990 static HRESULT WINAPI FilterMapper2_EnumMatchingFilters(
991     IFilterMapper2 * iface,
992     IEnumMoniker **ppEnum,
993     DWORD dwFlags,
994     BOOL bExactMatch,
995     DWORD dwMerit,
996     BOOL bInputNeeded,
997     DWORD cInputTypes,
998     const GUID *pInputTypes,
999     const REGPINMEDIUM *pMedIn,
1000     const CLSID *pPinCategoryIn,
1001     BOOL bRender,
1002     BOOL bOutputNeeded,
1003     DWORD cOutputTypes,
1004     const GUID *pOutputTypes,
1005     const REGPINMEDIUM *pMedOut,
1006     const CLSID *pPinCategoryOut)
1007 {
1008     ICreateDevEnum * pCreateDevEnum;
1009     IMoniker * pMonikerCat;
1010     IEnumMoniker * pEnumCat;
1011     HRESULT hr;
1012     struct Vector monikers = {NULL, 0, 0};
1013
1014     TRACE("(%p, %x, %s, %x, %s, %d, %p, %p, %p, %s, %s, %p, %p, %p)\n",
1015         ppEnum,
1016         dwFlags,
1017         bExactMatch ? "true" : "false",
1018         dwMerit,
1019         bInputNeeded ? "true" : "false",
1020         cInputTypes,
1021         pInputTypes,
1022         pMedIn,
1023         pPinCategoryIn,
1024         bRender ? "true" : "false",
1025         bOutputNeeded ? "true" : "false",
1026         pOutputTypes,
1027         pMedOut,
1028         pPinCategoryOut);
1029
1030     if (dwFlags != 0)
1031     {
1032         FIXME("dwFlags = %x not implemented\n", dwFlags);
1033     }
1034
1035     *ppEnum = NULL;
1036
1037     hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, &IID_ICreateDevEnum, (LPVOID*)&pCreateDevEnum);
1038     if (FAILED(hr))
1039         return hr;
1040
1041     hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEnumCat, 0);
1042     if (FAILED(hr)) {
1043         ICreateDevEnum_Release(pCreateDevEnum);
1044         return hr;
1045     }
1046
1047     while (IEnumMoniker_Next(pEnumCat, 1, &pMonikerCat, NULL) == S_OK)
1048     {
1049         IPropertyBag * pPropBagCat = NULL;
1050         VARIANT var;
1051         HRESULT hrSub; /* this is so that one buggy filter
1052                           doesn't make the whole lot fail */
1053
1054         VariantInit(&var);
1055
1056         hrSub = IMoniker_BindToStorage(pMonikerCat, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
1057
1058         if (SUCCEEDED(hrSub))
1059             hrSub = IPropertyBag_Read(pPropBagCat, wszMeritName, &var, NULL);
1060
1061         if (SUCCEEDED(hrSub) && (V_UNION(&var, ulVal) >= dwMerit))
1062         {
1063             CLSID clsidCat;
1064             IEnumMoniker * pEnum;
1065             IMoniker * pMoniker;
1066
1067             VariantClear(&var);
1068
1069             if (TRACE_ON(quartz))
1070             {
1071                 VARIANT temp;
1072                 V_VT(&temp) = VT_EMPTY;
1073                 IPropertyBag_Read(pPropBagCat, wszFriendlyName, &temp, NULL);
1074                 TRACE("Considering category %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
1075                 VariantClear(&temp);
1076             }
1077
1078             hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
1079
1080             if (SUCCEEDED(hrSub))
1081                 hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsidCat);
1082
1083             if (SUCCEEDED(hrSub))
1084                 hrSub = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
1085
1086             if (hrSub == S_OK)
1087             {
1088                 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
1089                 {
1090                     IPropertyBag * pPropBag = NULL;
1091                     VARIANT var;
1092                     BYTE *pData = NULL;
1093                     REGFILTER2 rf2;
1094                     DWORD i;
1095                     BOOL bInputMatch = !bInputNeeded;
1096                     BOOL bOutputMatch = !bOutputNeeded;
1097
1098                     ZeroMemory(&rf2, sizeof(rf2));
1099                     VariantInit(&var);
1100
1101                     hrSub = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBag);
1102
1103                     if (TRACE_ON(quartz))
1104                     {
1105                         VARIANT temp;
1106                         V_VT(&temp) = VT_EMPTY;
1107                         IPropertyBag_Read(pPropBag, wszFriendlyName, &temp, NULL);
1108                         TRACE("Considering filter %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
1109                         VariantClear(&temp);
1110                     }
1111
1112                     if (SUCCEEDED(hrSub))
1113                     {
1114                         hrSub = IPropertyBag_Read(pPropBag, wszFilterDataName, &var, NULL);
1115                     }
1116
1117                     if (SUCCEEDED(hrSub))
1118                         hrSub = SafeArrayAccessData(V_UNION(&var, parray), (LPVOID*)&pData);
1119
1120                     if (SUCCEEDED(hrSub))
1121                         hrSub = FM2_ReadFilterData(pData, &rf2);
1122
1123                     if (pData)
1124                         SafeArrayUnaccessData(V_UNION(&var, parray));
1125
1126                     VariantClear(&var);
1127
1128                     /* Logic used for bInputMatch expression:
1129                      * There exists some pin such that bInputNeeded implies (pin is an input and
1130                      * (bRender implies pin has render flag) and major/minor types members of
1131                      * pInputTypes )
1132                      * bOutputMatch is similar, but without the "bRender implies ..." part
1133                      * and substituting variables names containing input for output
1134                      */
1135
1136                     /* determine whether filter meets requirements */
1137                     if (SUCCEEDED(hrSub) && (rf2.dwMerit >= dwMerit))
1138                     {
1139                         for (i = 0; (i < rf2.u.s1.cPins2) && (!bInputMatch || !bOutputMatch); i++)
1140                         {
1141                             const REGFILTERPINS2 * rfp2 = rf2.u.s1.rgPins2 + i;
1142
1143                             bInputMatch = bInputMatch || (!(rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
1144                                 (!bRender || (rfp2->dwFlags & REG_PINFLAG_B_RENDERER)) &&
1145                                 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cInputTypes, pInputTypes));
1146                             bOutputMatch = bOutputMatch || ((rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
1147                                 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cOutputTypes, pOutputTypes));
1148                         }
1149
1150                         if (bInputMatch && bOutputMatch)
1151                         {
1152                             struct MONIKER_MERIT mm = {pMoniker, rf2.dwMerit};
1153                             IMoniker_AddRef(pMoniker);
1154                             add_data(&monikers, (LPBYTE)&mm, sizeof(mm));
1155                         }
1156                     }
1157
1158                     FM2_DeleteRegFilter(&rf2);
1159                     if (pPropBag)
1160                         IPropertyBag_Release(pPropBag);
1161                     IMoniker_Release(pMoniker);
1162                 }
1163                 IEnumMoniker_Release(pEnum);
1164             }
1165         }
1166
1167         VariantClear(&var);
1168         if (pPropBagCat)
1169             IPropertyBag_Release(pPropBagCat);
1170         IMoniker_Release(pMonikerCat);
1171     }
1172
1173     if (SUCCEEDED(hr))
1174     {
1175         IMoniker ** ppMoniker;
1176         unsigned int i;
1177         ULONG nMonikerCount = monikers.current / sizeof(struct MONIKER_MERIT);
1178
1179         /* sort the monikers in descending merit order */
1180         qsort(monikers.pData, nMonikerCount,
1181               sizeof(struct MONIKER_MERIT),
1182               mm_compare);
1183
1184         /* construct an IEnumMoniker interface */
1185         ppMoniker = CoTaskMemAlloc(nMonikerCount * sizeof(IMoniker *));
1186         for (i = 0; i < nMonikerCount; i++)
1187         {
1188             /* no need to AddRef here as already AddRef'd above */
1189             ppMoniker[i] = ((struct MONIKER_MERIT *)monikers.pData)[i].pMoniker;
1190         }
1191         hr = EnumMonikerImpl_Create(ppMoniker, nMonikerCount, ppEnum);
1192         CoTaskMemFree(ppMoniker);
1193     }
1194
1195     delete_vector(&monikers);
1196     IEnumMoniker_Release(pEnumCat);
1197     ICreateDevEnum_Release(pCreateDevEnum);
1198
1199     return hr;
1200 }
1201
1202 static const IFilterMapper2Vtbl fm2vtbl =
1203 {
1204
1205     FilterMapper2_QueryInterface,
1206     FilterMapper2_AddRef,
1207     FilterMapper2_Release,
1208
1209     FilterMapper2_CreateCategory,
1210     FilterMapper2_UnregisterFilter,
1211     FilterMapper2_RegisterFilter,
1212     FilterMapper2_EnumMatchingFilters
1213 };
1214
1215 /*** IUnknown methods ***/
1216
1217 static HRESULT WINAPI FilterMapper_QueryInterface(IFilterMapper * iface, REFIID riid, LPVOID *ppv)
1218 {
1219     FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1220
1221     TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
1222
1223     return FilterMapper2_QueryInterface((IFilterMapper2*)&This->lpVtbl, riid, ppv);
1224 }
1225
1226 static ULONG WINAPI FilterMapper_AddRef(IFilterMapper * iface)
1227 {
1228     FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1229
1230     return FilterMapper2_AddRef((IFilterMapper2*)This);
1231 }
1232
1233 static ULONG WINAPI FilterMapper_Release(IFilterMapper * iface)
1234 {
1235     FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1236
1237     return FilterMapper2_Release((IFilterMapper2*)This);
1238 }
1239
1240 /*** IFilterMapper methods ***/
1241
1242 static HRESULT WINAPI FilterMapper_EnumMatchingFilters(
1243     IFilterMapper * iface,
1244     IEnumRegFilters **ppEnum,
1245     DWORD dwMerit,
1246     BOOL bInputNeeded,
1247     CLSID clsInMaj,
1248     CLSID clsInSub,
1249     BOOL bRender,
1250     BOOL bOutputNeeded,
1251     CLSID clsOutMaj,
1252     CLSID clsOutSub)
1253 {
1254     FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1255     GUID InputType[2];
1256     GUID OutputType[2];
1257     IEnumMoniker* ppEnumMoniker;
1258     IMoniker* IMon;
1259     ULONG nb;
1260     ULONG idx = 0, nb_mon = 0;
1261     REGFILTER* regfilters;
1262     HRESULT hr;
1263
1264     TRACE("(%p/%p)->(%p, %x, %s, %s, %s, %s, %s, %s, %s) stub!\n",
1265         iface,This,
1266         ppEnum,
1267         dwMerit,
1268         bInputNeeded ? "true" : "false",
1269         debugstr_guid(&clsInMaj),
1270         debugstr_guid(&clsInSub),
1271         bRender ? "true" : "false",
1272         bOutputNeeded ? "true" : "false",
1273         debugstr_guid(&clsOutMaj),
1274         debugstr_guid(&clsOutSub));
1275
1276     InputType[0] = clsInMaj;
1277     InputType[1] = clsInSub;
1278     OutputType[0] = clsOutMaj;
1279     OutputType[1] = clsOutSub;
1280
1281     *ppEnum = NULL;
1282
1283     hr = IFilterMapper2_EnumMatchingFilters((IFilterMapper2*)This,
1284                                        &ppEnumMoniker,
1285                                        0,
1286                                        TRUE,
1287                                        dwMerit,
1288                                        bInputNeeded,
1289                                        1,
1290                                        InputType,
1291                                        NULL,
1292                                        &GUID_NULL,
1293                                        bRender,
1294                                        bOutputNeeded,
1295                                        1,
1296                                        OutputType,
1297                                        NULL,
1298                                        &GUID_NULL);
1299
1300     if (FAILED(hr))
1301         return hr;
1302     
1303     while(IEnumMoniker_Next(ppEnumMoniker, 1, &IMon, &nb) == S_OK)
1304     {
1305         IMoniker_Release(IMon);
1306         nb_mon++;
1307     }
1308
1309     if (!nb_mon)
1310     {
1311         IEnumMoniker_Release(ppEnumMoniker);
1312         return IEnumRegFiltersImpl_Construct(NULL, 0, ppEnum);
1313     }
1314
1315     regfilters = CoTaskMemAlloc(nb_mon * sizeof(REGFILTER));
1316     if (!regfilters)
1317     {
1318         IEnumMoniker_Release(ppEnumMoniker);
1319         return E_OUTOFMEMORY;
1320     }
1321     ZeroMemory(regfilters, nb_mon * sizeof(REGFILTER)); /* will prevent bad free of Name in case of error. */
1322     
1323     IEnumMoniker_Reset(ppEnumMoniker);
1324     while(IEnumMoniker_Next(ppEnumMoniker, 1, &IMon, &nb) == S_OK)
1325     {
1326         IPropertyBag * pPropBagCat = NULL;
1327         VARIANT var;
1328         HRESULT hrSub;
1329         GUID clsid;
1330         int len;
1331
1332         VariantInit(&var);
1333
1334         hrSub = IMoniker_BindToStorage(IMon, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
1335
1336         if (SUCCEEDED(hrSub))
1337             hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
1338
1339         if (SUCCEEDED(hrSub))
1340             hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsid);
1341
1342         VariantClear(&var);
1343
1344         if (SUCCEEDED(hrSub))
1345             hrSub = IPropertyBag_Read(pPropBagCat, wszFriendlyName, &var, NULL);
1346
1347         if (SUCCEEDED(hrSub))
1348         {
1349             len = (strlenW((WCHAR*)V_UNION(&var, bstrVal))+1) * sizeof(WCHAR);
1350             if (!(regfilters[idx].Name = CoTaskMemAlloc(len*2)))
1351                 hr = E_OUTOFMEMORY;
1352         }
1353
1354         if (SUCCEEDED(hrSub) && regfilters[idx].Name)
1355         {
1356             memcpy(regfilters[idx].Name, V_UNION(&var, bstrVal), len);
1357             regfilters[idx].Clsid = clsid;
1358             idx++;
1359         }
1360
1361         if (pPropBagCat)
1362             IPropertyBag_Release(pPropBagCat);
1363         IMoniker_Release(IMon);
1364         VariantClear(&var);
1365     }
1366
1367     if (SUCCEEDED(hr))
1368     {
1369         hr = IEnumRegFiltersImpl_Construct(regfilters, nb_mon, ppEnum);
1370     }
1371
1372     for (idx = 0; idx < nb_mon; idx++)
1373         CoTaskMemFree(regfilters[idx].Name);
1374     CoTaskMemFree(regfilters);
1375     IEnumMoniker_Release(ppEnumMoniker);
1376     
1377     return hr;
1378 }
1379
1380
1381 static HRESULT WINAPI FilterMapper_RegisterFilter(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, DWORD dwMerit)
1382 {
1383     HRESULT hr;
1384     LPWSTR wszClsid = NULL;
1385     HKEY hKey;
1386     LONG lRet;
1387     WCHAR wszKeyName[ARRAYSIZE(wszFilterSlash)-1 + (CHARS_IN_GUID-1) + 1];
1388
1389     TRACE("(%p)->(%s, %s, %x)\n", iface, debugstr_guid(&clsid), debugstr_w(szName), dwMerit);
1390
1391     hr = StringFromCLSID(&clsid, &wszClsid);
1392
1393     if (SUCCEEDED(hr))
1394     {
1395         strcpyW(wszKeyName, wszFilterSlash);
1396         strcatW(wszKeyName, wszClsid);
1397     
1398         lRet = RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
1399         hr = HRESULT_FROM_WIN32(lRet);
1400     }
1401
1402     if (SUCCEEDED(hr))
1403     {
1404         lRet = RegSetValueExW(hKey, NULL, 0, REG_SZ, (const BYTE*)szName, (strlenW(szName) + 1) * sizeof(WCHAR));
1405         hr = HRESULT_FROM_WIN32(lRet);
1406         CloseHandle(hKey);
1407     }
1408
1409     if (SUCCEEDED(hr))
1410     {
1411         strcpyW(wszKeyName, wszClsidSlash);
1412         strcatW(wszKeyName, wszClsid);
1413     
1414         lRet = RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL);
1415         hr = HRESULT_FROM_WIN32(lRet);
1416     }
1417
1418     if (SUCCEEDED(hr))
1419     {
1420         lRet = RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwMerit, sizeof(dwMerit));
1421         hr = HRESULT_FROM_WIN32(lRet);
1422         CloseHandle(hKey);
1423     }
1424     
1425     CoTaskMemFree(wszClsid);
1426
1427     return hr;
1428 }
1429
1430 static HRESULT WINAPI FilterMapper_RegisterFilterInstance(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, CLSID *MRId)
1431 {
1432     TRACE("(%p)->(%s, %s, %p)\n", iface, debugstr_guid(&clsid), debugstr_w(szName), MRId);
1433
1434     /* Not implemented in Windows (tested on Win2k) */
1435
1436     return E_NOTIMPL;
1437 }
1438
1439 static HRESULT WINAPI FilterMapper_RegisterPin(
1440     IFilterMapper * iface,
1441     CLSID Filter,
1442     LPCWSTR szName,
1443     BOOL bRendered,
1444     BOOL bOutput,
1445     BOOL bZero,
1446     BOOL bMany,
1447     CLSID ConnectsToFilter,
1448     LPCWSTR ConnectsToPin)
1449 {
1450     HRESULT hr;
1451     LONG lRet;
1452     LPWSTR wszClsid = NULL;
1453     HKEY hKey = NULL;
1454     HKEY hPinsKey = NULL;
1455     WCHAR * wszPinsKeyName;
1456     WCHAR wszKeyName[ARRAYSIZE(wszClsidSlash)-1 + (CHARS_IN_GUID-1) + 1];
1457
1458     TRACE("(%p)->(%s, %s, %d, %d, %d, %d, %s, %s)\n", iface, debugstr_guid(&Filter), debugstr_w(szName), bRendered,
1459                 bOutput, bZero, bMany, debugstr_guid(&ConnectsToFilter), debugstr_w(ConnectsToPin));
1460
1461     hr = StringFromCLSID(&Filter, &wszClsid);
1462
1463     if (SUCCEEDED(hr))
1464     {
1465         strcpyW(wszKeyName, wszClsidSlash);
1466         strcatW(wszKeyName, wszClsid);
1467
1468         lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1469         hr = HRESULT_FROM_WIN32(lRet);
1470     }
1471
1472     if (SUCCEEDED(hr))
1473     {
1474         wszPinsKeyName = CoTaskMemAlloc((strlenW(wszPins) + 1 + strlenW(szName) + 1) * 2);
1475         if (!wszPinsKeyName)
1476              hr = E_OUTOFMEMORY;
1477     }
1478
1479     if (SUCCEEDED(hr))
1480     {
1481         strcpyW(wszPinsKeyName, wszPins);
1482         strcatW(wszPinsKeyName, wszSlash);
1483         strcatW(wszPinsKeyName, szName);
1484     
1485         lRet = RegCreateKeyExW(hKey, wszPinsKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hPinsKey, NULL);
1486         hr = HRESULT_FROM_WIN32(lRet);
1487         CoTaskMemFree(wszPinsKeyName);
1488     }
1489
1490     if (SUCCEEDED(hr))
1491     {
1492         lRet = RegSetValueExW(hPinsKey, wszAllowedMany, 0, REG_DWORD, (LPBYTE)&bMany, sizeof(bMany));
1493         hr = HRESULT_FROM_WIN32(lRet);
1494     }
1495
1496     if (SUCCEEDED(hr))
1497     {
1498         lRet = RegSetValueExW(hPinsKey, wszAllowedZero, 0, REG_DWORD, (LPBYTE)&bZero, sizeof(bZero));
1499         hr = HRESULT_FROM_WIN32(lRet);
1500     }
1501
1502     if (SUCCEEDED(hr))
1503     {
1504         lRet = RegSetValueExW(hPinsKey, wszDirection, 0, REG_DWORD, (LPBYTE)&bOutput, sizeof(bOutput));
1505         hr = HRESULT_FROM_WIN32(lRet);
1506     }
1507
1508     if (SUCCEEDED(hr))
1509     {
1510         lRet = RegSetValueExW(hPinsKey, wszIsRendered, 0, REG_DWORD, (LPBYTE)&bRendered, sizeof(bRendered));
1511         hr = HRESULT_FROM_WIN32(lRet);
1512     }
1513
1514     if (SUCCEEDED(hr))
1515     {
1516         HKEY hkeyDummy = NULL;
1517
1518         lRet = RegCreateKeyExW(hPinsKey, wszTypes, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkeyDummy, NULL);
1519         hr = HRESULT_FROM_WIN32(lRet);
1520
1521         if (hkeyDummy) RegCloseKey(hkeyDummy);
1522     }
1523
1524     CoTaskMemFree(wszClsid);
1525     if (hKey)
1526         CloseHandle(hKey);
1527     if (hPinsKey)
1528         CloseHandle(hPinsKey);
1529
1530     return hr;
1531 }
1532
1533
1534 static HRESULT WINAPI FilterMapper_RegisterPinType(
1535     IFilterMapper * iface,
1536     CLSID clsFilter,
1537     LPCWSTR szName,
1538     CLSID clsMajorType,
1539     CLSID clsSubType)
1540 {
1541     HRESULT hr;
1542     LONG lRet;
1543     LPWSTR wszClsid = NULL;
1544     LPWSTR wszClsidMajorType = NULL;
1545     LPWSTR wszClsidSubType = NULL;
1546     HKEY hKey = NULL;
1547     WCHAR * wszTypesKey;
1548     WCHAR wszKeyName[MAX_PATH];
1549
1550     TRACE("(%p)->(%s, %s, %s, %s)\n", iface, debugstr_guid(&clsFilter), debugstr_w(szName),
1551                     debugstr_guid(&clsMajorType), debugstr_guid(&clsSubType));
1552
1553     hr = StringFromCLSID(&clsFilter, &wszClsid);
1554
1555     if (SUCCEEDED(hr))
1556     {
1557         hr = StringFromCLSID(&clsMajorType, &wszClsidMajorType);
1558     }
1559
1560     if (SUCCEEDED(hr))
1561     {
1562         hr = StringFromCLSID(&clsSubType, &wszClsidSubType);
1563     }
1564
1565     if (SUCCEEDED(hr))
1566     {
1567         wszTypesKey = CoTaskMemAlloc((strlenW(wszClsidSlash) + strlenW(wszClsid) + strlenW(wszPins) +
1568                         strlenW(szName) + strlenW(wszTypes) + 3 + 1) * 2);
1569         if (!wszTypesKey)
1570             hr = E_OUTOFMEMORY;
1571     }
1572
1573     if (SUCCEEDED(hr))
1574     {
1575         strcpyW(wszTypesKey, wszClsidSlash);
1576         strcatW(wszTypesKey, wszClsid);
1577         strcatW(wszTypesKey, wszSlash);
1578         strcatW(wszTypesKey, wszPins);
1579         strcatW(wszTypesKey, wszSlash);
1580         strcatW(wszTypesKey, szName);
1581         strcatW(wszTypesKey, wszSlash);
1582         strcatW(wszTypesKey, wszTypes);
1583
1584         lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszTypesKey, 0, KEY_WRITE, &hKey);
1585         hr = HRESULT_FROM_WIN32(lRet);
1586         CoTaskMemFree(wszTypesKey);
1587     }
1588
1589     if (SUCCEEDED(hr))
1590     {
1591         HKEY hkeyDummy = NULL;
1592
1593         strcpyW(wszKeyName, wszClsidMajorType);
1594         strcatW(wszKeyName, wszSlash);
1595         strcatW(wszKeyName, wszClsidSubType);
1596
1597         lRet = RegCreateKeyExW(hKey, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkeyDummy, NULL);
1598         hr = HRESULT_FROM_WIN32(lRet);
1599         CloseHandle(hKey);
1600
1601         if (hkeyDummy) RegCloseKey(hkeyDummy);
1602     }
1603
1604     CoTaskMemFree(wszClsid);
1605     CoTaskMemFree(wszClsidMajorType);
1606     CoTaskMemFree(wszClsidSubType);
1607
1608     return hr;
1609 }
1610
1611 static HRESULT WINAPI FilterMapper_UnregisterFilter(IFilterMapper * iface, CLSID Filter)
1612 {
1613     HRESULT hr;
1614     LONG lRet;
1615     LPWSTR wszClsid = NULL;
1616     HKEY hKey;
1617     WCHAR wszKeyName[ARRAYSIZE(wszClsidSlash)-1 + (CHARS_IN_GUID-1) + 1];
1618
1619     TRACE("(%p)->(%s)\n", iface, debugstr_guid(&Filter));
1620
1621     hr = StringFromCLSID(&Filter, &wszClsid);
1622
1623     if (SUCCEEDED(hr))
1624     {
1625         lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszFilter, 0, KEY_WRITE, &hKey);
1626         hr = HRESULT_FROM_WIN32(lRet);
1627     }
1628
1629     if (SUCCEEDED(hr))
1630     {
1631         lRet = RegDeleteKeyW(hKey, wszClsid);
1632         hr = HRESULT_FROM_WIN32(lRet);
1633         CloseHandle(hKey);
1634     }
1635
1636     if (SUCCEEDED(hr))
1637     {
1638         strcpyW(wszKeyName, wszClsidSlash);
1639         strcatW(wszKeyName, wszClsid);
1640
1641         lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1642         hr = HRESULT_FROM_WIN32(lRet);
1643     }
1644
1645     if (SUCCEEDED(hr))
1646     {
1647         lRet = RegDeleteValueW(hKey, wszMeritName);
1648         if (lRet != ERROR_SUCCESS)
1649             hr = HRESULT_FROM_WIN32(lRet);
1650
1651         lRet = RegDeleteTreeW(hKey, wszPins);
1652         if (lRet != ERROR_SUCCESS)
1653             hr = HRESULT_FROM_WIN32(lRet);
1654
1655         CloseHandle(hKey);
1656     }
1657
1658     CoTaskMemFree(wszClsid);
1659
1660     return hr;
1661 }
1662
1663 static HRESULT WINAPI FilterMapper_UnregisterFilterInstance(IFilterMapper * iface, CLSID MRId)
1664 {
1665     TRACE("(%p)->(%s)\n", iface, debugstr_guid(&MRId));
1666
1667     /* Not implemented in Windows (tested on Win2k) */
1668
1669     return E_NOTIMPL;
1670 }
1671
1672 static HRESULT WINAPI FilterMapper_UnregisterPin(IFilterMapper * iface, CLSID Filter, LPCWSTR Name)
1673 {
1674     HRESULT hr;
1675     LONG lRet;
1676     LPWSTR wszClsid = NULL;
1677     HKEY hKey = NULL;
1678     WCHAR * wszPinNameKey;
1679     WCHAR wszKeyName[ARRAYSIZE(wszClsidSlash)-1 + (CHARS_IN_GUID-1) + 1];
1680
1681     TRACE("(%p)->(%s, %s)\n", iface, debugstr_guid(&Filter), debugstr_w(Name));
1682
1683     if (!Name)
1684         return E_INVALIDARG;
1685
1686     hr = StringFromCLSID(&Filter, &wszClsid);
1687
1688     if (SUCCEEDED(hr))
1689     {
1690         strcpyW(wszKeyName, wszClsidSlash);
1691         strcatW(wszKeyName, wszClsid);
1692
1693         lRet = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey);
1694         hr = HRESULT_FROM_WIN32(lRet);
1695     }
1696
1697     if (SUCCEEDED(hr))
1698     {
1699         wszPinNameKey = CoTaskMemAlloc((strlenW(wszPins) + 1 + strlenW(Name) + 1) * 2);
1700         if (!wszPinNameKey)
1701             hr = E_OUTOFMEMORY;
1702     }
1703
1704     if (SUCCEEDED(hr))
1705     {
1706         strcpyW(wszPinNameKey, wszPins);
1707         strcatW(wszPinNameKey, wszSlash);
1708         strcatW(wszPinNameKey, Name);
1709
1710         lRet = RegDeleteTreeW(hKey, wszPinNameKey);
1711         hr = HRESULT_FROM_WIN32(lRet);
1712         CoTaskMemFree(wszPinNameKey);
1713     }
1714
1715     CoTaskMemFree(wszClsid);
1716     if (hKey)
1717         CloseHandle(hKey);
1718
1719     return hr;
1720 }
1721
1722 static const IFilterMapperVtbl fmvtbl =
1723 {
1724
1725     FilterMapper_QueryInterface,
1726     FilterMapper_AddRef,
1727     FilterMapper_Release,
1728
1729     FilterMapper_RegisterFilter,
1730     FilterMapper_RegisterFilterInstance,
1731     FilterMapper_RegisterPin,
1732     FilterMapper_RegisterPinType,
1733     FilterMapper_UnregisterFilter,
1734     FilterMapper_UnregisterFilterInstance,
1735     FilterMapper_UnregisterPin,
1736     FilterMapper_EnumMatchingFilters
1737 };
1738
1739
1740 /*** IUnknown methods ***/
1741 static HRESULT WINAPI AMFilterData_QueryInterface(IAMFilterData * iface, REFIID riid, LPVOID *ppv)
1742 {
1743     FilterMapper2Impl *This = impl_from_IAMFilterData(iface);
1744
1745     return FilterMapper2_QueryInterface((IFilterMapper2*)This, riid, ppv);
1746 }
1747
1748 static ULONG WINAPI AMFilterData_AddRef(IAMFilterData * iface)
1749 {
1750     FilterMapper2Impl *This = impl_from_IAMFilterData(iface);
1751
1752     return FilterMapper2_AddRef((IFilterMapper2*)This);
1753 }
1754
1755 static ULONG WINAPI AMFilterData_Release(IAMFilterData * iface)
1756 {
1757     FilterMapper2Impl *This = impl_from_IAMFilterData(iface);
1758
1759     return FilterMapper2_Release((IFilterMapper2*)This);
1760 }
1761
1762 /*** IAMFilterData methods ***/
1763 static HRESULT WINAPI AMFilterData_ParseFilterData(IAMFilterData* iface,
1764                                                    BYTE *pData, ULONG cb,
1765                                                    BYTE **ppRegFilter2)
1766 {
1767     FilterMapper2Impl *This = impl_from_IAMFilterData(iface);
1768     HRESULT hr = S_OK;
1769     REGFILTER2 *prf2;
1770
1771     TRACE("(%p/%p)->(%p, %d, %p)\n", This, iface, pData, cb, ppRegFilter2);
1772
1773     prf2 = CoTaskMemAlloc(sizeof(*prf2));
1774     if (!prf2)
1775         return E_OUTOFMEMORY;
1776     *ppRegFilter2 = (BYTE *)&prf2;
1777
1778     hr = FM2_ReadFilterData(pData, prf2);
1779     if (FAILED(hr))
1780     {
1781         CoTaskMemFree(prf2);
1782         *ppRegFilter2 = NULL;
1783     }
1784
1785     return hr;
1786 }
1787
1788 static HRESULT WINAPI AMFilterData_CreateFilterData(IAMFilterData* iface,
1789                                                     REGFILTER2 *prf2,
1790                                                     BYTE **pRegFilterData,
1791                                                     ULONG *pcb)
1792 {
1793     FilterMapper2Impl *This = impl_from_IAMFilterData(iface);
1794
1795     TRACE("(%p/%p)->(%p, %p, %p)\n", This, iface, prf2, pRegFilterData, pcb);
1796
1797     return FM2_WriteFilterData(prf2, pRegFilterData, pcb);
1798 }
1799
1800 static const IAMFilterDataVtbl AMFilterDataVtbl = {
1801     AMFilterData_QueryInterface,
1802     AMFilterData_AddRef,
1803     AMFilterData_Release,
1804     AMFilterData_ParseFilterData,
1805     AMFilterData_CreateFilterData
1806 };