widl: Generate helper macros for WinRT implementation.
[wine/zf.git] / dlls / quartz / regsvr.c
blob92555630e9e4e9059ecd521cababa81ce179dfba
1 /*
2 * self-registerable dll functions for quartz.dll
4 * Copyright (C) 2003 John K. Hohm
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
23 #define COBJMACROS
24 #include <stdarg.h>
25 #include <string.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winreg.h"
32 #include "winerror.h"
34 #include "ole2.h"
35 #include "uuids.h"
36 #include "strmif.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
43 * Near the bottom of this file are the exported DllRegisterServer and
44 * DllUnregisterServer, which make all this worthwhile.
47 struct mediatype
49 CLSID const *majortype; /* NULL for end of list */
50 CLSID const *subtype;
51 DWORD fourcc;
54 struct pin
56 DWORD flags; /* 0xFFFFFFFF for end of list */
57 struct mediatype mediatypes[11];
60 struct regsvr_filter
62 CLSID const *clsid; /* NULL for end of list */
63 CLSID const *category;
64 WCHAR name[50];
65 DWORD merit;
66 struct pin pins[11];
69 /***********************************************************************
70 * register_filters
72 static HRESULT register_filters(struct regsvr_filter const *list)
74 HRESULT hr;
75 IFilterMapper2* pFM2 = NULL;
77 CoInitialize(NULL);
78 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pFM2);
80 if (SUCCEEDED(hr)) {
81 for (; SUCCEEDED(hr) && list->clsid; ++list) {
82 REGFILTER2 rf2;
83 REGFILTERPINS2* prfp2;
84 int i;
86 for (i = 0; list->pins[i].flags != 0xFFFFFFFF; i++) ;
87 rf2.dwVersion = 2;
88 rf2.dwMerit = list->merit;
89 rf2.u.s2.cPins2 = i;
90 rf2.u.s2.rgPins2 = prfp2 = CoTaskMemAlloc(i*sizeof(REGFILTERPINS2));
91 if (!prfp2) {
92 hr = E_OUTOFMEMORY;
93 break;
95 for (i = 0; list->pins[i].flags != 0xFFFFFFFF; i++) {
96 REGPINTYPES* lpMediatype;
97 CLSID* lpClsid;
98 int j, nbmt;
100 for (nbmt = 0; list->pins[i].mediatypes[nbmt].majortype; nbmt++) ;
101 /* Allocate a single buffer for regpintypes struct and clsids */
102 lpMediatype = CoTaskMemAlloc(nbmt*(sizeof(REGPINTYPES) + 2*sizeof(CLSID)));
103 if (!lpMediatype) {
104 hr = E_OUTOFMEMORY;
105 break;
107 lpClsid = (CLSID*) (lpMediatype + nbmt);
108 for (j = 0; j < nbmt; j++) {
109 (lpMediatype + j)->clsMajorType = lpClsid + j*2;
110 memcpy(lpClsid + j*2, list->pins[i].mediatypes[j].majortype, sizeof(CLSID));
111 (lpMediatype + j)->clsMinorType = lpClsid + j*2 + 1;
112 if (list->pins[i].mediatypes[j].subtype)
113 memcpy(lpClsid + j*2 + 1, list->pins[i].mediatypes[j].subtype, sizeof(CLSID));
114 else {
115 /* Subtypes are often a combination of major type + fourcc/tag */
116 memcpy(lpClsid + j*2 + 1, list->pins[i].mediatypes[j].majortype, sizeof(CLSID));
117 *(DWORD*)(lpClsid + j*2 + 1) = list->pins[i].mediatypes[j].fourcc;
120 prfp2[i].dwFlags = list->pins[i].flags;
121 prfp2[i].cInstances = 0;
122 prfp2[i].nMediaTypes = j;
123 prfp2[i].lpMediaType = lpMediatype;
124 prfp2[i].nMediums = 0;
125 prfp2[i].lpMedium = NULL;
126 prfp2[i].clsPinCategory = NULL;
129 if (FAILED(hr)) {
130 ERR("failed to register with hresult 0x%x\n", hr);
131 CoTaskMemFree(prfp2);
132 break;
135 hr = IFilterMapper2_RegisterFilter(pFM2, list->clsid, list->name, NULL, list->category, NULL, &rf2);
137 while (i) {
138 CoTaskMemFree((REGPINTYPES*)prfp2[i-1].lpMediaType);
139 i--;
141 CoTaskMemFree(prfp2);
145 if (pFM2)
146 IFilterMapper2_Release(pFM2);
148 CoUninitialize();
150 return hr;
153 /***********************************************************************
154 * unregister_filters
156 static HRESULT unregister_filters(struct regsvr_filter const *list)
158 HRESULT hr;
159 IFilterMapper2* pFM2;
161 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pFM2);
163 if (SUCCEEDED(hr)) {
164 for (; SUCCEEDED(hr) && list->clsid; ++list)
165 hr = IFilterMapper2_UnregisterFilter(pFM2, list->category, NULL, list->clsid);
166 IFilterMapper2_Release(pFM2);
169 return hr;
172 /***********************************************************************
173 * filter list
176 static struct regsvr_filter const filter_list[] = {
177 { &CLSID_VideoRenderer,
178 &CLSID_LegacyAmFilterCategory,
179 L"Video Renderer",
180 0x800000,
181 { { REG_PINFLAG_B_RENDERER,
182 { { &MEDIATYPE_Video, &GUID_NULL },
183 { NULL }
186 { 0xFFFFFFFF },
189 { &CLSID_VideoRendererDefault,
190 &CLSID_LegacyAmFilterCategory,
191 L"Video Renderer",
192 0x800001,
193 { { REG_PINFLAG_B_RENDERER,
194 { { &MEDIATYPE_Video, &GUID_NULL },
195 { NULL }
198 { 0xFFFFFFFF },
201 { &CLSID_VideoMixingRenderer9,
202 &CLSID_LegacyAmFilterCategory,
203 L"Video Mixing Renderer 9",
204 0x200000,
205 { { REG_PINFLAG_B_RENDERER,
206 { { &MEDIATYPE_Video, &GUID_NULL },
207 { NULL }
210 { 0xFFFFFFFF },
213 { &CLSID_AVIDec,
214 &CLSID_LegacyAmFilterCategory,
215 L"AVI Decompressor",
216 0x5ffff0,
217 { { 0,
218 { { &MEDIATYPE_Video, &GUID_NULL },
219 { NULL }
222 { REG_PINFLAG_B_OUTPUT,
223 { { &MEDIATYPE_Video, &GUID_NULL },
224 { NULL }
227 { 0xFFFFFFFF },
230 { &CLSID_AsyncReader,
231 &CLSID_LegacyAmFilterCategory,
232 L"File Source (Async.)",
233 0x400000,
234 { { REG_PINFLAG_B_OUTPUT,
235 { { &MEDIATYPE_Stream, &GUID_NULL },
236 { NULL }
239 { 0xFFFFFFFF },
242 { &CLSID_ACMWrapper,
243 &CLSID_LegacyAmFilterCategory,
244 L"ACM Wrapper",
245 0x5ffff0,
246 { { 0,
247 { { &MEDIATYPE_Audio, &GUID_NULL },
248 { NULL }
251 { REG_PINFLAG_B_OUTPUT,
252 { { &MEDIATYPE_Audio, &GUID_NULL },
253 { NULL }
256 { 0xFFFFFFFF },
259 { NULL } /* list terminator */
262 extern HRESULT WINAPI QUARTZ_DllRegisterServer(void) DECLSPEC_HIDDEN;
263 extern HRESULT WINAPI QUARTZ_DllUnregisterServer(void) DECLSPEC_HIDDEN;
265 /***********************************************************************
266 * DllRegisterServer (QUARTZ.@)
268 HRESULT WINAPI DllRegisterServer(void)
270 HRESULT hr;
272 TRACE("\n");
274 hr = QUARTZ_DllRegisterServer();
275 if (SUCCEEDED(hr))
276 hr = register_filters(filter_list);
277 return hr;
280 /***********************************************************************
281 * DllUnregisterServer (QUARTZ.@)
283 HRESULT WINAPI DllUnregisterServer(void)
285 HRESULT hr;
287 TRACE("\n");
289 hr = unregister_filters(filter_list);
290 if (SUCCEEDED(hr))
291 hr = QUARTZ_DllUnregisterServer();
292 return hr;