[QUARTZ] Sync with Wine Staging 1.9.4. CORE-10912
[reactos.git] / reactos / dll / directx / wine / quartz / regsvr.c
1 /*
2 * self-registerable dll functions for quartz.dll
3 *
4 * Copyright (C) 2003 John K. Hohm
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "quartz_private.h"
22
23 #include <uuids.h>
24
25 /*
26 * Near the bottom of this file are the exported DllRegisterServer and
27 * DllUnregisterServer, which make all this worthwhile.
28 */
29
30 /***********************************************************************
31 * interface for self-registering
32 */
33 struct regsvr_interface
34 {
35 IID const *iid; /* NULL for end of list */
36 LPCSTR name; /* can be NULL to omit */
37 IID const *base_iid; /* can be NULL to omit */
38 int num_methods; /* can be <0 to omit */
39 CLSID const *ps_clsid; /* can be NULL to omit */
40 CLSID const *ps_clsid32; /* can be NULL to omit */
41 };
42
43 static HRESULT register_interfaces(struct regsvr_interface const *list);
44 static HRESULT unregister_interfaces(struct regsvr_interface const *list);
45
46 struct regsvr_coclass
47 {
48 CLSID const *clsid; /* NULL for end of list */
49 LPCSTR name; /* can be NULL to omit */
50 LPCSTR ips; /* can be NULL to omit */
51 LPCSTR ips32; /* can be NULL to omit */
52 LPCSTR ips32_tmodel; /* can be NULL to omit */
53 LPCSTR progid; /* can be NULL to omit */
54 LPCSTR viprogid; /* can be NULL to omit */
55 LPCSTR progid_extra; /* can be NULL to omit */
56 };
57
58 static HRESULT register_coclasses(struct regsvr_coclass const *list);
59 static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
60
61 struct regsvr_mediatype_parsing
62 {
63 CLSID const *majortype; /* NULL for end of list */
64 CLSID const *subtype;
65 LPCSTR line[11]; /* NULL for end of list */
66 };
67
68 static HRESULT register_mediatypes_parsing(struct regsvr_mediatype_parsing const *list);
69 static HRESULT unregister_mediatypes_parsing(struct regsvr_mediatype_parsing const *list);
70
71 struct regsvr_mediatype_extension
72 {
73 CLSID const *majortype; /* NULL for end of list */
74 CLSID const *subtype;
75 LPCSTR extension;
76 };
77
78 struct mediatype
79 {
80 CLSID const *majortype; /* NULL for end of list */
81 CLSID const *subtype;
82 DWORD fourcc;
83 };
84
85 struct pin
86 {
87 DWORD flags; /* 0xFFFFFFFF for end of list */
88 struct mediatype mediatypes[11];
89 };
90
91 struct regsvr_filter
92 {
93 CLSID const *clsid; /* NULL for end of list */
94 CLSID const *category;
95 WCHAR name[50];
96 DWORD merit;
97 struct pin pins[11];
98 };
99
100 static HRESULT register_mediatypes_extension(struct regsvr_mediatype_extension const *list);
101 static HRESULT unregister_mediatypes_extension(struct regsvr_mediatype_extension const *list);
102
103 static HRESULT register_filters(struct regsvr_filter const *list);
104 static HRESULT unregister_filters(struct regsvr_filter const *list);
105
106 /***********************************************************************
107 * static string constants
108 */
109 static const WCHAR interface_keyname[] = {
110 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
111 static const WCHAR base_ifa_keyname[] = {
112 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
113 'e', 0 };
114 static const WCHAR num_methods_keyname[] = {
115 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
116 static const WCHAR ps_clsid_keyname[] = {
117 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
118 'i', 'd', 0 };
119 static const WCHAR ps_clsid32_keyname[] = {
120 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
121 'i', 'd', '3', '2', 0 };
122 static const WCHAR clsid_keyname[] = {
123 'C', 'L', 'S', 'I', 'D', 0 };
124 static const WCHAR curver_keyname[] = {
125 'C', 'u', 'r', 'V', 'e', 'r', 0 };
126 static const WCHAR ips_keyname[] = {
127 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
128 0 };
129 static const WCHAR ips32_keyname[] = {
130 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
131 '3', '2', 0 };
132 static const WCHAR progid_keyname[] = {
133 'P', 'r', 'o', 'g', 'I', 'D', 0 };
134 static const WCHAR viprogid_keyname[] = {
135 'V', 'e', 'r', 's', 'i', 'o', 'n', 'I', 'n', 'd', 'e', 'p',
136 'e', 'n', 'd', 'e', 'n', 't', 'P', 'r', 'o', 'g', 'I', 'D',
137 0 };
138 static const char tmodel_valuename[] = "ThreadingModel";
139 static const WCHAR mediatype_name[] = {
140 'M', 'e', 'd', 'i', 'a', ' ', 'T', 'y', 'p', 'e', 0 };
141 static const WCHAR subtype_valuename[] = {
142 'S', 'u', 'b', 't', 'y', 'p', 'e', 0 };
143 static const WCHAR sourcefilter_valuename[] = {
144 'S', 'o', 'u', 'r', 'c', 'e', ' ', 'F', 'i', 'l', 't', 'e', 'r', 0 };
145 static const WCHAR extensions_keyname[] = {
146 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 's', 0 };
147
148 /***********************************************************************
149 * static helper functions
150 */
151 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid);
152 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
153 WCHAR const *value);
154 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
155 char const *value);
156 static LONG register_progid(WCHAR const *clsid,
157 char const *progid, char const *curver_progid,
158 char const *name, char const *extra);
159
160 /***********************************************************************
161 * register_interfaces
162 */
163 static HRESULT register_interfaces(struct regsvr_interface const *list)
164 {
165 LONG res = ERROR_SUCCESS;
166 HKEY interface_key;
167
168 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, NULL, 0,
169 KEY_READ | KEY_WRITE, NULL, &interface_key, NULL);
170 if (res != ERROR_SUCCESS) goto error_return;
171
172 for (; res == ERROR_SUCCESS && list->iid; ++list) {
173 WCHAR buf[39];
174 HKEY iid_key;
175
176 StringFromGUID2(list->iid, buf, 39);
177 res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0,
178 KEY_READ | KEY_WRITE, NULL, &iid_key, NULL);
179 if (res != ERROR_SUCCESS) goto error_close_interface_key;
180
181 if (list->name) {
182 res = RegSetValueExA(iid_key, NULL, 0, REG_SZ, (const BYTE*)list->name,
183 strlen(list->name) + 1);
184 if (res != ERROR_SUCCESS) goto error_close_iid_key;
185 }
186
187 if (list->base_iid) {
188 res = register_key_guid(iid_key, base_ifa_keyname, list->base_iid);
189 if (res != ERROR_SUCCESS) goto error_close_iid_key;
190 }
191
192 if (0 <= list->num_methods) {
193 static const WCHAR fmt[] = { '%', 'd', 0 };
194 HKEY key;
195
196 res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0,
197 KEY_READ | KEY_WRITE, NULL, &key, NULL);
198 if (res != ERROR_SUCCESS) goto error_close_iid_key;
199
200 sprintfW(buf, fmt, list->num_methods);
201 res = RegSetValueExW(key, NULL, 0, REG_SZ, (const BYTE*)buf,
202 (lstrlenW(buf) + 1) * sizeof(WCHAR));
203 RegCloseKey(key);
204
205 if (res != ERROR_SUCCESS) goto error_close_iid_key;
206 }
207
208 if (list->ps_clsid) {
209 res = register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid);
210 if (res != ERROR_SUCCESS) goto error_close_iid_key;
211 }
212
213 if (list->ps_clsid32) {
214 res = register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32);
215 if (res != ERROR_SUCCESS) goto error_close_iid_key;
216 }
217
218 error_close_iid_key:
219 RegCloseKey(iid_key);
220 }
221
222 error_close_interface_key:
223 RegCloseKey(interface_key);
224 error_return:
225 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
226 }
227
228 /***********************************************************************
229 * unregister_interfaces
230 */
231 static HRESULT unregister_interfaces(struct regsvr_interface const *list)
232 {
233 LONG res = ERROR_SUCCESS;
234 HKEY interface_key;
235
236 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0,
237 KEY_READ | KEY_WRITE, &interface_key);
238 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
239 if (res != ERROR_SUCCESS) goto error_return;
240
241 for (; res == ERROR_SUCCESS && list->iid; ++list) {
242 WCHAR buf[39];
243
244 StringFromGUID2(list->iid, buf, 39);
245 res = RegDeleteTreeW(interface_key, buf);
246 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
247 }
248
249 RegCloseKey(interface_key);
250 error_return:
251 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
252 }
253
254 /***********************************************************************
255 * register_coclasses
256 */
257 static HRESULT register_coclasses(struct regsvr_coclass const *list)
258 {
259 LONG res = ERROR_SUCCESS;
260 HKEY coclass_key;
261
262 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
263 KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
264 if (res != ERROR_SUCCESS) goto error_return;
265
266 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
267 WCHAR buf[39];
268 HKEY clsid_key;
269
270 StringFromGUID2(list->clsid, buf, 39);
271 res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
272 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
273 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
274
275 if (list->name) {
276 res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ, (const BYTE*)list->name,
277 strlen(list->name) + 1);
278 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
279 }
280
281 if (list->ips) {
282 res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
283 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
284 }
285
286 if (list->ips32) {
287 HKEY ips32_key;
288
289 res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
290 KEY_READ | KEY_WRITE, NULL,
291 &ips32_key, NULL);
292 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
293
294 res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ, (const BYTE*)list->ips32,
295 lstrlenA(list->ips32) + 1);
296 if (res == ERROR_SUCCESS && list->ips32_tmodel)
297 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
298 (const BYTE*)list->ips32_tmodel,
299 strlen(list->ips32_tmodel) + 1);
300 RegCloseKey(ips32_key);
301 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
302 }
303
304 if (list->progid) {
305 res = register_key_defvalueA(clsid_key, progid_keyname,
306 list->progid);
307 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
308
309 res = register_progid(buf, list->progid, NULL,
310 list->name, list->progid_extra);
311 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
312 }
313
314 if (list->viprogid) {
315 res = register_key_defvalueA(clsid_key, viprogid_keyname,
316 list->viprogid);
317 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
318
319 res = register_progid(buf, list->viprogid, list->progid,
320 list->name, list->progid_extra);
321 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
322 }
323
324 error_close_clsid_key:
325 RegCloseKey(clsid_key);
326 }
327
328 error_close_coclass_key:
329 RegCloseKey(coclass_key);
330 error_return:
331 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
332 }
333
334 /***********************************************************************
335 * unregister_coclasses
336 */
337 static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
338 {
339 LONG res = ERROR_SUCCESS;
340 HKEY coclass_key;
341
342 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
343 KEY_READ | KEY_WRITE, &coclass_key);
344 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
345 if (res != ERROR_SUCCESS) goto error_return;
346
347 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
348 WCHAR buf[39];
349
350 StringFromGUID2(list->clsid, buf, 39);
351 res = RegDeleteTreeW(coclass_key, buf);
352 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
353 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
354
355 if (list->progid) {
356 res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->progid);
357 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
358 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
359 }
360
361 if (list->viprogid) {
362 res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->viprogid);
363 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
364 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
365 }
366 }
367
368 error_close_coclass_key:
369 RegCloseKey(coclass_key);
370 error_return:
371 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
372 }
373
374 /***********************************************************************
375 * register_mediatypes_parsing
376 */
377 static HRESULT register_mediatypes_parsing(struct regsvr_mediatype_parsing const *list)
378 {
379 LONG res = ERROR_SUCCESS;
380 HKEY mediatype_key;
381 WCHAR buf[39];
382 int i;
383
384 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0, NULL, 0,
385 KEY_READ | KEY_WRITE, NULL, &mediatype_key, NULL);
386 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
387
388 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
389 HKEY majortype_key = NULL;
390 HKEY subtype_key = NULL;
391
392 StringFromGUID2(list->majortype, buf, 39);
393 res = RegCreateKeyExW(mediatype_key, buf, 0, NULL, 0,
394 KEY_READ | KEY_WRITE, NULL, &majortype_key, NULL);
395 if (res != ERROR_SUCCESS) goto error_close_keys;
396
397 StringFromGUID2(list->subtype, buf, 39);
398 res = RegCreateKeyExW(majortype_key, buf, 0, NULL, 0,
399 KEY_READ | KEY_WRITE, NULL, &subtype_key, NULL);
400 if (res != ERROR_SUCCESS) goto error_close_keys;
401
402 StringFromGUID2(&CLSID_AsyncReader, buf, 39);
403 res = RegSetValueExW(subtype_key, sourcefilter_valuename, 0, REG_SZ, (const BYTE*)buf,
404 (lstrlenW(buf) + 1) * sizeof(WCHAR));
405 if (res != ERROR_SUCCESS) goto error_close_keys;
406
407 for(i = 0; list->line[i]; i++) {
408 char buffer[3];
409 wsprintfA(buffer, "%d", i);
410 res = RegSetValueExA(subtype_key, buffer, 0, REG_SZ, (const BYTE*)list->line[i],
411 lstrlenA(list->line[i]));
412 if (res != ERROR_SUCCESS) goto error_close_keys;
413 }
414
415 error_close_keys:
416 if (majortype_key)
417 RegCloseKey(majortype_key);
418 if (subtype_key)
419 RegCloseKey(subtype_key);
420 }
421
422 RegCloseKey(mediatype_key);
423
424 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
425 }
426
427 /***********************************************************************
428 * register_mediatypes_extension
429 */
430 static HRESULT register_mediatypes_extension(struct regsvr_mediatype_extension const *list)
431 {
432 LONG res = ERROR_SUCCESS;
433 HKEY mediatype_key;
434 HKEY extensions_root_key = NULL;
435 WCHAR buf[39];
436
437 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0, NULL, 0,
438 KEY_READ | KEY_WRITE, NULL, &mediatype_key, NULL);
439 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
440
441 res = RegCreateKeyExW(mediatype_key, extensions_keyname, 0, NULL, 0,
442 KEY_READ | KEY_WRITE, NULL, &extensions_root_key, NULL);
443 if (res != ERROR_SUCCESS) goto error_return;
444
445 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
446 HKEY extension_key;
447
448 res = RegCreateKeyExA(extensions_root_key, list->extension, 0, NULL, 0,
449 KEY_READ | KEY_WRITE, NULL, &extension_key, NULL);
450 if (res != ERROR_SUCCESS) break;
451
452 StringFromGUID2(list->majortype, buf, 39);
453 res = RegSetValueExW(extension_key, mediatype_name, 0, REG_SZ, (const BYTE*)buf,
454 (lstrlenW(buf) + 1) * sizeof(WCHAR));
455 if (res != ERROR_SUCCESS) goto error_close_key;
456
457 StringFromGUID2(list->subtype, buf, 39);
458 res = RegSetValueExW(extension_key, subtype_valuename, 0, REG_SZ, (const BYTE*)buf,
459 (lstrlenW(buf) + 1) * sizeof(WCHAR));
460 if (res != ERROR_SUCCESS) goto error_close_key;
461
462 StringFromGUID2(&CLSID_AsyncReader, buf, 39);
463 res = RegSetValueExW(extension_key, sourcefilter_valuename, 0, REG_SZ, (const BYTE*)buf,
464 (lstrlenW(buf) + 1) * sizeof(WCHAR));
465 if (res != ERROR_SUCCESS) goto error_close_key;
466
467 error_close_key:
468 RegCloseKey(extension_key);
469 }
470
471 error_return:
472 RegCloseKey(mediatype_key);
473 if (extensions_root_key)
474 RegCloseKey(extensions_root_key);
475
476 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
477 }
478
479 /***********************************************************************
480 * unregister_mediatypes_parsing
481 */
482 static HRESULT unregister_mediatypes_parsing(struct regsvr_mediatype_parsing const *list)
483 {
484 LONG res;
485 HKEY mediatype_key;
486 HKEY majortype_key;
487 WCHAR buf[39];
488
489 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0,
490 KEY_READ | KEY_WRITE, &mediatype_key);
491 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
492 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
493
494 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
495 StringFromGUID2(list->majortype, buf, 39);
496 res = RegOpenKeyExW(mediatype_key, buf, 0,
497 KEY_READ | KEY_WRITE, &majortype_key);
498 if (res == ERROR_FILE_NOT_FOUND) {
499 res = ERROR_SUCCESS;
500 continue;
501 }
502 if (res != ERROR_SUCCESS) break;
503
504 StringFromGUID2(list->subtype, buf, 39);
505 res = RegDeleteTreeW(majortype_key, buf);
506 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
507
508 /* Removed majortype key if there is no more subtype key */
509 res = RegDeleteKeyW(majortype_key, 0);
510 if (res == ERROR_ACCESS_DENIED) res = ERROR_SUCCESS;
511
512 RegCloseKey(majortype_key);
513 }
514
515 RegCloseKey(mediatype_key);
516
517 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
518 }
519
520 /***********************************************************************
521 * unregister_mediatypes_extension
522 */
523 static HRESULT unregister_mediatypes_extension(struct regsvr_mediatype_extension const *list)
524 {
525 LONG res;
526 HKEY mediatype_key;
527 HKEY extensions_root_key = NULL;
528
529 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, mediatype_name, 0,
530 KEY_READ | KEY_WRITE, &mediatype_key);
531 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
532 if (res != ERROR_SUCCESS) return HRESULT_FROM_WIN32(res);
533
534 res = RegOpenKeyExW(mediatype_key, extensions_keyname, 0,
535 KEY_READ | KEY_WRITE, &extensions_root_key);
536 if (res == ERROR_FILE_NOT_FOUND)
537 res = ERROR_SUCCESS;
538 else if (res == ERROR_SUCCESS)
539 for (; res == ERROR_SUCCESS && list->majortype; ++list) {
540 res = RegDeleteTreeA(extensions_root_key, list->extension);
541 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
542 }
543
544 RegCloseKey(mediatype_key);
545 if (extensions_root_key)
546 RegCloseKey(extensions_root_key);
547
548 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
549 }
550
551 /***********************************************************************
552 * register_filters
553 */
554 static HRESULT register_filters(struct regsvr_filter const *list)
555 {
556 HRESULT hr;
557 IFilterMapper2* pFM2 = NULL;
558
559 CoInitialize(NULL);
560 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pFM2);
561
562 if (SUCCEEDED(hr)) {
563 for (; SUCCEEDED(hr) && list->clsid; ++list) {
564 REGFILTER2 rf2;
565 REGFILTERPINS2* prfp2;
566 int i;
567
568 for (i = 0; list->pins[i].flags != 0xFFFFFFFF; i++) ;
569 rf2.dwVersion = 2;
570 rf2.dwMerit = list->merit;
571 rf2.u.s2.cPins2 = i;
572 rf2.u.s2.rgPins2 = prfp2 = CoTaskMemAlloc(i*sizeof(REGFILTERPINS2));
573 if (!prfp2) {
574 hr = E_OUTOFMEMORY;
575 break;
576 }
577 for (i = 0; list->pins[i].flags != 0xFFFFFFFF; i++) {
578 REGPINTYPES* lpMediatype;
579 CLSID* lpClsid;
580 int j, nbmt;
581
582 for (nbmt = 0; list->pins[i].mediatypes[nbmt].majortype; nbmt++) ;
583 /* Allocate a single buffer for regpintypes struct and clsids */
584 lpMediatype = CoTaskMemAlloc(nbmt*(sizeof(REGPINTYPES) + 2*sizeof(CLSID)));
585 if (!lpMediatype) {
586 hr = E_OUTOFMEMORY;
587 break;
588 }
589 lpClsid = (CLSID*) (lpMediatype + nbmt);
590 for (j = 0; j < nbmt; j++) {
591 (lpMediatype + j)->clsMajorType = lpClsid + j*2;
592 memcpy(lpClsid + j*2, list->pins[i].mediatypes[j].majortype, sizeof(CLSID));
593 (lpMediatype + j)->clsMinorType = lpClsid + j*2 + 1;
594 if (list->pins[i].mediatypes[j].subtype)
595 memcpy(lpClsid + j*2 + 1, list->pins[i].mediatypes[j].subtype, sizeof(CLSID));
596 else {
597 /* Subtypes are often a combination of major type + fourcc/tag */
598 memcpy(lpClsid + j*2 + 1, list->pins[i].mediatypes[j].majortype, sizeof(CLSID));
599 *(DWORD*)(lpClsid + j*2 + 1) = list->pins[i].mediatypes[j].fourcc;
600 }
601 }
602 prfp2[i].dwFlags = list->pins[i].flags;
603 prfp2[i].cInstances = 0;
604 prfp2[i].nMediaTypes = j;
605 prfp2[i].lpMediaType = lpMediatype;
606 prfp2[i].nMediums = 0;
607 prfp2[i].lpMedium = NULL;
608 prfp2[i].clsPinCategory = NULL;
609 }
610
611 if (FAILED(hr)) {
612 ERR("failed to register with hresult 0x%x\n", hr);
613 CoTaskMemFree(prfp2);
614 break;
615 }
616
617 hr = IFilterMapper2_RegisterFilter(pFM2, list->clsid, list->name, NULL, list->category, NULL, &rf2);
618
619 while (i) {
620 CoTaskMemFree((REGPINTYPES*)prfp2[i-1].lpMediaType);
621 i--;
622 }
623 CoTaskMemFree(prfp2);
624 }
625 }
626
627 if (pFM2)
628 IFilterMapper2_Release(pFM2);
629
630 CoUninitialize();
631
632 return hr;
633 }
634
635 /***********************************************************************
636 * unregister_filters
637 */
638 static HRESULT unregister_filters(struct regsvr_filter const *list)
639 {
640 HRESULT hr;
641 IFilterMapper2* pFM2;
642
643 CoInitialize(NULL);
644
645 hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pFM2);
646
647 if (SUCCEEDED(hr)) {
648 for (; SUCCEEDED(hr) && list->clsid; ++list)
649 hr = IFilterMapper2_UnregisterFilter(pFM2, list->category, NULL, list->clsid);
650 IFilterMapper2_Release(pFM2);
651 }
652
653 CoUninitialize();
654
655 return hr;
656 }
657
658 /***********************************************************************
659 * regsvr_key_guid
660 */
661 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid)
662 {
663 WCHAR buf[39];
664
665 StringFromGUID2(guid, buf, 39);
666 return register_key_defvalueW(base, name, buf);
667 }
668
669 /***********************************************************************
670 * regsvr_key_defvalueW
671 */
672 static LONG register_key_defvalueW(
673 HKEY base,
674 WCHAR const *name,
675 WCHAR const *value)
676 {
677 LONG res;
678 HKEY key;
679
680 res = RegCreateKeyExW(base, name, 0, NULL, 0,
681 KEY_READ | KEY_WRITE, NULL, &key, NULL);
682 if (res != ERROR_SUCCESS) return res;
683 res = RegSetValueExW(key, NULL, 0, REG_SZ, (const BYTE*)value,
684 (lstrlenW(value) + 1) * sizeof(WCHAR));
685 RegCloseKey(key);
686 return res;
687 }
688
689 /***********************************************************************
690 * regsvr_key_defvalueA
691 */
692 static LONG register_key_defvalueA(
693 HKEY base,
694 WCHAR const *name,
695 char const *value)
696 {
697 LONG res;
698 HKEY key;
699
700 res = RegCreateKeyExW(base, name, 0, NULL, 0,
701 KEY_READ | KEY_WRITE, NULL, &key, NULL);
702 if (res != ERROR_SUCCESS) return res;
703 res = RegSetValueExA(key, NULL, 0, REG_SZ, (const BYTE*)value, lstrlenA(value) + 1);
704 RegCloseKey(key);
705 return res;
706 }
707
708 /***********************************************************************
709 * regsvr_progid
710 */
711 static LONG register_progid(
712 WCHAR const *clsid,
713 char const *progid,
714 char const *curver_progid,
715 char const *name,
716 char const *extra)
717 {
718 LONG res;
719 HKEY progid_key;
720
721 res = RegCreateKeyExA(HKEY_CLASSES_ROOT, progid, 0,
722 NULL, 0, KEY_READ | KEY_WRITE, NULL,
723 &progid_key, NULL);
724 if (res != ERROR_SUCCESS) return res;
725
726 if (name) {
727 res = RegSetValueExA(progid_key, NULL, 0, REG_SZ, (const BYTE*)name, strlen(name) + 1);
728 if (res != ERROR_SUCCESS) goto error_close_progid_key;
729 }
730
731 if (clsid) {
732 res = register_key_defvalueW(progid_key, clsid_keyname, clsid);
733 if (res != ERROR_SUCCESS) goto error_close_progid_key;
734 }
735
736 if (curver_progid) {
737 res = register_key_defvalueA(progid_key, curver_keyname,
738 curver_progid);
739 if (res != ERROR_SUCCESS) goto error_close_progid_key;
740 }
741
742 if (extra) {
743 HKEY extra_key;
744
745 res = RegCreateKeyExA(progid_key, extra, 0,
746 NULL, 0, KEY_READ | KEY_WRITE, NULL,
747 &extra_key, NULL);
748 if (res == ERROR_SUCCESS)
749 RegCloseKey(extra_key);
750 }
751
752 error_close_progid_key:
753 RegCloseKey(progid_key);
754 return res;
755 }
756
757 /***********************************************************************
758 * coclass list
759 */
760 static struct regsvr_coclass const coclass_list[] = {
761 { NULL } /* list terminator */
762 };
763
764 /***********************************************************************
765 * interface list
766 */
767
768 static struct regsvr_interface const interface_list[] = {
769 { NULL } /* list terminator */
770 };
771
772 /***********************************************************************
773 * mediatype list
774 */
775
776 static struct regsvr_mediatype_parsing const mediatype_parsing_list[] = {
777 { &MEDIATYPE_Stream,
778 &MEDIASUBTYPE_Avi,
779 { "0,4,,52494646,8,4,,41564920",
780 NULL }
781 },
782 { &MEDIATYPE_Stream,
783 &MEDIASUBTYPE_MPEG1System,
784 { "0, 16, FFFFFFFFF100010001800001FFFFFFFF, 000001BA2100010001800001000001BB",
785 NULL }
786 },
787 { &MEDIATYPE_Stream,
788 &MEDIASUBTYPE_MPEG1VideoCD,
789 { "0, 4, , 52494646, 8, 8, , 43445841666D7420, 36, 20, FFFFFFFF00000000FFFFFFFFFFFFFFFFFFFFFFFF, 646174610000000000FFFFFFFFFFFFFFFFFFFF00",
790 NULL }
791 },
792 { &MEDIATYPE_Stream,
793 &MEDIASUBTYPE_MPEG1Video,
794 { "0, 4, , 000001B3",
795 NULL }
796 },
797 { &MEDIATYPE_Stream,
798 &MEDIASUBTYPE_MPEG1Audio,
799 { "0, 2, FFE0, FFE0",
800 "0, 10, FFFFFF00000080808080, 494433000000000000",
801 NULL }
802 },
803 { &MEDIATYPE_Stream,
804 &MEDIASUBTYPE_MPEG2_PROGRAM,
805 { "0, 5, FFFFFFFFC0, 000001BA40",
806 NULL }
807 },
808 { &MEDIATYPE_Stream,
809 &MEDIASUBTYPE_QTMovie,
810 { "4, 4, , 6d646174",
811 "4, 4, , 6d6f6f76",
812 NULL }
813 },
814 { &MEDIATYPE_Stream,
815 &MEDIASUBTYPE_WAVE,
816 { "0,4,,52494646,8,4,,57415645",
817 NULL }
818 },
819 { &MEDIATYPE_Stream,
820 &MEDIASUBTYPE_AU,
821 { "0,4,,2e736e64",
822 NULL }
823 },
824 { &MEDIATYPE_Stream,
825 &MEDIASUBTYPE_AIFF,
826 { "0,4,,464f524d,8,4,,41494646",
827 "0,4,,464f524d,8,4,,41494643",
828 NULL }
829 },
830 { &MEDIATYPE_Stream,
831 &MEDIATYPE_Text,
832 { "0,4,,4C595249",
833 "0,4,,6C797269",
834 NULL }
835 },
836 { &MEDIATYPE_Stream,
837 &MEDIATYPE_Midi,
838 { "0,4,,52494646,8,4,,524D4944",
839 "0,4,,4D546864",
840 NULL }
841 },
842 { NULL } /* list terminator */
843 };
844
845 /***********************************************************************
846 * mediatype list
847 */
848
849 static struct regsvr_mediatype_extension const mediatype_extension_list[] = {
850 { &MEDIATYPE_Stream,
851 &MEDIASUBTYPE_MPEG1Audio,
852 ".mp3"
853 },
854 { NULL } /* list terminator */
855 };
856
857 /***********************************************************************
858 * filter list
859 */
860
861 static struct regsvr_filter const filter_list[] = {
862 { &CLSID_AviSplitter,
863 &CLSID_LegacyAmFilterCategory,
864 {'A','V','I',' ','S','p','l','i','t','t','e','r',0},
865 0x5ffff0,
866 { { 0,
867 { { &MEDIATYPE_Stream, &MEDIASUBTYPE_Avi },
868 { NULL }
869 },
870 },
871 { REG_PINFLAG_B_OUTPUT,
872 { { &MEDIATYPE_Video, &GUID_NULL },
873 { NULL }
874 },
875 },
876 { 0xFFFFFFFF },
877 }
878 },
879 { &CLSID_MPEG1Splitter,
880 &CLSID_LegacyAmFilterCategory,
881 {'M','P','E','G','-','I',' ','S','t','r','e','a','m',' ','S','p','l','i','t','t','e','r',0},
882 0x5ffff0,
883 { { 0,
884 { { &MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1Audio },
885 { &MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1Video },
886 { &MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1System },
887 { &MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1VideoCD },
888 { NULL }
889 },
890 },
891 { REG_PINFLAG_B_OUTPUT,
892 { { &MEDIATYPE_Audio, &MEDIASUBTYPE_MPEG1Packet },
893 { &MEDIATYPE_Audio, &MEDIASUBTYPE_MPEG1AudioPayload },
894 { NULL }
895 },
896 },
897 { REG_PINFLAG_B_OUTPUT,
898 { { &MEDIATYPE_Video, &MEDIASUBTYPE_MPEG1Packet },
899 { &MEDIATYPE_Video, &MEDIASUBTYPE_MPEG1Payload },
900 { NULL }
901 },
902 },
903 { 0xFFFFFFFF },
904 }
905 },
906 { &CLSID_NullRenderer,
907 &CLSID_LegacyAmFilterCategory,
908 {'N','u','l','l',' ','R','e','n','d','e','r','e','r',0},
909 0x200000,
910 { { REG_PINFLAG_B_RENDERER,
911 { { &MEDIATYPE_NULL, &GUID_NULL },
912 { NULL }
913 },
914 },
915 { 0xFFFFFFFF },
916 }
917 },
918 { &CLSID_VideoRenderer,
919 &CLSID_LegacyAmFilterCategory,
920 {'V','i','d','e','o',' ','R','e','n','d','e','r','e','r',0},
921 0x800000,
922 { { REG_PINFLAG_B_RENDERER,
923 { { &MEDIATYPE_Video, &GUID_NULL },
924 { NULL }
925 },
926 },
927 { 0xFFFFFFFF },
928 }
929 },
930 { &CLSID_VideoRendererDefault,
931 &CLSID_LegacyAmFilterCategory,
932 {'V','i','d','e','o',' ','R','e','n','d','e','r','e','r',0},
933 0x800000,
934 { { REG_PINFLAG_B_RENDERER,
935 { { &MEDIATYPE_Video, &GUID_NULL },
936 { NULL }
937 },
938 },
939 { 0xFFFFFFFF },
940 }
941 },
942 { &CLSID_VideoMixingRenderer,
943 &CLSID_LegacyAmFilterCategory,
944 {'V','i','d','e','o',' ','M','i','x','i','n','g',' ','R','e','n','d','e','r','e','r',0},
945 0x200000,
946 { { REG_PINFLAG_B_RENDERER,
947 { { &MEDIATYPE_Video, &GUID_NULL },
948 { NULL }
949 },
950 },
951 { 0xFFFFFFFF },
952 }
953 },
954 { &CLSID_VideoMixingRenderer9,
955 &CLSID_LegacyAmFilterCategory,
956 {'V','i','d','e','o',' ','M','i','x','i','n','g',' ','R','e','n','d','e','r','e','r',' ','9',0},
957 0x200000,
958 { { REG_PINFLAG_B_RENDERER,
959 { { &MEDIATYPE_Video, &GUID_NULL },
960 { NULL }
961 },
962 },
963 { 0xFFFFFFFF },
964 }
965 },
966 { &CLSID_DSoundRender,
967 &CLSID_LegacyAmFilterCategory,
968 {'A','u','d','i','o',' ','R','e','n','d','e','r','e','r',0},
969 0x800000,
970 { { REG_PINFLAG_B_RENDERER,
971 { { &MEDIATYPE_Audio, &MEDIASUBTYPE_PCM },
972 /* { &MEDIATYPE_Audio, &MEDIASUBTYPE_IEEE_FLOAT }, */
973 { NULL }
974 },
975 },
976 { 0xFFFFFFFF },
977 }
978 },
979 { &CLSID_AudioRender,
980 &CLSID_LegacyAmFilterCategory,
981 {'A','u','d','i','o',' ','R','e','n','d','e','r','e','r',0},
982 0x800000,
983 { { REG_PINFLAG_B_RENDERER,
984 { { &MEDIATYPE_Audio, &MEDIASUBTYPE_PCM },
985 /* { &MEDIATYPE_Audio, &MEDIASUBTYPE_IEEE_FLOAT }, */
986 { NULL }
987 },
988 },
989 { 0xFFFFFFFF },
990 }
991 },
992 { &CLSID_AVIDec,
993 &CLSID_LegacyAmFilterCategory,
994 {'A','V','I',' ','D','e','c','o','m','p','r','e','s','s','o','r',0},
995 0x5ffff0,
996 { { 0,
997 { { &MEDIATYPE_Video, &GUID_NULL },
998 { NULL }
999 },
1000 },
1001 { REG_PINFLAG_B_OUTPUT,
1002 { { &MEDIATYPE_Video, &GUID_NULL },
1003 { NULL }
1004 },
1005 },
1006 { 0xFFFFFFFF },
1007 }
1008 },
1009 { &CLSID_AsyncReader,
1010 &CLSID_LegacyAmFilterCategory,
1011 {'F','i','l','e',' ','S','o','u','r','c','e',' ','(','A','s','y','n','c','.',')',0},
1012 0x400000,
1013 { { REG_PINFLAG_B_OUTPUT,
1014 { { &MEDIATYPE_Stream, &GUID_NULL },
1015 { NULL }
1016 },
1017 },
1018 { 0xFFFFFFFF },
1019 }
1020 },
1021 { &CLSID_ACMWrapper,
1022 &CLSID_LegacyAmFilterCategory,
1023 {'A','C','M',' ','W','r','a','p','p','e','r',0},
1024 0x5ffff0,
1025 { { 0,
1026 { { &MEDIATYPE_Audio, &GUID_NULL },
1027 { NULL }
1028 },
1029 },
1030 { REG_PINFLAG_B_OUTPUT,
1031 { { &MEDIATYPE_Audio, &GUID_NULL },
1032 { NULL }
1033 },
1034 },
1035 { 0xFFFFFFFF },
1036 }
1037 },
1038 { &CLSID_WAVEParser,
1039 &CLSID_LegacyAmFilterCategory,
1040 {'W','a','v','e',' ','P','a','r','s','e','r',0},
1041 0x400000,
1042 { { 0,
1043 { { &MEDIATYPE_Stream, &MEDIASUBTYPE_WAVE },
1044 { &MEDIATYPE_Stream, &MEDIASUBTYPE_AU },
1045 { &MEDIATYPE_Stream, &MEDIASUBTYPE_AIFF },
1046 { NULL }
1047 },
1048 },
1049 { REG_PINFLAG_B_OUTPUT,
1050 { { &MEDIATYPE_Audio, &GUID_NULL },
1051 { NULL }
1052 },
1053 },
1054 { 0xFFFFFFFF },
1055 }
1056 },
1057 { NULL } /* list terminator */
1058 };
1059
1060 extern HRESULT WINAPI QUARTZ_DllRegisterServer(void) DECLSPEC_HIDDEN;
1061 extern HRESULT WINAPI QUARTZ_DllUnregisterServer(void) DECLSPEC_HIDDEN;
1062
1063 /***********************************************************************
1064 * DllRegisterServer (QUARTZ.@)
1065 */
1066 HRESULT WINAPI DllRegisterServer(void)
1067 {
1068 HRESULT hr;
1069
1070 TRACE("\n");
1071
1072 hr = QUARTZ_DllRegisterServer();
1073 if (SUCCEEDED(hr))
1074 hr = register_coclasses(coclass_list);
1075 if (SUCCEEDED(hr))
1076 hr = register_interfaces(interface_list);
1077 if (SUCCEEDED(hr))
1078 hr = register_mediatypes_parsing(mediatype_parsing_list);
1079 if (SUCCEEDED(hr))
1080 hr = register_mediatypes_extension(mediatype_extension_list);
1081 if (SUCCEEDED(hr))
1082 hr = register_filters(filter_list);
1083 return hr;
1084 }
1085
1086 /***********************************************************************
1087 * DllUnregisterServer (QUARTZ.@)
1088 */
1089 HRESULT WINAPI DllUnregisterServer(void)
1090 {
1091 HRESULT hr;
1092
1093 TRACE("\n");
1094
1095 hr = unregister_filters(filter_list);
1096 if (SUCCEEDED(hr))
1097 hr = unregister_coclasses(coclass_list);
1098 if (SUCCEEDED(hr))
1099 hr = unregister_interfaces(interface_list);
1100 if (SUCCEEDED(hr))
1101 hr = unregister_mediatypes_parsing(mediatype_parsing_list);
1102 if (SUCCEEDED(hr))
1103 hr = unregister_mediatypes_extension(mediatype_extension_list);
1104 if (SUCCEEDED(hr))
1105 hr = QUARTZ_DllUnregisterServer();
1106 return hr;
1107 }