shlwapi: Handle URL_WININET_COMPATIBILITY flag in UrlCanonicalize.
[wine/multimedia.git] / dlls / gameux / regsvr.c
blob965cc12ef78ee4b4890652ffa84aca7f21603219
1 /*
2 * Gameux library self-registerable dll functions
4 * Copyright (C) 2010 Mariusz PluciƄski
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 #include "config.h"
23 #include <stdarg.h>
24 #include <string.h>
26 #define COBJMACROS
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "winreg.h"
32 #include "winerror.h"
33 #include "ole2.h"
35 #include "gameux.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(gameux);
42 * Near the bottom of this file are the exported DllRegisterServer and
43 * DllUnregisterServer, which make all this worthwhile.
46 /***********************************************************************
47 * interface for self-registering
49 struct regsvr_interface
51 IID const *iid; /* NULL for end of list */
52 LPCSTR name; /* can be NULL to omit */
53 IID const *base_iid; /* can be NULL to omit */
54 int num_methods; /* can be <0 to omit */
55 CLSID const *ps_clsid; /* can be NULL to omit */
56 CLSID const *ps_clsid32; /* can be NULL to omit */
59 static HRESULT register_interfaces(struct regsvr_interface const *list);
60 static HRESULT unregister_interfaces(struct regsvr_interface const *list);
62 struct regsvr_coclass
64 CLSID const *clsid; /* NULL for end of list */
65 LPCSTR name; /* can be NULL to omit */
66 LPCSTR ips; /* can be NULL to omit */
67 LPCSTR ips32; /* can be NULL to omit */
68 LPCSTR ips32_tmodel; /* can be NULL to omit */
69 LPCSTR progid; /* can be NULL to omit */
70 LPCSTR version; /* can be NULL to omit */
73 static HRESULT register_coclasses(struct regsvr_coclass const *list);
74 static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
76 struct progid
78 LPCSTR name; /* NULL for end of list */
79 LPCSTR description; /* can be NULL to omit */
80 CLSID const *clsid;
81 LPCSTR curver; /* can be NULL to omit */
84 static HRESULT register_progids(struct progid const *list);
85 static HRESULT unregister_progids(struct progid const *list);
87 /***********************************************************************
88 * static string constants
90 static WCHAR const interface_keyname[10] = {
91 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
92 static WCHAR const base_ifa_keyname[14] = {
93 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
94 'e', 0 };
95 static WCHAR const num_methods_keyname[11] = {
96 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
97 static WCHAR const ps_clsid_keyname[15] = {
98 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
99 'i', 'd', 0 };
100 static WCHAR const ps_clsid32_keyname[17] = {
101 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
102 'i', 'd', '3', '2', 0 };
103 static WCHAR const clsid_keyname[6] = {
104 'C', 'L', 'S', 'I', 'D', 0 };
105 static WCHAR const ips_keyname[13] = {
106 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
107 0 };
108 static WCHAR const ips32_keyname[15] = {
109 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
110 '3', '2', 0 };
111 static WCHAR const progid_keyname[7] = {
112 'P', 'r', 'o', 'g', 'I', 'D', 0 };
113 static WCHAR const versionindependentprogid_keyname[] = {
114 'V', 'e', 'r', 's', 'i', 'o', 'n',
115 'I', 'n', 'd', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 't',
116 'P', 'r', 'o', 'g', 'I', 'D', 0 };
117 static WCHAR const version_keyname[] = {
118 'V', 'e', 'r', 's', 'i', 'o', 'n', 0 };
119 static WCHAR const curver_keyname[] = {
120 'C', 'u', 'r', 'V', 'e', 'r', 0 };
121 static char const tmodel_valuename[] = "ThreadingModel";
123 /***********************************************************************
124 * static helper functions
126 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid);
127 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
128 WCHAR const *value);
129 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
130 char const *value);
132 /***********************************************************************
133 * register_interfaces
135 static HRESULT register_interfaces(struct regsvr_interface const *list)
137 LONG res = ERROR_SUCCESS;
138 HKEY interface_key;
140 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, NULL, 0,
141 KEY_READ | KEY_WRITE, NULL, &interface_key, NULL);
142 if (res != ERROR_SUCCESS) goto error_return;
144 for (; res == ERROR_SUCCESS && list->iid; ++list)
146 WCHAR buf[39];
147 HKEY iid_key;
149 StringFromGUID2(list->iid, buf, 39);
150 res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0,
151 KEY_READ | KEY_WRITE, NULL, &iid_key, NULL);
152 if (res != ERROR_SUCCESS) goto error_close_interface_key;
154 if (list->name) {
155 res = RegSetValueExA(iid_key, NULL, 0, REG_SZ,
156 (CONST BYTE*)(list->name),
157 strlen(list->name) + 1);
158 if (res != ERROR_SUCCESS) goto error_close_iid_key;
161 if (list->base_iid) {
162 res = register_key_guid(iid_key, base_ifa_keyname, list->base_iid);
163 if (res != ERROR_SUCCESS) goto error_close_iid_key;
166 if (0 <= list->num_methods) {
167 static WCHAR const fmt[3] = { '%', 'd', 0 };
168 HKEY key;
170 res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0,
171 KEY_READ | KEY_WRITE, NULL, &key, NULL);
172 if (res != ERROR_SUCCESS) goto error_close_iid_key;
174 wsprintfW(buf, fmt, list->num_methods);
175 res = RegSetValueExW(key, NULL, 0, REG_SZ,
176 (CONST BYTE*)buf,
177 (lstrlenW(buf) + 1) * sizeof(WCHAR));
178 RegCloseKey(key);
180 if (res != ERROR_SUCCESS) goto error_close_iid_key;
183 if (list->ps_clsid) {
184 res = register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid);
185 if (res != ERROR_SUCCESS) goto error_close_iid_key;
188 if (list->ps_clsid32) {
189 res = register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32);
190 if (res != ERROR_SUCCESS) goto error_close_iid_key;
193 error_close_iid_key:
194 RegCloseKey(iid_key);
197 error_close_interface_key:
198 RegCloseKey(interface_key);
199 error_return:
200 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
203 /***********************************************************************
204 * unregister_interfaces
206 static HRESULT unregister_interfaces(struct regsvr_interface const *list)
208 LONG res = ERROR_SUCCESS;
209 HKEY interface_key;
211 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0,
212 KEY_READ | KEY_WRITE, &interface_key);
213 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
214 if (res != ERROR_SUCCESS) goto error_return;
216 for (; res == ERROR_SUCCESS && list->iid; ++list) {
217 WCHAR buf[39];
219 StringFromGUID2(list->iid, buf, 39);
220 res = RegDeleteTreeW(interface_key, buf);
221 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
224 RegCloseKey(interface_key);
225 error_return:
226 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
229 /***********************************************************************
230 * register_coclasses
232 static HRESULT register_coclasses(struct regsvr_coclass const *list)
234 LONG res = ERROR_SUCCESS;
235 HKEY coclass_key;
237 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
238 KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
239 if (res != ERROR_SUCCESS) goto error_return;
241 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
242 WCHAR buf[39];
243 HKEY clsid_key;
245 StringFromGUID2(list->clsid, buf, 39);
246 res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
247 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
248 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
250 if (list->name) {
251 res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
252 (CONST BYTE*)(list->name),
253 strlen(list->name) + 1);
254 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
257 if (list->ips) {
258 res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
259 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
262 if (list->ips32) {
263 HKEY ips32_key;
265 res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
266 KEY_READ | KEY_WRITE, NULL,
267 &ips32_key, NULL);
268 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
270 res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
271 (CONST BYTE*)list->ips32,
272 lstrlenA(list->ips32) + 1);
273 if (res == ERROR_SUCCESS && list->ips32_tmodel)
274 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
275 (CONST BYTE*)list->ips32_tmodel,
276 strlen(list->ips32_tmodel) + 1);
277 RegCloseKey(ips32_key);
278 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
281 if (list->progid) {
282 char *buffer = NULL;
283 LPCSTR progid;
285 if (list->version) {
286 buffer = HeapAlloc(GetProcessHeap(), 0, strlen(list->progid) + strlen(list->version) + 2);
287 if (!buffer) {
288 res = ERROR_OUTOFMEMORY;
289 goto error_close_clsid_key;
291 strcpy(buffer, list->progid);
292 strcat(buffer, ".");
293 strcat(buffer, list->version);
294 progid = buffer;
295 } else
296 progid = list->progid;
298 res = register_key_defvalueA(clsid_key, progid_keyname, progid);
299 HeapFree(GetProcessHeap(), 0, buffer);
300 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
302 if (list->version) {
303 res = register_key_defvalueA(clsid_key, versionindependentprogid_keyname, list->progid);
304 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
308 if (list->version) {
309 res = register_key_defvalueA(clsid_key, version_keyname, list->version);
310 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
313 error_close_clsid_key:
314 RegCloseKey(clsid_key);
317 error_close_coclass_key:
318 RegCloseKey(coclass_key);
319 error_return:
320 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
323 /***********************************************************************
324 * unregister_coclasses
326 static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
328 LONG res = ERROR_SUCCESS;
329 HKEY coclass_key;
331 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
332 KEY_READ | KEY_WRITE, &coclass_key);
333 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
334 if (res != ERROR_SUCCESS) goto error_return;
336 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
337 WCHAR buf[39];
339 StringFromGUID2(list->clsid, buf, 39);
340 res = RegDeleteTreeW(coclass_key, buf);
341 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
342 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
345 error_close_coclass_key:
346 RegCloseKey(coclass_key);
347 error_return:
348 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
351 /***********************************************************************
352 * register_progids
354 static HRESULT register_progids(struct progid const *list)
356 LONG res = ERROR_SUCCESS;
358 for (; res == ERROR_SUCCESS && list->name; ++list) {
359 WCHAR buf[39];
360 HKEY progid_key;
362 res = RegCreateKeyExA(HKEY_CLASSES_ROOT, list->name, 0,
363 NULL, 0, KEY_READ | KEY_WRITE, NULL,
364 &progid_key, NULL);
365 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
367 res = RegSetValueExA(progid_key, NULL, 0, REG_SZ,
368 (CONST BYTE*)list->description,
369 strlen(list->description) + 1);
370 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
372 StringFromGUID2(list->clsid, buf, 39);
374 res = register_key_defvalueW(progid_key, clsid_keyname, buf);
375 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
377 if (list->curver) {
378 res = register_key_defvalueA(progid_key, curver_keyname, list->curver);
379 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
382 error_close_clsid_key:
383 RegCloseKey(progid_key);
386 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
389 /***********************************************************************
390 * unregister_progids
392 static HRESULT unregister_progids(struct progid const *list)
394 LONG res = ERROR_SUCCESS;
396 for (; res == ERROR_SUCCESS && list->name; ++list) {
397 res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->name);
398 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
401 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
404 /***********************************************************************
405 * regsvr_key_guid
407 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid)
409 WCHAR buf[39];
411 StringFromGUID2(guid, buf, 39);
412 return register_key_defvalueW(base, name, buf);
415 /***********************************************************************
416 * regsvr_key_defvalueW
418 static LONG register_key_defvalueW(
419 HKEY base,
420 WCHAR const *name,
421 WCHAR const *value)
423 LONG res;
424 HKEY key;
426 res = RegCreateKeyExW(base, name, 0, NULL, 0,
427 KEY_READ | KEY_WRITE, NULL, &key, NULL);
428 if (res != ERROR_SUCCESS) return res;
429 res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
430 (lstrlenW(value) + 1) * sizeof(WCHAR));
431 RegCloseKey(key);
432 return res;
435 /***********************************************************************
436 * regsvr_key_defvalueA
438 static LONG register_key_defvalueA(
439 HKEY base,
440 WCHAR const *name,
441 char const *value)
443 LONG res;
444 HKEY key;
446 res = RegCreateKeyExW(base, name, 0, NULL, 0,
447 KEY_READ | KEY_WRITE, NULL, &key, NULL);
448 if (res != ERROR_SUCCESS) return res;
449 res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
450 lstrlenA(value) + 1);
451 RegCloseKey(key);
452 return res;
455 /***********************************************************************
456 * coclass list
458 static struct regsvr_coclass const coclass_list[] = {
459 { &CLSID_GameExplorer,
460 "GameExplorer Class",
461 NULL,
462 "gameux.dll",
463 "Both",
464 "gameux.GameExplorer.1",
465 "1.0",
468 &CLSID_GameStatistics,
469 "GameStatistics Class",
470 NULL,
471 "gameux.dll",
472 "Apartment",
473 "gameux.GameStatistics.1",
474 "1,0",
476 { NULL } /* list terminator */
479 /***********************************************************************
480 * interface list
482 static struct regsvr_interface const interface_list[] = {
483 { NULL } /* list terminator */
486 /***********************************************************************
487 * progid list
489 static struct progid const progid_list[] = {
490 { "gameux.GameExplorer",
491 "GameExplorer Class",
492 &CLSID_GameExplorer,
493 NULL
495 { NULL } /* list terminator */
498 /***********************************************************************
499 * DllRegisterServer (GAMEUX.@)
501 HRESULT WINAPI DllRegisterServer(void)
503 HRESULT hr;
505 TRACE("\n");
507 hr = register_coclasses(coclass_list);
508 if (SUCCEEDED(hr))
509 hr = register_interfaces(interface_list);
510 if (SUCCEEDED(hr))
511 hr = register_progids(progid_list);
513 return hr;
516 /***********************************************************************
517 * DllUnregisterServer (GAMEUX.@)
519 HRESULT WINAPI DllUnregisterServer(void)
521 HRESULT hr;
523 TRACE("\n");
525 hr = unregister_coclasses(coclass_list);
526 if (SUCCEEDED(hr))
527 hr = unregister_interfaces(interface_list);
528 if (SUCCEEDED(hr))
529 hr = unregister_progids(progid_list);
531 return hr;