Replace the ICOM_THIS_From macros by inline functions.
[wine/multimedia.git] / dlls / quartz / filtermapper.c
blobe287af3031da7f33ffc4333904ffb391b2083a6d
1 /*
2 * IFilterMapper & IFilterMapper2 Implementations
4 * Copyright 2003 Robert Shearman
5 * Copyright 2004 Christian Costa
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "winerror.h"
32 #include "quartz_private.h"
34 #define COM_NO_WINDOWS_H
35 #include "ole2.h"
36 #include "olectl.h"
37 #include "strmif.h"
38 #include "wine/unicode.h"
39 #include "uuids.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
45 typedef struct FilterMapper2Impl
47 const IFilterMapper2Vtbl *lpVtbl;
48 const IFilterMapperVtbl *lpVtblFilterMapper;
49 LONG refCount;
50 } FilterMapper2Impl;
52 static const IFilterMapper2Vtbl fm2vtbl;
53 static const IFilterMapperVtbl fmvtbl;
55 static inline FilterMapper2Impl *impl_from_IFilterMapper( IFilterMapper *iface )
57 return (FilterMapper2Impl *)((char*)iface - FIELD_OFFSET(FilterMapper2Impl, lpVtblFilterMapper));
60 static const WCHAR wszClsidSlash[] = {'C','L','S','I','D','\\',0};
61 static const WCHAR wszSlashInstance[] = {'\\','I','n','s','t','a','n','c','e','\\',0};
62 static const WCHAR wszSlash[] = {'\\',0};
64 /* CLSID property in media category Moniker */
65 static const WCHAR wszClsidName[] = {'C','L','S','I','D',0};
66 /* FriendlyName property in media category Moniker */
67 static const WCHAR wszFriendlyName[] = {'F','r','i','e','n','d','l','y','N','a','m','e',0};
68 /* Merit property in media category Moniker (CLSID_ActiveMovieCategories only) */
69 static const WCHAR wszMeritName[] = {'M','e','r','i','t',0};
70 /* FilterData property in media category Moniker (not CLSID_ActiveMovieCategories) */
71 static const WCHAR wszFilterDataName[] = {'F','i','l','t','e','r','D','a','t','a',0};
72 /* For filters registered with IFilterMapper */
73 static const WCHAR wszFilterSlash[] = {'F','i','l','t','e','r','\\',0};
74 static const WCHAR wszFilter[] = {'F','i','l','t','e','r',0};
75 /* For pins registered with IFilterMapper */
76 static const WCHAR wszPins[] = {'P','i','n','s',0};
77 static const WCHAR wszAllowedMany[] = {'A','l','l','o','w','e','d','M','a','n','y',0};
78 static const WCHAR wszAllowedZero[] = {'A','l','l','o','w','e','d','Z','e','r','o',0};
79 static const WCHAR wszDirection[] = {'D','i','r','e','c','t','i','o','n',0};
80 static const WCHAR wszIsRendered[] = {'I','s','R','e','n','d','e','r','e','d',0};
81 /* For types registered with IFilterMapper */
82 static const WCHAR wszTypes[] = {'T','y','p','e','s',0};
85 /* registry format for REGFILTER2 */
86 struct REG_RF
88 DWORD dwVersion;
89 DWORD dwMerit;
90 DWORD dwPins;
91 DWORD dwUnused;
94 struct REG_RFP
96 BYTE signature[4]; /* e.g. "0pi3" */
97 DWORD dwFlags;
98 DWORD dwInstances;
99 DWORD dwMediaTypes;
100 DWORD dwMediums;
101 DWORD bCategory; /* is there a category clsid? */
102 /* optional: dwOffsetCategoryClsid */
105 struct REG_TYPE
107 BYTE signature[4]; /* e.g. "0ty3" */
108 DWORD dwUnused;
109 DWORD dwOffsetMajor;
110 DWORD dwOffsetMinor;
113 struct MONIKER_MERIT
115 IMoniker * pMoniker;
116 DWORD dwMerit;
119 struct Vector
121 LPBYTE pData;
122 int capacity; /* in bytes */
123 int current; /* pointer to next free byte */
126 /* returns the position it was added at */
127 static int add_data(struct Vector * v, const BYTE * pData, int size)
129 int index = v->current;
130 if (v->current + size > v->capacity)
132 LPBYTE pOldData = v->pData;
133 v->capacity = (v->capacity + size) * 2;
134 v->pData = CoTaskMemAlloc(v->capacity);
135 memcpy(v->pData, pOldData, v->current);
136 CoTaskMemFree(pOldData);
138 memcpy(v->pData + v->current, pData, size);
139 v->current += size;
140 return index;
143 static int find_data(struct Vector * v, const BYTE * pData, int size)
145 int index;
146 for (index = 0; index < v->current; index++)
147 if (!memcmp(v->pData + index, pData, size))
148 return index;
149 /* not found */
150 return -1;
153 static void delete_vector(struct Vector * v)
155 if (v->pData)
156 CoTaskMemFree(v->pData);
157 v->current = 0;
158 v->capacity = 0;
161 HRESULT FilterMapper2_create(IUnknown *pUnkOuter, LPVOID *ppObj)
163 FilterMapper2Impl * pFM2impl;
165 TRACE("(%p, %p)\n", pUnkOuter, ppObj);
167 if (pUnkOuter)
168 return CLASS_E_NOAGGREGATION;
170 pFM2impl = CoTaskMemAlloc(sizeof(*pFM2impl));
171 if (!pFM2impl)
172 return E_OUTOFMEMORY;
174 pFM2impl->lpVtbl = &fm2vtbl;
175 pFM2impl->lpVtblFilterMapper = &fmvtbl;
176 pFM2impl->refCount = 1;
178 *ppObj = pFM2impl;
180 TRACE("-- created at %p\n", pFM2impl);
182 return S_OK;
185 /*** IUnknown methods ***/
187 static HRESULT WINAPI FilterMapper2_QueryInterface(IFilterMapper2 * iface, REFIID riid, LPVOID *ppv)
189 FilterMapper2Impl *This = (FilterMapper2Impl *)iface;
191 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
193 *ppv = NULL;
195 if (IsEqualIID(riid, &IID_IUnknown))
196 *ppv = iface;
197 else if (IsEqualIID(riid, &IID_IFilterMapper2))
198 *ppv = iface;
199 else if (IsEqualIID(riid, &IID_IFilterMapper))
200 *ppv = &This->lpVtblFilterMapper;
202 if (*ppv != NULL)
204 IUnknown_AddRef((IUnknown *)*ppv);
205 return S_OK;
208 FIXME("No interface for %s\n", debugstr_guid(riid));
209 return E_NOINTERFACE;
212 static ULONG WINAPI FilterMapper2_AddRef(IFilterMapper2 * iface)
214 FilterMapper2Impl *This = (FilterMapper2Impl *)iface;
215 ULONG refCount = InterlockedIncrement(&This->refCount);
217 TRACE("(%p)->()\n", iface);
219 return refCount;
222 static ULONG WINAPI FilterMapper2_Release(IFilterMapper2 * iface)
224 FilterMapper2Impl *This = (FilterMapper2Impl *)iface;
225 ULONG refCount = InterlockedDecrement(&This->refCount);
227 TRACE("(%p)->()\n", iface);
229 if (refCount == 0)
231 CoTaskMemFree(This);
232 return 0;
234 return refCount;
237 /*** IFilterMapper2 methods ***/
239 static HRESULT WINAPI FilterMapper2_CreateCategory(
240 IFilterMapper2 * iface,
241 REFCLSID clsidCategory,
242 DWORD dwCategoryMerit,
243 LPCWSTR szDescription)
245 LPWSTR wClsidAMCat = NULL;
246 LPWSTR wClsidCategory = NULL;
247 WCHAR wszKeyName[strlenW(wszClsidSlash) + strlenW(wszSlashInstance) + (CHARS_IN_GUID-1) * 2 + 1];
248 HKEY hKey = NULL;
249 HRESULT hr;
251 TRACE("(%s, %lx, %s)\n", debugstr_guid(clsidCategory), dwCategoryMerit, debugstr_w(szDescription));
253 hr = StringFromCLSID(&CLSID_ActiveMovieCategories, &wClsidAMCat);
255 if (SUCCEEDED(hr))
257 hr = StringFromCLSID(clsidCategory, &wClsidCategory);
260 if (SUCCEEDED(hr))
262 strcpyW(wszKeyName, wszClsidSlash);
263 strcatW(wszKeyName, wClsidAMCat);
264 strcatW(wszKeyName, wszSlashInstance);
265 strcatW(wszKeyName, wClsidCategory);
267 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL));
270 if (SUCCEEDED(hr))
272 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, wszFriendlyName, 0, REG_SZ, (const BYTE*)szDescription, (strlenW(szDescription) + 1) * sizeof(WCHAR)));
275 if (SUCCEEDED(hr))
277 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, wszClsidName, 0, REG_SZ, (LPBYTE)wClsidCategory, (strlenW(wClsidCategory) + 1) * sizeof(WCHAR)));
280 if (SUCCEEDED(hr))
282 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwCategoryMerit, sizeof(dwCategoryMerit)));
285 CloseHandle(hKey);
287 if (wClsidCategory)
288 CoTaskMemFree(wClsidCategory);
289 if (wClsidAMCat)
290 CoTaskMemFree(wClsidAMCat);
292 return hr;
295 static HRESULT WINAPI FilterMapper2_UnregisterFilter(
296 IFilterMapper2 * iface,
297 const CLSID *pclsidCategory,
298 const OLECHAR *szInstance,
299 REFCLSID Filter)
301 WCHAR wszKeyName[MAX_PATH];
302 LPWSTR wClsidCategory = NULL;
303 LPWSTR wFilter = NULL;
304 HRESULT hr;
306 TRACE("(%p, %s, %s)\n", pclsidCategory, debugstr_w(szInstance), debugstr_guid(Filter));
308 if (!pclsidCategory)
309 pclsidCategory = &CLSID_LegacyAmFilterCategory;
311 hr = StringFromCLSID(pclsidCategory, &wClsidCategory);
313 if (SUCCEEDED(hr))
315 strcpyW(wszKeyName, wszClsidSlash);
316 strcatW(wszKeyName, wClsidCategory);
317 strcatW(wszKeyName, wszSlashInstance);
318 if (szInstance)
319 strcatW(wszKeyName, szInstance);
320 else
322 hr = StringFromCLSID(Filter, &wFilter);
323 if (SUCCEEDED(hr))
324 strcatW(wszKeyName, wFilter);
328 if (SUCCEEDED(hr))
330 hr = HRESULT_FROM_WIN32(RegDeleteKeyW(HKEY_CLASSES_ROOT, wszKeyName));
333 if (wClsidCategory)
334 CoTaskMemFree(wClsidCategory);
335 if (wFilter)
336 CoTaskMemFree(wFilter);
338 return hr;
341 static HRESULT FM2_WriteFriendlyName(IPropertyBag * pPropBag, LPCWSTR szName)
343 VARIANT var;
345 V_VT(&var) = VT_BSTR;
346 V_UNION(&var, bstrVal) = (BSTR)szName;
348 return IPropertyBag_Write(pPropBag, wszFriendlyName, &var);
351 static HRESULT FM2_WriteClsid(IPropertyBag * pPropBag, REFCLSID clsid)
353 LPWSTR wszClsid = NULL;
354 VARIANT var;
355 HRESULT hr;
357 hr = StringFromCLSID(clsid, &wszClsid);
359 if (SUCCEEDED(hr))
361 V_VT(&var) = VT_BSTR;
362 V_UNION(&var, bstrVal) = wszClsid;
363 hr = IPropertyBag_Write(pPropBag, wszClsidName, &var);
365 if (wszClsid)
366 CoTaskMemFree(wszClsid);
367 return hr;
370 static HRESULT FM2_WriteFilterData(IPropertyBag * pPropBag, const REGFILTER2 * prf2)
372 VARIANT var;
373 int size = sizeof(struct REG_RF);
374 unsigned int i;
375 struct Vector mainStore = {NULL, 0, 0};
376 struct Vector clsidStore = {NULL, 0, 0};
377 struct REG_RF rrf;
378 SAFEARRAY * psa;
379 SAFEARRAYBOUND saBound;
380 HRESULT hr = S_OK;
382 rrf.dwVersion = prf2->dwVersion;
383 rrf.dwMerit = prf2->dwMerit;
384 rrf.dwPins = prf2->u.s1.cPins2;
385 rrf.dwUnused = 0;
387 add_data(&mainStore, (LPBYTE)&rrf, sizeof(rrf));
389 for (i = 0; i < prf2->u.s1.cPins2; i++)
391 size += sizeof(struct REG_RFP);
392 if (prf2->u.s1.rgPins2[i].clsPinCategory)
393 size += sizeof(DWORD);
394 size += prf2->u.s1.rgPins2[i].nMediaTypes * sizeof(struct REG_TYPE);
395 size += prf2->u.s1.rgPins2[i].nMediums * sizeof(DWORD);
398 for (i = 0; i < prf2->u.s1.cPins2; i++)
400 struct REG_RFP rrfp;
401 REGFILTERPINS2 rgPin2 = prf2->u.s1.rgPins2[i];
402 unsigned int j;
404 rrfp.signature[0] = '0';
405 rrfp.signature[1] = 'p';
406 rrfp.signature[2] = 'i';
407 rrfp.signature[3] = '3';
408 rrfp.signature[0] += i;
409 rrfp.dwFlags = rgPin2.dwFlags;
410 rrfp.dwInstances = rgPin2.cInstances;
411 rrfp.dwMediaTypes = rgPin2.nMediaTypes;
412 rrfp.dwMediums = rgPin2.nMediums;
413 rrfp.bCategory = rgPin2.clsPinCategory ? 1 : 0;
415 add_data(&mainStore, (LPBYTE)&rrfp, sizeof(rrfp));
416 if (rrfp.bCategory)
418 DWORD index = find_data(&clsidStore, (const BYTE*)rgPin2.clsPinCategory, sizeof(CLSID));
419 if (index == -1)
420 index = add_data(&clsidStore, (const BYTE*)rgPin2.clsPinCategory, sizeof(CLSID));
421 index += size;
423 add_data(&mainStore, (LPBYTE)&index, sizeof(index));
426 for (j = 0; j < rgPin2.nMediaTypes; j++)
428 struct REG_TYPE rt;
429 rt.signature[0] = '0';
430 rt.signature[1] = 't';
431 rt.signature[2] = 'y';
432 rt.signature[3] = '3';
433 rt.signature[0] += j;
435 rt.dwUnused = 0;
436 rt.dwOffsetMajor = find_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
437 if (rt.dwOffsetMajor == -1)
438 rt.dwOffsetMajor = add_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMajorType, sizeof(CLSID));
439 rt.dwOffsetMajor += size;
440 rt.dwOffsetMinor = find_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMinorType, sizeof(CLSID));
441 if (rt.dwOffsetMinor == -1)
442 rt.dwOffsetMinor = add_data(&clsidStore, (const BYTE*)rgPin2.lpMediaType[j].clsMinorType, sizeof(CLSID));
443 rt.dwOffsetMinor += size;
445 add_data(&mainStore, (LPBYTE)&rt, sizeof(rt));
448 for (j = 0; j < rgPin2.nMediums; j++)
450 DWORD index = find_data(&clsidStore, (const BYTE*)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
451 if (index == -1)
452 index = add_data(&clsidStore, (const BYTE*)(rgPin2.lpMedium + j), sizeof(REGPINMEDIUM));
453 index += size;
455 add_data(&mainStore, (LPBYTE)&index, sizeof(index));
459 saBound.lLbound = 0;
460 saBound.cElements = mainStore.current + clsidStore.current;
461 psa = SafeArrayCreate(VT_UI1, 1, &saBound);
462 if (!psa)
464 ERR("Couldn't create SAFEARRAY\n");
465 hr = E_FAIL;
468 if (SUCCEEDED(hr))
470 LPBYTE pbSAData;
471 hr = SafeArrayAccessData(psa, (LPVOID *)&pbSAData);
472 if (SUCCEEDED(hr))
474 memcpy(pbSAData, mainStore.pData, mainStore.current);
475 memcpy(pbSAData + mainStore.current, clsidStore.pData, clsidStore.current);
476 hr = SafeArrayUnaccessData(psa);
480 V_VT(&var) = VT_ARRAY | VT_UI1;
481 V_UNION(&var, parray) = psa;
483 if (SUCCEEDED(hr))
484 hr = IPropertyBag_Write(pPropBag, wszFilterDataName, &var);
486 if (psa)
487 SafeArrayDestroy(psa);
489 delete_vector(&mainStore);
490 delete_vector(&clsidStore);
491 return hr;
494 static HRESULT FM2_ReadFilterData(IPropertyBag * pPropBag, REGFILTER2 * prf2)
496 VARIANT var;
497 HRESULT hr;
498 LPBYTE pData = NULL;
499 struct REG_RF * prrf;
500 LPBYTE pCurrent;
501 DWORD i;
502 REGFILTERPINS2 * rgPins2;
504 VariantInit(&var);
505 V_VT(&var) = VT_ARRAY | VT_UI1;
507 hr = IPropertyBag_Read(pPropBag, wszFilterDataName, &var, NULL);
509 if (SUCCEEDED(hr))
510 hr = SafeArrayAccessData(V_UNION(&var, parray), (LPVOID*)&pData);
512 if (SUCCEEDED(hr))
514 prrf = (struct REG_RF *)pData;
515 pCurrent = pData;
517 if (prrf->dwVersion != 2)
519 FIXME("Filter registry version %ld not supported\n", prrf->dwVersion);
520 ZeroMemory(prf2, sizeof(*prf2));
521 hr = E_FAIL;
525 if (SUCCEEDED(hr))
527 TRACE("version = %ld, merit = %lx, #pins = %ld, unused = %lx\n",
528 prrf->dwVersion, prrf->dwMerit, prrf->dwPins, prrf->dwUnused);
530 prf2->dwVersion = prrf->dwVersion;
531 prf2->dwMerit = prrf->dwMerit;
532 prf2->u.s1.cPins2 = prrf->dwPins;
533 rgPins2 = CoTaskMemAlloc(prrf->dwPins * sizeof(*rgPins2));
534 prf2->u.s1.rgPins2 = rgPins2;
535 pCurrent += sizeof(struct REG_RF);
537 for (i = 0; i < prrf->dwPins; i++)
539 struct REG_RFP * prrfp = (struct REG_RFP *)pCurrent;
540 REGPINTYPES * lpMediaType;
541 REGPINMEDIUM * lpMedium;
542 UINT j;
544 /* FIXME: check signature */
546 TRACE("\tsignature = %s\n", debugstr_an(prrfp->signature, 4));
548 TRACE("\tpin[%ld]: flags = %lx, instances = %ld, media types = %ld, mediums = %ld\n",
549 i, prrfp->dwFlags, prrfp->dwInstances, prrfp->dwMediaTypes, prrfp->dwMediums);
551 rgPins2[i].dwFlags = prrfp->dwFlags;
552 rgPins2[i].cInstances = prrfp->dwInstances;
553 rgPins2[i].nMediaTypes = prrfp->dwMediaTypes;
554 rgPins2[i].nMediums = prrfp->dwMediums;
555 pCurrent += sizeof(struct REG_RFP);
556 if (prrfp->bCategory)
558 CLSID * clsCat = CoTaskMemAlloc(sizeof(CLSID));
559 memcpy(clsCat, pData + *(DWORD*)(pCurrent), sizeof(CLSID));
560 pCurrent += sizeof(DWORD);
561 rgPins2[i].clsPinCategory = clsCat;
563 else
564 rgPins2[i].clsPinCategory = NULL;
566 if (rgPins2[i].nMediaTypes > 0)
567 lpMediaType = CoTaskMemAlloc(rgPins2[i].nMediaTypes * sizeof(*lpMediaType));
568 else
569 lpMediaType = NULL;
571 rgPins2[i].lpMediaType = lpMediaType;
573 for (j = 0; j < rgPins2[i].nMediaTypes; j++)
575 struct REG_TYPE * prt = (struct REG_TYPE *)pCurrent;
576 CLSID * clsMajor = CoTaskMemAlloc(sizeof(CLSID));
577 CLSID * clsMinor = CoTaskMemAlloc(sizeof(CLSID));
579 /* FIXME: check signature */
580 TRACE("\t\tsignature = %s\n", debugstr_an(prt->signature, 4));
582 memcpy(clsMajor, pData + prt->dwOffsetMajor, sizeof(CLSID));
583 memcpy(clsMinor, pData + prt->dwOffsetMinor, sizeof(CLSID));
585 lpMediaType[j].clsMajorType = clsMajor;
586 lpMediaType[j].clsMinorType = clsMinor;
588 pCurrent += sizeof(*prt);
591 if (rgPins2[i].nMediums > 0)
592 lpMedium = CoTaskMemAlloc(rgPins2[i].nMediums * sizeof(*lpMedium));
593 else
594 lpMedium = NULL;
596 rgPins2[i].lpMedium = lpMedium;
598 for (j = 0; j < rgPins2[i].nMediums; j++)
600 DWORD dwOffset = *(DWORD *)pCurrent;
602 memcpy(lpMedium + j, pData + dwOffset, sizeof(REGPINMEDIUM));
604 pCurrent += sizeof(dwOffset);
610 if (pData)
611 SafeArrayUnaccessData(V_UNION(&var, parray));
613 VariantClear(&var);
615 return hr;
618 static void FM2_DeleteRegFilter(REGFILTER2 * prf2)
620 UINT i;
621 for (i = 0; i < prf2->u.s1.cPins2; i++)
623 UINT j;
624 if (prf2->u.s1.rgPins2[i].clsPinCategory)
625 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].clsPinCategory);
627 for (j = 0; j < prf2->u.s1.rgPins2[i].nMediaTypes; j++)
629 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMajorType);
630 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMediaType[j].clsMinorType);
632 CoTaskMemFree((LPVOID)prf2->u.s1.rgPins2[i].lpMedium);
636 static HRESULT WINAPI FilterMapper2_RegisterFilter(
637 IFilterMapper2 * iface,
638 REFCLSID clsidFilter,
639 LPCWSTR szName,
640 IMoniker **ppMoniker,
641 const CLSID *pclsidCategory,
642 const OLECHAR *szInstance,
643 const REGFILTER2 *prf2)
645 IParseDisplayName * pParser = NULL;
646 IBindCtx * pBindCtx = NULL;
647 IMoniker * pMoniker = NULL;
648 IPropertyBag * pPropBag = NULL;
649 HRESULT hr;
650 LPWSTR pwszParseName = NULL;
651 LPWSTR pCurrent;
652 static const WCHAR wszDevice[] = {'@','d','e','v','i','c','e',':','s','w',':',0};
653 int nameLen;
654 ULONG ulEaten;
655 LPWSTR szClsidTemp = NULL;
656 REGFILTER2 regfilter2;
657 REGFILTERPINS2* pregfp2 = NULL;
659 TRACE("(%s, %s, %p, %s, %s, %p)\n",
660 debugstr_guid(clsidFilter),
661 debugstr_w(szName),
662 ppMoniker,
663 debugstr_guid(pclsidCategory),
664 debugstr_w(szInstance),
665 prf2);
667 if (prf2->dwVersion == 2)
669 regfilter2 = *prf2;
671 else if (prf2->dwVersion == 1)
673 ULONG i;
674 DWORD flags;
675 /* REGFILTER2 structure is converted from version 1 to 2. Tested on Win2k. */
676 regfilter2.dwVersion = 2;
677 regfilter2.dwMerit = prf2->dwMerit;
678 regfilter2.u.s1.cPins2 = prf2->u.s.cPins;
679 pregfp2 = (REGFILTERPINS2*) CoTaskMemAlloc(prf2->u.s.cPins * sizeof(REGFILTERPINS2));
680 regfilter2.u.s1.rgPins2 = pregfp2;
681 for (i = 0; i < prf2->u.s.cPins; i++)
683 flags = 0;
684 if (prf2->u.s.rgPins[i].bRendered)
685 flags |= REG_PINFLAG_B_RENDERER;
686 if (prf2->u.s.rgPins[i].bOutput)
687 flags |= REG_PINFLAG_B_OUTPUT;
688 if (prf2->u.s.rgPins[i].bZero)
689 flags |= REG_PINFLAG_B_ZERO;
690 if (prf2->u.s.rgPins[i].bMany)
691 flags |= REG_PINFLAG_B_MANY;
692 pregfp2[i].dwFlags = flags;
693 pregfp2[i].cInstances = 1;
694 pregfp2[i].nMediaTypes = prf2->u.s.rgPins[i].nMediaTypes;
695 pregfp2[i].lpMediaType = prf2->u.s.rgPins[i].lpMediaType;
696 pregfp2[i].nMediums = 0;
697 pregfp2[i].lpMedium = NULL;
698 pregfp2[i].clsPinCategory = NULL;
701 else
703 FIXME("dwVersion other that 1 or 2 not supported at the moment\n");
704 return E_NOTIMPL;
707 if (ppMoniker)
708 *ppMoniker = NULL;
710 if (!pclsidCategory)
711 /* MSDN mentions the inexistent CLSID_ActiveMovieFilters GUID.
712 * In fact this is the CLSID_LegacyAmFilterCategory one */
713 pclsidCategory = &CLSID_LegacyAmFilterCategory;
715 /* sizeof... will include the null terminator and
716 * the + 1 is for the separator ('\\'). The -1 is
717 * because CHARS_IN_GUID includes the null terminator
719 nameLen = sizeof(wszDevice)/sizeof(wszDevice[0]) + CHARS_IN_GUID - 1 + 1;
721 if (szInstance)
722 nameLen += strlenW(szInstance);
723 else
724 nameLen += CHARS_IN_GUID - 1; /* CHARS_IN_GUID includes null terminator */
726 pCurrent = pwszParseName = CoTaskMemAlloc(nameLen*sizeof(WCHAR));
727 if (!pwszParseName)
728 return E_OUTOFMEMORY;
730 strcpyW(pwszParseName, wszDevice);
731 pCurrent += strlenW(wszDevice);
733 hr = StringFromCLSID(pclsidCategory, &szClsidTemp);
735 if (SUCCEEDED(hr))
737 memcpy(pCurrent, szClsidTemp, CHARS_IN_GUID * sizeof(WCHAR));
738 pCurrent += CHARS_IN_GUID - 1;
739 pCurrent[0] = '\\';
741 if (szInstance)
742 strcpyW(pCurrent+1, szInstance);
743 else
745 if (szClsidTemp)
747 CoTaskMemFree(szClsidTemp);
748 szClsidTemp = NULL;
750 hr = StringFromCLSID(clsidFilter, &szClsidTemp);
751 if (SUCCEEDED(hr))
752 strcpyW(pCurrent+1, szClsidTemp);
756 if (SUCCEEDED(hr))
757 hr = CoCreateInstance(&CLSID_CDeviceMoniker, NULL, CLSCTX_INPROC, &IID_IParseDisplayName, (LPVOID *)&pParser);
759 if (SUCCEEDED(hr))
760 hr = CreateBindCtx(0, &pBindCtx);
762 if (SUCCEEDED(hr))
763 hr = IParseDisplayName_ParseDisplayName(pParser, pBindCtx, pwszParseName, &ulEaten, &pMoniker);
765 if (pBindCtx)
766 IBindCtx_Release(pBindCtx);
767 if (pParser)
768 IParseDisplayName_Release(pParser);
770 if (SUCCEEDED(hr))
771 hr = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID)&pPropBag);
773 if (SUCCEEDED(hr))
774 hr = FM2_WriteFriendlyName(pPropBag, szName);
776 if (SUCCEEDED(hr))
777 hr = FM2_WriteClsid(pPropBag, clsidFilter);
779 if (SUCCEEDED(hr))
780 hr = FM2_WriteFilterData(pPropBag, &regfilter2);
782 if (pPropBag)
783 IPropertyBag_Release(pPropBag);
784 if (szClsidTemp)
785 CoTaskMemFree(szClsidTemp);
787 if (SUCCEEDED(hr) && ppMoniker)
788 *ppMoniker = pMoniker;
789 else if (pMoniker)
790 IMoniker_Release(pMoniker);
792 if (pregfp2)
793 CoTaskMemFree(pregfp2);
795 TRACE("-- returning %lx\n", hr);
797 return hr;
800 /* internal helper function */
801 static BOOL MatchTypes(
802 BOOL bExactMatch,
803 DWORD nPinTypes,
804 const REGPINTYPES * pPinTypes,
805 DWORD nMatchTypes,
806 const GUID * pMatchTypes)
808 BOOL bMatch = FALSE;
809 DWORD j;
811 if ((nMatchTypes == 0) && (nPinTypes > 0))
812 bMatch = TRUE;
814 for (j = 0; j < nPinTypes; j++)
816 DWORD i;
817 for (i = 0; i < nMatchTypes*2; i+=2)
819 if (((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMajorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMajorType, &pMatchTypes[i])) &&
820 ((!bExactMatch && IsEqualGUID(pPinTypes[j].clsMinorType, &GUID_NULL)) || IsEqualGUID(&pMatchTypes[i+1], &GUID_NULL) || IsEqualGUID(pPinTypes[j].clsMinorType, &pMatchTypes[i+1])))
822 bMatch = TRUE;
823 break;
827 return bMatch;
830 /* internal helper function for qsort of MONIKER_MERIT array */
831 static int mm_compare(const void * left, const void * right)
833 const struct MONIKER_MERIT * mmLeft = (const struct MONIKER_MERIT *)left;
834 const struct MONIKER_MERIT * mmRight = (const struct MONIKER_MERIT *)right;
836 if (mmLeft->dwMerit == mmRight->dwMerit)
837 return 0;
838 if (mmLeft->dwMerit > mmRight->dwMerit)
839 return -1;
840 return 1;
843 /* NOTES:
844 * Exact match means whether or not to treat GUID_NULL's in filter data as wild cards
845 * (GUID_NULL's in input to function automatically treated as wild cards)
846 * Input/Output needed means match only on criteria if TRUE (with zero input types
847 * meaning match any input/output pin as long as one exists), otherwise match any
848 * filter that meets the rest of the requirements.
850 static HRESULT WINAPI FilterMapper2_EnumMatchingFilters(
851 IFilterMapper2 * iface,
852 IEnumMoniker **ppEnum,
853 DWORD dwFlags,
854 BOOL bExactMatch,
855 DWORD dwMerit,
856 BOOL bInputNeeded,
857 DWORD cInputTypes,
858 const GUID *pInputTypes,
859 const REGPINMEDIUM *pMedIn,
860 const CLSID *pPinCategoryIn,
861 BOOL bRender,
862 BOOL bOutputNeeded,
863 DWORD cOutputTypes,
864 const GUID *pOutputTypes,
865 const REGPINMEDIUM *pMedOut,
866 const CLSID *pPinCategoryOut)
868 ICreateDevEnum * pCreateDevEnum;
869 IMoniker * pMonikerCat;
870 IEnumMoniker * pEnumCat;
871 HRESULT hr;
872 struct Vector monikers = {NULL, 0, 0};
874 TRACE("(%p, %lx, %s, %lx, %s, %ld, %p, %p, %p, %s, %s, %p, %p, %p)\n",
875 ppEnum,
876 dwFlags,
877 bExactMatch ? "true" : "false",
878 dwMerit,
879 bInputNeeded ? "true" : "false",
880 cInputTypes,
881 pInputTypes,
882 pMedIn,
883 pPinCategoryIn,
884 bRender ? "true" : "false",
885 bOutputNeeded ? "true" : "false",
886 pOutputTypes,
887 pMedOut,
888 pPinCategoryOut);
890 if (dwFlags != 0)
892 FIXME("dwFlags = %lx not implemented\n", dwFlags);
895 *ppEnum = NULL;
897 hr = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, &IID_ICreateDevEnum, (LPVOID*)&pCreateDevEnum);
899 if (SUCCEEDED(hr))
900 hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &CLSID_ActiveMovieCategories, &pEnumCat, 0);
902 while (IEnumMoniker_Next(pEnumCat, 1, &pMonikerCat, NULL) == S_OK)
904 IPropertyBag * pPropBagCat = NULL;
905 VARIANT var;
906 HRESULT hrSub; /* this is so that one buggy filter
907 doesn't make the whole lot fail */
909 VariantInit(&var);
911 hrSub = IMoniker_BindToStorage(pMonikerCat, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
913 if (SUCCEEDED(hrSub))
914 hrSub = IPropertyBag_Read(pPropBagCat, wszMeritName, &var, NULL);
916 if (SUCCEEDED(hrSub) && (V_UNION(&var, ulVal) >= dwMerit))
918 CLSID clsidCat;
919 IEnumMoniker * pEnum;
920 IMoniker * pMoniker;
922 VariantClear(&var);
924 if (TRACE_ON(quartz))
926 VARIANT temp;
927 V_VT(&temp) = VT_EMPTY;
928 IPropertyBag_Read(pPropBagCat, wszFriendlyName, &temp, NULL);
929 TRACE("Considering category %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
930 VariantClear(&temp);
933 hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
935 if (SUCCEEDED(hrSub))
936 hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsidCat);
938 if (SUCCEEDED(hrSub))
939 hrSub = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum, &clsidCat, &pEnum, 0);
941 if (hrSub == S_OK)
943 while (IEnumMoniker_Next(pEnum, 1, &pMoniker, NULL) == S_OK)
945 IPropertyBag * pPropBag = NULL;
946 REGFILTER2 rf2;
947 DWORD i;
948 BOOL bInputMatch = !bInputNeeded;
949 BOOL bOutputMatch = !bOutputNeeded;
951 ZeroMemory(&rf2, sizeof(rf2));
953 hrSub = IMoniker_BindToStorage(pMoniker, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBag);
955 if (TRACE_ON(quartz))
957 VARIANT temp;
958 V_VT(&temp) = VT_EMPTY;
959 IPropertyBag_Read(pPropBag, wszFriendlyName, &temp, NULL);
960 TRACE("Considering filter %s\n", debugstr_w(V_UNION(&temp, bstrVal)));
961 VariantClear(&temp);
964 if (SUCCEEDED(hrSub))
965 hrSub = FM2_ReadFilterData(pPropBag, &rf2);
967 /* Logic used for bInputMatch expression:
968 * There exists some pin such that bInputNeeded implies (pin is an input and
969 * (bRender implies pin has render flag) and major/minor types members of
970 * pInputTypes )
971 * bOutputMatch is similar, but without the "bRender implies ..." part
972 * and substituting variables names containing input for output
975 /* determine whether filter meets requirements */
976 if (SUCCEEDED(hrSub) && (rf2.dwMerit >= dwMerit))
978 for (i = 0; (i < rf2.u.s1.cPins2) && (!bInputMatch || !bOutputMatch); i++)
980 const REGFILTERPINS2 * rfp2 = rf2.u.s1.rgPins2 + i;
982 bInputMatch = bInputMatch || (!(rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
983 (!bRender || (rfp2->dwFlags & REG_PINFLAG_B_RENDERER)) &&
984 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cInputTypes, pInputTypes));
985 bOutputMatch = bOutputMatch || ((rfp2->dwFlags & REG_PINFLAG_B_OUTPUT) &&
986 MatchTypes(bExactMatch, rfp2->nMediaTypes, rfp2->lpMediaType, cOutputTypes, pOutputTypes));
989 if (bInputMatch && bOutputMatch)
991 struct MONIKER_MERIT mm = {pMoniker, rf2.dwMerit};
992 IMoniker_AddRef(pMoniker);
993 add_data(&monikers, (LPBYTE)&mm, sizeof(mm));
997 FM2_DeleteRegFilter(&rf2);
998 if (pPropBag)
999 IPropertyBag_Release(pPropBag);
1000 IMoniker_Release(pMoniker);
1002 IEnumMoniker_Release(pEnum);
1006 VariantClear(&var);
1007 if (pPropBagCat)
1008 IPropertyBag_Release(pPropBagCat);
1009 IMoniker_Release(pMonikerCat);
1012 if (SUCCEEDED(hr))
1014 IMoniker ** ppMoniker;
1015 unsigned int i;
1016 ULONG nMonikerCount = monikers.current / sizeof(struct MONIKER_MERIT);
1018 /* sort the monikers in descending merit order */
1019 qsort(monikers.pData, nMonikerCount,
1020 sizeof(struct MONIKER_MERIT),
1021 mm_compare);
1023 /* construct an IEnumMoniker interface */
1024 ppMoniker = CoTaskMemAlloc(nMonikerCount * sizeof(IMoniker *));
1025 for (i = 0; i < nMonikerCount; i++)
1027 /* no need to AddRef here as already AddRef'd above */
1028 ppMoniker[i] = ((struct MONIKER_MERIT *)monikers.pData)[i].pMoniker;
1030 hr = EnumMonikerImpl_Create(ppMoniker, nMonikerCount, ppEnum);
1031 CoTaskMemFree(ppMoniker);
1034 delete_vector(&monikers);
1035 IEnumMoniker_Release(pEnumCat);
1036 ICreateDevEnum_Release(pCreateDevEnum);
1038 return hr;
1041 static const IFilterMapper2Vtbl fm2vtbl =
1044 FilterMapper2_QueryInterface,
1045 FilterMapper2_AddRef,
1046 FilterMapper2_Release,
1048 FilterMapper2_CreateCategory,
1049 FilterMapper2_UnregisterFilter,
1050 FilterMapper2_RegisterFilter,
1051 FilterMapper2_EnumMatchingFilters
1054 /*** IUnknown methods ***/
1056 static HRESULT WINAPI FilterMapper_QueryInterface(IFilterMapper * iface, REFIID riid, LPVOID *ppv)
1058 FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1060 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
1062 return FilterMapper2_QueryInterface((IFilterMapper2*)&This->lpVtbl, riid, ppv);
1065 static ULONG WINAPI FilterMapper_AddRef(IFilterMapper * iface)
1067 FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1069 return FilterMapper2_AddRef((IFilterMapper2*)This);
1072 static ULONG WINAPI FilterMapper_Release(IFilterMapper * iface)
1074 FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1076 return FilterMapper2_Release((IFilterMapper2*)This);
1079 /*** IFilterMapper methods ***/
1081 static HRESULT WINAPI FilterMapper_EnumMatchingFilters(
1082 IFilterMapper * iface,
1083 IEnumRegFilters **ppEnum,
1084 DWORD dwMerit,
1085 BOOL bInputNeeded,
1086 CLSID clsInMaj,
1087 CLSID clsInSub,
1088 BOOL bRender,
1089 BOOL bOutputNeeded,
1090 CLSID clsOutMaj,
1091 CLSID clsOutSub)
1093 FilterMapper2Impl *This = impl_from_IFilterMapper(iface);
1094 GUID InputType[2];
1095 GUID OutputType[2];
1096 IEnumMoniker* ppEnumMoniker;
1097 IMoniker* IMon;
1098 ULONG nb;
1099 ULONG idx = 0, nb_mon = 0;
1100 REGFILTER* regfilters;
1101 HRESULT hr;
1103 TRACE("(%p/%p)->(%p, %lx, %s, %s, %s, %s, %s, %s, %s) stub!\n",
1104 iface,This,
1105 ppEnum,
1106 dwMerit,
1107 bInputNeeded ? "true" : "false",
1108 debugstr_guid(&clsInMaj),
1109 debugstr_guid(&clsInSub),
1110 bRender ? "true" : "false",
1111 bOutputNeeded ? "true" : "false",
1112 debugstr_guid(&clsOutMaj),
1113 debugstr_guid(&clsOutSub));
1115 InputType[0] = clsInMaj;
1116 InputType[1] = clsInSub;
1117 OutputType[0] = clsOutMaj;
1118 OutputType[1] = clsOutSub;
1120 hr = IFilterMapper2_EnumMatchingFilters((IFilterMapper2*)This,
1121 &ppEnumMoniker,
1123 TRUE,
1124 dwMerit,
1125 bInputNeeded,
1127 InputType,
1128 NULL,
1129 &GUID_NULL,
1130 bRender,
1131 bOutputNeeded,
1133 OutputType,
1134 NULL,
1135 &GUID_NULL);
1137 if (!SUCCEEDED(hr))
1138 return hr;
1140 while(IEnumMoniker_Next(ppEnumMoniker, 1, &IMon, &nb) == S_OK)
1142 IMoniker_Release(IMon);
1143 nb_mon++;
1146 *ppEnum = NULL;
1147 if (!nb_mon)
1149 IEnumMoniker_Release(ppEnumMoniker);
1150 return IEnumRegFiltersImpl_Construct(NULL, 0, ppEnum);
1153 regfilters = CoTaskMemAlloc(nb_mon * sizeof(REGFILTER));
1154 if (!regfilters)
1156 IEnumMoniker_Release(ppEnumMoniker);
1157 return E_OUTOFMEMORY;
1160 IEnumMoniker_Reset(ppEnumMoniker);
1161 while(IEnumMoniker_Next(ppEnumMoniker, 1, &IMon, &nb) == S_OK)
1163 IPropertyBag * pPropBagCat = NULL;
1164 VARIANT var;
1165 HRESULT hrSub;
1166 GUID clsid;
1167 int len;
1169 VariantInit(&var);
1170 V_VT(&var) = VT_BSTR;
1172 hrSub = IMoniker_BindToStorage(IMon, NULL, NULL, &IID_IPropertyBag, (LPVOID*)&pPropBagCat);
1174 if (SUCCEEDED(hrSub))
1175 hrSub = IPropertyBag_Read(pPropBagCat, wszClsidName, &var, NULL);
1177 if (SUCCEEDED(hrSub))
1178 hrSub = CLSIDFromString(V_UNION(&var, bstrVal), &clsid);
1180 if (SUCCEEDED(hrSub))
1181 hrSub = IPropertyBag_Read(pPropBagCat, wszFriendlyName, &var, NULL);
1183 if (SUCCEEDED(hrSub))
1185 len = (strlenW((WCHAR*)&V_UNION(&var, bstrVal))+1) * sizeof(WCHAR);
1186 if (!(regfilters[idx].Name = CoTaskMemAlloc(len*2)))
1187 hr = E_OUTOFMEMORY;
1190 if (SUCCEEDED(hrSub))
1192 memcpy(regfilters[idx].Name, &V_UNION(&var, bstrVal), len);
1193 regfilters[idx].Clsid = clsid;
1194 idx++;
1197 if (pPropBagCat)
1198 IPropertyBag_Release(pPropBagCat);
1199 IMoniker_Release(IMon);
1202 /* In case of release all resources */
1203 if (!SUCCEEDED(hr))
1205 for (idx = 0; idx < nb_mon; idx++)
1206 CoTaskMemFree(regfilters[idx].Name);
1207 CoTaskMemFree(regfilters);
1208 IEnumMoniker_Release(ppEnumMoniker);
1209 return hr;
1212 hr = IEnumRegFiltersImpl_Construct(regfilters, nb_mon, ppEnum);
1213 CoTaskMemFree(regfilters);
1214 IEnumMoniker_Release(ppEnumMoniker);
1216 return hr;
1220 static HRESULT WINAPI FilterMapper_RegisterFilter(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, DWORD dwMerit)
1222 HRESULT hr;
1223 LPWSTR wszClsid = NULL;
1224 HKEY hKey;
1225 WCHAR wszKeyName[strlenW(wszFilterSlash) + (CHARS_IN_GUID-1) + 1];
1227 TRACE("(%p)->(%s, %s, %lx)\n", iface, debugstr_guid(&clsid), debugstr_w(szName), dwMerit);
1229 hr = StringFromCLSID(&clsid, &wszClsid);
1231 if (SUCCEEDED(hr))
1233 strcpyW(wszKeyName, wszFilterSlash);
1234 strcatW(wszKeyName, wszClsid);
1236 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL));
1239 if (SUCCEEDED(hr))
1241 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, NULL, 0, REG_SZ, (const BYTE*)szName, strlenW(szName) + 1));
1242 CloseHandle(hKey);
1245 if (SUCCEEDED(hr))
1247 strcpyW(wszKeyName, wszClsidSlash);
1248 strcatW(wszKeyName, wszClsid);
1250 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL));
1253 if (SUCCEEDED(hr))
1255 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, wszMeritName, 0, REG_DWORD, (LPBYTE)&dwMerit, sizeof(dwMerit)));
1256 CloseHandle(hKey);
1259 return hr;
1262 static HRESULT WINAPI FilterMapper_RegisterFilterInstance(IFilterMapper * iface, CLSID clsid, LPCWSTR szName, CLSID *MRId)
1264 TRACE("(%p)->(%s, %s, %p)\n", iface, debugstr_guid(&clsid), debugstr_w(szName), MRId);
1266 /* Not implemented in Windows (tested on Win2k) */
1268 return E_NOTIMPL;
1271 static HRESULT WINAPI FilterMapper_RegisterPin(
1272 IFilterMapper * iface,
1273 CLSID Filter,
1274 LPCWSTR szName,
1275 BOOL bRendered,
1276 BOOL bOutput,
1277 BOOL bZero,
1278 BOOL bMany,
1279 CLSID ConnectsToFilter,
1280 LPCWSTR ConnectsToPin)
1282 HRESULT hr;
1283 LPWSTR wszClsid = NULL;
1284 HKEY hKey = NULL;
1285 HKEY hPinsKey = NULL;
1286 WCHAR * wszPinsKeyName;
1287 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1289 TRACE("(%p)->(%s, %s, %d, %d, %d, %d, %s, %s)\n", iface, debugstr_guid(&Filter), debugstr_w(szName), bRendered,
1290 bOutput, bZero, bMany, debugstr_guid(&ConnectsToFilter), debugstr_w(ConnectsToPin));
1292 hr = StringFromCLSID(&Filter, &wszClsid);
1294 if (SUCCEEDED(hr))
1296 strcpyW(wszKeyName, wszClsidSlash);
1297 strcatW(wszKeyName, wszClsid);
1299 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey));
1302 if (SUCCEEDED(hr))
1304 wszPinsKeyName = CoTaskMemAlloc((strlenW(wszPins) + 1 + strlenW(szName) + 1) * 2);
1305 if (!wszPinsKeyName)
1306 hr = E_OUTOFMEMORY;
1309 if (SUCCEEDED(hr))
1311 strcpyW(wszPinsKeyName, wszPins);
1312 strcatW(wszPinsKeyName, wszSlash);
1313 strcatW(wszPinsKeyName, szName);
1315 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(hKey, wszPinsKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hPinsKey, NULL));
1316 CoTaskMemFree(wszPinsKeyName);
1319 if (SUCCEEDED(hr))
1321 hr = HRESULT_FROM_WIN32(RegSetValueExW(hPinsKey, wszAllowedMany, 0, REG_DWORD, (LPBYTE)&bMany, sizeof(bMany)));
1324 if (SUCCEEDED(hr))
1326 hr = HRESULT_FROM_WIN32(RegSetValueExW(hPinsKey, wszAllowedZero, 0, REG_DWORD, (LPBYTE)&bZero, sizeof(bZero)));
1329 if (SUCCEEDED(hr))
1331 hr = HRESULT_FROM_WIN32(RegSetValueExW(hPinsKey, wszDirection, 0, REG_DWORD, (LPBYTE)&bOutput, sizeof(bOutput)));
1334 if (SUCCEEDED(hr))
1336 hr = HRESULT_FROM_WIN32(RegSetValueExW(hPinsKey, wszIsRendered, 0, REG_DWORD, (LPBYTE)&bRendered, sizeof(bRendered)));
1339 if (SUCCEEDED(hr))
1341 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(hPinsKey, wszTypes, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL, NULL));
1344 if (wszClsid)
1345 CoTaskMemFree(wszClsid);
1346 if (hKey)
1347 CloseHandle(hKey);
1348 if (hPinsKey)
1349 CloseHandle(hPinsKey);
1351 return hr;
1355 static HRESULT WINAPI FilterMapper_RegisterPinType(
1356 IFilterMapper * iface,
1357 CLSID clsFilter,
1358 LPCWSTR szName,
1359 CLSID clsMajorType,
1360 CLSID clsSubType)
1362 HRESULT hr;
1363 LPWSTR wszClsid = NULL;
1364 LPWSTR wszClsidMajorType = NULL;
1365 LPWSTR wszClsidSubType = NULL;
1366 HKEY hKey = NULL;
1367 WCHAR * wszTypesKey;
1368 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1370 TRACE("(%p)->(%s, %s, %s, %s)\n", iface, debugstr_guid(&clsFilter), debugstr_w(szName),
1371 debugstr_guid(&clsMajorType), debugstr_guid(&clsSubType));
1373 hr = StringFromCLSID(&clsFilter, &wszClsid);
1375 if (SUCCEEDED(hr))
1377 hr = StringFromCLSID(&clsMajorType, &wszClsidMajorType);
1380 if (SUCCEEDED(hr))
1382 hr = StringFromCLSID(&clsSubType, &wszClsidSubType);
1385 if (SUCCEEDED(hr))
1387 wszTypesKey = CoTaskMemAlloc((strlenW(wszClsidSlash) + strlenW(wszClsid) + strlenW(wszPins) +
1388 strlenW(szName) + strlenW(wszTypes) + 3 + 1) * 2);
1389 if (!wszTypesKey)
1390 hr = E_OUTOFMEMORY;
1393 if (SUCCEEDED(hr))
1395 strcpyW(wszTypesKey, wszClsidSlash);
1396 strcatW(wszTypesKey, wszClsid);
1397 strcatW(wszTypesKey, wszSlash);
1398 strcatW(wszTypesKey, wszPins);
1399 strcatW(wszTypesKey, wszSlash);
1400 strcatW(wszTypesKey, szName);
1401 strcatW(wszTypesKey, wszSlash);
1402 strcatW(wszTypesKey, wszTypes);
1404 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_CLASSES_ROOT, wszTypesKey, 0, KEY_WRITE, &hKey));
1405 CoTaskMemFree(wszTypesKey);
1408 if (SUCCEEDED(hr))
1410 strcpyW(wszKeyName, wszClsidMajorType);
1411 strcatW(wszKeyName, wszSlash);
1412 strcatW(wszKeyName, wszClsidSubType);
1414 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(hKey, wszKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL, NULL));
1415 CloseHandle(hKey);
1418 if (wszClsid)
1419 CoTaskMemFree(wszClsid);
1420 if (wszClsidMajorType)
1421 CoTaskMemFree(wszClsidMajorType);
1422 if (wszClsidSubType)
1423 CoTaskMemFree(wszClsidSubType);
1425 return hr;
1428 static HRESULT WINAPI FilterMapper_UnregisterFilter(IFilterMapper * iface, CLSID Filter)
1430 HRESULT hr;
1431 LPWSTR wszClsid = NULL;
1432 HKEY hKey;
1433 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1435 TRACE("(%p)->(%s)\n", iface, debugstr_guid(&Filter));
1437 hr = StringFromCLSID(&Filter, &wszClsid);
1439 if (SUCCEEDED(hr))
1441 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_CLASSES_ROOT, wszFilter, 0, KEY_WRITE, &hKey));
1444 if (SUCCEEDED(hr))
1446 hr = HRESULT_FROM_WIN32(RegDeleteKeyW(hKey, wszClsid));
1447 CloseHandle(hKey);
1450 if (SUCCEEDED(hr))
1452 strcpyW(wszKeyName, wszClsidSlash);
1453 strcatW(wszKeyName, wszClsid);
1455 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey));
1458 if (SUCCEEDED(hr))
1460 hr = HRESULT_FROM_WIN32(RegDeleteKeyW(hKey, wszMeritName));
1461 CloseHandle(hKey);
1464 if (wszClsid)
1465 CoTaskMemFree(wszClsid);
1467 return hr;
1470 static HRESULT WINAPI FilterMapper_UnregisterFilterInstance(IFilterMapper * iface, CLSID MRId)
1472 TRACE("(%p)->(%s)\n", iface, debugstr_guid(&MRId));
1474 /* Not implemented in Windows (tested on Win2k) */
1476 return E_NOTIMPL;
1479 static HRESULT WINAPI FilterMapper_UnregisterPin(IFilterMapper * iface, CLSID Filter, LPCWSTR Name)
1481 HRESULT hr;
1482 LPWSTR wszClsid = NULL;
1483 HKEY hKey = NULL;
1484 WCHAR * wszPinNameKey;
1485 WCHAR wszKeyName[strlenW(wszClsidSlash) + (CHARS_IN_GUID-1) + 1];
1487 TRACE("(%p)->(%s, %s)\n", iface, debugstr_guid(&Filter), debugstr_w(Name));
1489 if (!Name)
1490 return E_INVALIDARG;
1492 hr = StringFromCLSID(&Filter, &wszClsid);
1494 if (SUCCEEDED(hr))
1496 strcpyW(wszKeyName, wszClsidSlash);
1497 strcatW(wszKeyName, wszClsid);
1499 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_CLASSES_ROOT, wszKeyName, 0, KEY_WRITE, &hKey));
1502 if (SUCCEEDED(hr))
1504 wszPinNameKey = CoTaskMemAlloc((strlenW(wszPins) + 1 + strlenW(Name) + 1) * 2);
1505 if (!wszPinNameKey)
1506 hr = E_OUTOFMEMORY;
1509 if (SUCCEEDED(hr))
1511 strcpyW(wszPinNameKey, wszPins);
1512 strcatW(wszPinNameKey, wszSlash);
1513 strcatW(wszPinNameKey, Name);
1515 hr = HRESULT_FROM_WIN32(RegDeleteKeyW(hKey, wszPinNameKey));
1516 CoTaskMemFree(wszPinNameKey);
1519 if (wszClsid)
1520 CoTaskMemFree(wszClsid);
1521 if (hKey)
1522 CloseHandle(hKey);
1524 return hr;
1527 static const IFilterMapperVtbl fmvtbl =
1530 FilterMapper_QueryInterface,
1531 FilterMapper_AddRef,
1532 FilterMapper_Release,
1534 FilterMapper_RegisterFilter,
1535 FilterMapper_RegisterFilterInstance,
1536 FilterMapper_RegisterPin,
1537 FilterMapper_RegisterPinType,
1538 FilterMapper_UnregisterFilter,
1539 FilterMapper_UnregisterFilterInstance,
1540 FilterMapper_UnregisterPin,
1541 FilterMapper_EnumMatchingFilters