windowscodecs: Fix ICO palette size calculation.
[wine/multimedia.git] / dlls / msxml4 / regsvr.c
blobe4b1a0d3d345ff996fa415847fa00454795a338d
1 /*
2 * MSXML4 self-registerable dll functions
4 * Copyright (C) 2003 John K. Hohm
5 * Copyright (C) 2006 Robert Shearman
6 * Copyright (C) 2008 Alistair Leslie-Hughes
7 * Copyright (C) 2010 Nikolay Sivov
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
26 #include <stdarg.h>
27 #include <string.h>
29 #define COBJMACROS
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "winreg.h"
35 #include "winerror.h"
36 #include "ole2.h"
38 #include "initguid.h"
39 #include "msxml2.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msxml4);
46 * Near the bottom of this file are the exported DllRegisterServer and
47 * DllUnregisterServer, which make all this worthwhile.
50 struct regsvr_coclass
52 CLSID const *clsid; /* NULL for end of list */
53 LPCSTR name; /* can be NULL to omit */
54 LPCSTR ips; /* can be NULL to omit */
55 LPCSTR ips32; /* can be NULL to omit */
56 LPCSTR ips32_tmodel; /* can be NULL to omit */
57 LPCSTR progid; /* can be NULL to omit */
58 LPCSTR version; /* can be NULL to omit */
61 static HRESULT register_coclasses(struct regsvr_coclass const *list);
62 static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
64 struct progid
66 LPCSTR name; /* NULL for end of list */
67 LPCSTR description; /* can be NULL to omit */
68 CLSID const *clsid;
69 LPCSTR curver; /* can be NULL to omit */
72 static HRESULT register_progids(struct progid const *list);
73 static HRESULT unregister_progids(struct progid const *list);
75 /***********************************************************************
76 * static string constants
78 static WCHAR const interface_keyname[10] = {
79 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
80 static WCHAR const base_ifa_keyname[14] = {
81 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
82 'e', 0 };
83 static WCHAR const num_methods_keyname[11] = {
84 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
85 static WCHAR const ps_clsid_keyname[15] = {
86 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
87 'i', 'd', 0 };
88 static WCHAR const ps_clsid32_keyname[17] = {
89 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
90 'i', 'd', '3', '2', 0 };
91 static WCHAR const clsid_keyname[6] = {
92 'C', 'L', 'S', 'I', 'D', 0 };
93 static WCHAR const ips_keyname[13] = {
94 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
95 0 };
96 static WCHAR const ips32_keyname[15] = {
97 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
98 '3', '2', 0 };
99 static WCHAR const progid_keyname[7] = {
100 'P', 'r', 'o', 'g', 'I', 'D', 0 };
101 static WCHAR const versionindependentprogid_keyname[] = {
102 'V', 'e', 'r', 's', 'i', 'o', 'n',
103 'I', 'n', 'd', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 't',
104 'P', 'r', 'o', 'g', 'I', 'D', 0 };
105 static WCHAR const version_keyname[] = {
106 'V', 'e', 'r', 's', 'i', 'o', 'n', 0 };
107 static WCHAR const curver_keyname[] = {
108 'C', 'u', 'r', 'V', 'e', 'r', 0 };
109 static char const tmodel_valuename[] = "ThreadingModel";
111 /***********************************************************************
112 * static helper functions
114 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
115 WCHAR const *value);
116 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
117 char const *value);
119 /***********************************************************************
120 * register_coclasses
122 static HRESULT register_coclasses(struct regsvr_coclass const *list)
124 LONG res = ERROR_SUCCESS;
125 HKEY coclass_key;
127 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
128 KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
129 if (res != ERROR_SUCCESS) goto error_return;
131 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
132 WCHAR buf[39];
133 HKEY clsid_key;
135 StringFromGUID2(list->clsid, buf, 39);
136 res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
137 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
138 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
140 if (list->name) {
141 res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
142 (CONST BYTE*)(list->name),
143 strlen(list->name) + 1);
144 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
147 if (list->ips) {
148 res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
149 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
152 if (list->ips32) {
153 HKEY ips32_key;
155 res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
156 KEY_READ | KEY_WRITE, NULL,
157 &ips32_key, NULL);
158 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
160 res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
161 (CONST BYTE*)list->ips32,
162 lstrlenA(list->ips32) + 1);
163 if (res == ERROR_SUCCESS && list->ips32_tmodel)
164 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
165 (CONST BYTE*)list->ips32_tmodel,
166 strlen(list->ips32_tmodel) + 1);
167 RegCloseKey(ips32_key);
168 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
171 if (list->progid) {
172 char *buffer = NULL;
173 LPCSTR progid;
175 if (list->version) {
176 buffer = HeapAlloc(GetProcessHeap(), 0, strlen(list->progid) + strlen(list->version) + 2);
177 if (!buffer) {
178 res = ERROR_OUTOFMEMORY;
179 goto error_close_clsid_key;
181 strcpy(buffer, list->progid);
182 strcat(buffer, ".");
183 strcat(buffer, list->version);
184 progid = buffer;
185 } else
186 progid = list->progid;
187 res = register_key_defvalueA(clsid_key, progid_keyname,
188 progid);
189 HeapFree(GetProcessHeap(), 0, buffer);
190 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
192 if (list->version) {
193 res = register_key_defvalueA(clsid_key, versionindependentprogid_keyname,
194 list->progid);
195 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
199 if (list->version) {
200 res = register_key_defvalueA(clsid_key, version_keyname,
201 list->version);
202 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
205 error_close_clsid_key:
206 RegCloseKey(clsid_key);
209 error_close_coclass_key:
210 RegCloseKey(coclass_key);
211 error_return:
212 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
215 /***********************************************************************
216 * unregister_coclasses
218 static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
220 LONG res = ERROR_SUCCESS;
221 HKEY coclass_key;
223 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
224 KEY_READ | KEY_WRITE, &coclass_key);
225 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
226 if (res != ERROR_SUCCESS) goto error_return;
228 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
229 WCHAR buf[39];
231 StringFromGUID2(list->clsid, buf, 39);
232 res = RegDeleteTreeW(coclass_key, buf);
233 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
234 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
237 error_close_coclass_key:
238 RegCloseKey(coclass_key);
239 error_return:
240 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
243 /***********************************************************************
244 * register_progids
246 static HRESULT register_progids(struct progid const *list)
248 LONG res = ERROR_SUCCESS;
250 for (; res == ERROR_SUCCESS && list->name; ++list) {
251 WCHAR buf[39];
252 HKEY progid_key;
254 res = RegCreateKeyExA(HKEY_CLASSES_ROOT, list->name, 0,
255 NULL, 0, KEY_READ | KEY_WRITE, NULL,
256 &progid_key, NULL);
257 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
259 res = RegSetValueExA(progid_key, NULL, 0, REG_SZ,
260 (CONST BYTE*)list->description,
261 strlen(list->description) + 1);
262 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
264 StringFromGUID2(list->clsid, buf, 39);
266 res = register_key_defvalueW(progid_key, clsid_keyname, buf);
267 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
269 if (list->curver) {
270 res = register_key_defvalueA(progid_key, curver_keyname, list->curver);
271 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
274 error_close_clsid_key:
275 RegCloseKey(progid_key);
278 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
281 /***********************************************************************
282 * unregister_progids
284 static HRESULT unregister_progids(struct progid const *list)
286 LONG res = ERROR_SUCCESS;
288 for (; res == ERROR_SUCCESS && list->name; ++list) {
289 res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->name);
290 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
293 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
296 /***********************************************************************
297 * regsvr_key_defvalueW
299 static LONG register_key_defvalueW(
300 HKEY base,
301 WCHAR const *name,
302 WCHAR const *value)
304 LONG res;
305 HKEY key;
307 res = RegCreateKeyExW(base, name, 0, NULL, 0,
308 KEY_READ | KEY_WRITE, NULL, &key, NULL);
309 if (res != ERROR_SUCCESS) return res;
310 res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
311 (lstrlenW(value) + 1) * sizeof(WCHAR));
312 RegCloseKey(key);
313 return res;
316 /***********************************************************************
317 * regsvr_key_defvalueA
319 static LONG register_key_defvalueA(
320 HKEY base,
321 WCHAR const *name,
322 char const *value)
324 LONG res;
325 HKEY key;
327 res = RegCreateKeyExW(base, name, 0, NULL, 0,
328 KEY_READ | KEY_WRITE, NULL, &key, NULL);
329 if (res != ERROR_SUCCESS) return res;
330 res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
331 lstrlenA(value) + 1);
332 RegCloseKey(key);
333 return res;
336 /***********************************************************************
337 * coclass list
339 static struct regsvr_coclass const coclass_list[] = {
340 { &CLSID_DOMDocument40,
341 "XML DOM Document 4.0",
342 NULL,
343 "msxml4.dll",
344 "Both",
345 "Msxml2.DOMDocument",
346 "4.0"
348 { &CLSID_SAXXMLReader40,
349 "SAX XML Reader 4.0",
350 NULL,
351 "msxml4.dll",
352 "Both",
353 "Msxml2.SAXXMLReader",
354 "4.0"
356 { &CLSID_XMLSchemaCache40,
357 "XML Schema Cache 4.0",
358 NULL,
359 "msxml4.dll",
360 "Both",
361 "Msxml2.XMLSchemaCache",
362 "4.0"
364 { &CLSID_MXXMLWriter40,
365 "IMXWriter interface 4.0",
366 NULL,
367 "msxml4.dll",
368 "Both",
369 "Msxml2.MXXMLWriter",
370 "4.0"
372 { &CLSID_SAXAttributes40,
373 "SAX Attribute 4.0",
374 NULL,
375 "msxml4.dll",
376 "Both",
377 "Msxml2.SAXAttributes",
378 "4.0"
380 { &CLSID_FreeThreadedDOMDocument40,
381 "Free Threaded XML DOM Document 4.0",
382 NULL,
383 "msxml4.dll",
384 "Both",
385 "Microsoft.FreeThreadedDOMDocument4.0",
386 "4.0"
388 { NULL } /* list terminator */
391 /***********************************************************************
392 * progid list
394 static struct progid const progid_list[] = {
395 { "Msxml2.DOMDocument.4.0",
396 "XML DOM Document 4.0",
397 &CLSID_DOMDocument40,
398 NULL
400 { "Msxml2.SAXXMLReader.4.0",
401 "SAX XML Reader 4.0",
402 &CLSID_SAXXMLReader40,
403 NULL
405 { "Msxml2.XMLSchemaCache.4.0",
406 "XML Schema Cache 4.0",
407 &CLSID_XMLSchemaCache40,
408 NULL
410 { "Msxml2.MXXMLWriter.4.0",
411 "MXXMLWriter 4.0",
412 &CLSID_MXXMLWriter40,
413 NULL
415 { "Msxml2.SAXAttributes.4.0",
416 "SAX Attribute 4.0",
417 &CLSID_SAXAttributes40,
418 NULL
420 { "MSXML.FreeThreadedDOMDocument40",
421 "Free threaded XML DOM Document 4.0",
422 &CLSID_FreeThreadedDOMDocument40,
423 NULL
425 { NULL } /* list terminator */
428 /***********************************************************************
429 * DllRegisterServer (MSXML4.@)
431 HRESULT WINAPI DllRegisterServer(void)
433 HRESULT hr;
435 TRACE("\n");
437 hr = register_coclasses(coclass_list);
438 if (SUCCEEDED(hr))
439 hr = register_progids(progid_list);
441 return hr;
444 /***********************************************************************
445 * DllUnregisterServer (MSXML4.@)
447 HRESULT WINAPI DllUnregisterServer(void)
449 HRESULT hr;
451 TRACE("\n");
453 hr = unregister_coclasses(coclass_list);
454 if (SUCCEEDED(hr))
455 hr = unregister_progids(progid_list);
457 return hr;