dxdiagn: Remove DECLSPEC_HIDDEN usage.
[wine.git] / dlls / quartz / regsvr.c
blobf203f0b7fa75df650599726a83d577774b1a4038
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 COBJMACROS
22 #include <stdarg.h>
23 #include <string.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "winerror.h"
32 #include "ole2.h"
33 #include "uuids.h"
34 #include "strmif.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
41 * Near the bottom of this file are the exported DllRegisterServer and
42 * DllUnregisterServer, which make all this worthwhile.
45 struct mediatype
47 CLSID const *majortype; /* NULL for end of list */
48 CLSID const *subtype;
49 DWORD fourcc;
52 struct pin
54 DWORD flags; /* 0xFFFFFFFF for end of list */
55 struct mediatype mediatypes[11];
58 struct regsvr_filter
60 CLSID const *clsid; /* NULL for end of list */
61 CLSID const *category;
62 WCHAR name[50];
63 DWORD merit;
64 struct pin pins[11];
67 /***********************************************************************
68 * register_filters
70 static HRESULT register_filters(struct regsvr_filter const *list)
72 HRESULT hr;
73 IFilterMapper2* pFM2 = NULL;
75 CoInitialize(NULL);
76 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pFM2);
78 if (SUCCEEDED(hr)) {
79 for (; SUCCEEDED(hr) && list->clsid; ++list) {
80 REGFILTER2 rf2;
81 REGFILTERPINS2* prfp2;
82 int i;
84 for (i = 0; list->pins[i].flags != 0xFFFFFFFF; i++) ;
85 rf2.dwVersion = 2;
86 rf2.dwMerit = list->merit;
87 rf2.cPins2 = i;
88 rf2.rgPins2 = prfp2 = CoTaskMemAlloc(i*sizeof(REGFILTERPINS2));
89 if (!prfp2) {
90 hr = E_OUTOFMEMORY;
91 break;
93 for (i = 0; list->pins[i].flags != 0xFFFFFFFF; i++) {
94 REGPINTYPES* lpMediatype;
95 CLSID* lpClsid;
96 int j, nbmt;
98 for (nbmt = 0; list->pins[i].mediatypes[nbmt].majortype; nbmt++) ;
99 /* Allocate a single buffer for regpintypes struct and clsids */
100 lpMediatype = CoTaskMemAlloc(nbmt*(sizeof(REGPINTYPES) + 2*sizeof(CLSID)));
101 if (!lpMediatype) {
102 hr = E_OUTOFMEMORY;
103 break;
105 lpClsid = (CLSID*) (lpMediatype + nbmt);
106 for (j = 0; j < nbmt; j++) {
107 (lpMediatype + j)->clsMajorType = lpClsid + j*2;
108 memcpy(lpClsid + j*2, list->pins[i].mediatypes[j].majortype, sizeof(CLSID));
109 (lpMediatype + j)->clsMinorType = lpClsid + j*2 + 1;
110 if (list->pins[i].mediatypes[j].subtype)
111 memcpy(lpClsid + j*2 + 1, list->pins[i].mediatypes[j].subtype, sizeof(CLSID));
112 else {
113 /* Subtypes are often a combination of major type + fourcc/tag */
114 memcpy(lpClsid + j*2 + 1, list->pins[i].mediatypes[j].majortype, sizeof(CLSID));
115 *(DWORD*)(lpClsid + j*2 + 1) = list->pins[i].mediatypes[j].fourcc;
118 prfp2[i].dwFlags = list->pins[i].flags;
119 prfp2[i].cInstances = 0;
120 prfp2[i].nMediaTypes = j;
121 prfp2[i].lpMediaType = lpMediatype;
122 prfp2[i].nMediums = 0;
123 prfp2[i].lpMedium = NULL;
124 prfp2[i].clsPinCategory = NULL;
127 if (FAILED(hr)) {
128 ERR("failed to register with hresult %#lx\n", hr);
129 CoTaskMemFree(prfp2);
130 break;
133 hr = IFilterMapper2_RegisterFilter(pFM2, list->clsid, list->name, NULL, list->category, NULL, &rf2);
135 while (i) {
136 CoTaskMemFree((REGPINTYPES*)prfp2[i-1].lpMediaType);
137 i--;
139 CoTaskMemFree(prfp2);
143 if (pFM2)
144 IFilterMapper2_Release(pFM2);
146 CoUninitialize();
148 return hr;
151 /***********************************************************************
152 * unregister_filters
154 static HRESULT unregister_filters(struct regsvr_filter const *list)
156 HRESULT hr;
157 IFilterMapper2* pFM2;
159 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pFM2);
161 if (SUCCEEDED(hr)) {
162 for (; SUCCEEDED(hr) && list->clsid; ++list)
163 hr = IFilterMapper2_UnregisterFilter(pFM2, list->category, NULL, list->clsid);
164 IFilterMapper2_Release(pFM2);
167 return hr;
170 /***********************************************************************
171 * filter list
174 static struct regsvr_filter const filter_list[] = {
175 { &CLSID_VideoRenderer,
176 &CLSID_LegacyAmFilterCategory,
177 L"Video Renderer",
178 0x800000,
179 { { REG_PINFLAG_B_RENDERER,
180 { { &MEDIATYPE_Video, &GUID_NULL },
181 { NULL }
184 { 0xFFFFFFFF },
187 { &CLSID_VideoRendererDefault,
188 &CLSID_LegacyAmFilterCategory,
189 L"Video Renderer",
190 0x800001,
191 { { REG_PINFLAG_B_RENDERER,
192 { { &MEDIATYPE_Video, &GUID_NULL },
193 { NULL }
196 { 0xFFFFFFFF },
199 { &CLSID_VideoMixingRenderer9,
200 &CLSID_LegacyAmFilterCategory,
201 L"Video Mixing Renderer 9",
202 0x200000,
203 { { REG_PINFLAG_B_RENDERER,
204 { { &MEDIATYPE_Video, &GUID_NULL },
205 { NULL }
208 { 0xFFFFFFFF },
211 { &CLSID_AVIDec,
212 &CLSID_LegacyAmFilterCategory,
213 L"AVI Decompressor",
214 0x5ffff0,
215 { { 0,
216 { { &MEDIATYPE_Video, &GUID_NULL },
217 { NULL }
220 { REG_PINFLAG_B_OUTPUT,
221 { { &MEDIATYPE_Video, &GUID_NULL },
222 { NULL }
225 { 0xFFFFFFFF },
228 { &CLSID_AsyncReader,
229 &CLSID_LegacyAmFilterCategory,
230 L"File Source (Async.)",
231 0x400000,
232 { { REG_PINFLAG_B_OUTPUT,
233 { { &MEDIATYPE_Stream, &GUID_NULL },
234 { NULL }
237 { 0xFFFFFFFF },
240 { &CLSID_ACMWrapper,
241 &CLSID_LegacyAmFilterCategory,
242 L"ACM Wrapper",
243 0x5ffff0,
244 { { 0,
245 { { &MEDIATYPE_Audio, &GUID_NULL },
246 { NULL }
249 { REG_PINFLAG_B_OUTPUT,
250 { { &MEDIATYPE_Audio, &GUID_NULL },
251 { NULL }
254 { 0xFFFFFFFF },
257 { NULL } /* list terminator */
260 extern HRESULT WINAPI QUARTZ_DllRegisterServer(void);
261 extern HRESULT WINAPI QUARTZ_DllUnregisterServer(void);
263 /***********************************************************************
264 * DllRegisterServer (QUARTZ.@)
266 HRESULT WINAPI DllRegisterServer(void)
268 HRESULT hr;
270 TRACE("\n");
272 hr = QUARTZ_DllRegisterServer();
273 if (SUCCEEDED(hr))
274 hr = register_filters(filter_list);
275 return hr;
278 /***********************************************************************
279 * DllUnregisterServer (QUARTZ.@)
281 HRESULT WINAPI DllUnregisterServer(void)
283 HRESULT hr;
285 TRACE("\n");
287 hr = unregister_filters(filter_list);
288 if (SUCCEEDED(hr))
289 hr = QUARTZ_DllUnregisterServer();
290 return hr;