2 * MSXML3 self-registerable dll functions
4 * Copyright (C) 2003 John K. Hohm
5 * Copyright (C) 2006 Robert Shearman
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 #include "msxml_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ole);
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);
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 clsid_str; /* can be NULL to omit */
70 LPCSTR progid; /* 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 /***********************************************************************
77 * static string constants
79 static WCHAR const interface_keyname[10] = {
80 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
81 static WCHAR const base_ifa_keyname[14] = {
82 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
84 static WCHAR const num_methods_keyname[11] = {
85 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
86 static WCHAR const ps_clsid_keyname[15] = {
87 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
89 static WCHAR const ps_clsid32_keyname[17] = {
90 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
91 'i', 'd', '3', '2', 0 };
92 static WCHAR const clsid_keyname[6] = {
93 'C', 'L', 'S', 'I', 'D', 0 };
94 static WCHAR const ips_keyname[13] = {
95 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
97 static WCHAR const ips32_keyname[15] = {
98 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
100 static WCHAR const progid_keyname[7] = {
101 'P', 'r', 'o', 'g', 'I', 'D', 0 };
102 static char const tmodel_valuename[] = "ThreadingModel";
104 /***********************************************************************
105 * static helper functions
107 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid);
108 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
110 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
112 static LONG recursive_delete_key(HKEY key);
113 static LONG recursive_delete_keyA(HKEY base, char const *name);
114 static LONG recursive_delete_keyW(HKEY base, WCHAR const *name);
116 /***********************************************************************
117 * register_interfaces
119 static HRESULT register_interfaces(struct regsvr_interface const *list)
121 LONG res = ERROR_SUCCESS;
124 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, NULL, 0,
125 KEY_READ | KEY_WRITE, NULL, &interface_key, NULL);
126 if (res != ERROR_SUCCESS) goto error_return;
128 for (; res == ERROR_SUCCESS && list->iid; ++list) {
132 StringFromGUID2(list->iid, buf, 39);
133 res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0,
134 KEY_READ | KEY_WRITE, NULL, &iid_key, NULL);
135 if (res != ERROR_SUCCESS) goto error_close_interface_key;
138 res = RegSetValueExA(iid_key, NULL, 0, REG_SZ,
139 (CONST BYTE*)(list->name),
140 strlen(list->name) + 1);
141 if (res != ERROR_SUCCESS) goto error_close_iid_key;
144 if (list->base_iid) {
145 res = register_key_guid(iid_key, base_ifa_keyname, list->base_iid);
146 if (res != ERROR_SUCCESS) goto error_close_iid_key;
149 if (0 <= list->num_methods) {
150 static WCHAR const fmt[3] = { '%', 'd', 0 };
153 res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0,
154 KEY_READ | KEY_WRITE, NULL, &key, NULL);
155 if (res != ERROR_SUCCESS) goto error_close_iid_key;
157 wsprintfW(buf, fmt, list->num_methods);
158 res = RegSetValueExW(key, NULL, 0, REG_SZ,
160 (lstrlenW(buf) + 1) * sizeof(WCHAR));
163 if (res != ERROR_SUCCESS) goto error_close_iid_key;
166 if (list->ps_clsid) {
167 res = register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid);
168 if (res != ERROR_SUCCESS) goto error_close_iid_key;
171 if (list->ps_clsid32) {
172 res = register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32);
173 if (res != ERROR_SUCCESS) goto error_close_iid_key;
177 RegCloseKey(iid_key);
180 error_close_interface_key:
181 RegCloseKey(interface_key);
183 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
186 /***********************************************************************
187 * unregister_interfaces
189 static HRESULT unregister_interfaces(struct regsvr_interface const *list)
191 LONG res = ERROR_SUCCESS;
194 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0,
195 KEY_READ | KEY_WRITE, &interface_key);
196 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
197 if (res != ERROR_SUCCESS) goto error_return;
199 for (; res == ERROR_SUCCESS && list->iid; ++list) {
202 StringFromGUID2(list->iid, buf, 39);
203 res = recursive_delete_keyW(interface_key, buf);
206 RegCloseKey(interface_key);
208 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
211 /***********************************************************************
214 static HRESULT register_coclasses(struct regsvr_coclass const *list)
216 LONG res = ERROR_SUCCESS;
219 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
220 KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
221 if (res != ERROR_SUCCESS) goto error_return;
223 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
227 StringFromGUID2(list->clsid, buf, 39);
228 res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
229 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
230 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
233 res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
234 (CONST BYTE*)(list->name),
235 strlen(list->name) + 1);
236 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
240 res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
241 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
247 res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
248 KEY_READ | KEY_WRITE, NULL,
250 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
252 res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
253 (CONST BYTE*)list->ips32,
254 lstrlenA(list->ips32) + 1);
255 if (res == ERROR_SUCCESS && list->ips32_tmodel)
256 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
257 (CONST BYTE*)list->ips32_tmodel,
258 strlen(list->ips32_tmodel) + 1);
259 RegCloseKey(ips32_key);
260 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
263 if (list->clsid_str) {
264 res = register_key_defvalueA(clsid_key, clsid_keyname,
266 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
272 res = register_key_defvalueA(clsid_key, progid_keyname,
274 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
276 res = RegCreateKeyExA(HKEY_CLASSES_ROOT, list->progid, 0,
277 NULL, 0, KEY_READ | KEY_WRITE, NULL,
279 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
281 res = register_key_defvalueW(progid_key, clsid_keyname, buf);
282 RegCloseKey(progid_key);
283 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
286 error_close_clsid_key:
287 RegCloseKey(clsid_key);
290 error_close_coclass_key:
291 RegCloseKey(coclass_key);
293 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
296 /***********************************************************************
297 * unregister_coclasses
299 static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
301 LONG res = ERROR_SUCCESS;
304 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
305 KEY_READ | KEY_WRITE, &coclass_key);
306 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
307 if (res != ERROR_SUCCESS) goto error_return;
309 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
312 StringFromGUID2(list->clsid, buf, 39);
313 res = recursive_delete_keyW(coclass_key, buf);
314 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
317 res = recursive_delete_keyA(HKEY_CLASSES_ROOT, list->progid);
318 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
322 error_close_coclass_key:
323 RegCloseKey(coclass_key);
325 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
328 /***********************************************************************
331 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid)
335 StringFromGUID2(guid, buf, 39);
336 return register_key_defvalueW(base, name, buf);
339 /***********************************************************************
340 * regsvr_key_defvalueW
342 static LONG register_key_defvalueW(
350 res = RegCreateKeyExW(base, name, 0, NULL, 0,
351 KEY_READ | KEY_WRITE, NULL, &key, NULL);
352 if (res != ERROR_SUCCESS) return res;
353 res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
354 (lstrlenW(value) + 1) * sizeof(WCHAR));
359 /***********************************************************************
360 * regsvr_key_defvalueA
362 static LONG register_key_defvalueA(
370 res = RegCreateKeyExW(base, name, 0, NULL, 0,
371 KEY_READ | KEY_WRITE, NULL, &key, NULL);
372 if (res != ERROR_SUCCESS) return res;
373 res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
374 lstrlenA(value) + 1);
379 /***********************************************************************
380 * recursive_delete_key
382 static LONG recursive_delete_key(HKEY key)
385 WCHAR subkey_name[MAX_PATH];
390 cName = sizeof(subkey_name) / sizeof(WCHAR);
391 res = RegEnumKeyExW(key, 0, subkey_name, &cName,
392 NULL, NULL, NULL, NULL);
393 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) {
394 res = ERROR_SUCCESS; /* presumably we're done enumerating */
397 res = RegOpenKeyExW(key, subkey_name, 0,
398 KEY_READ | KEY_WRITE, &subkey);
399 if (res == ERROR_FILE_NOT_FOUND) continue;
400 if (res != ERROR_SUCCESS) break;
402 res = recursive_delete_key(subkey);
404 if (res != ERROR_SUCCESS) break;
407 if (res == ERROR_SUCCESS) res = RegDeleteKeyW(key, 0);
411 /***********************************************************************
412 * recursive_delete_keyA
414 static LONG recursive_delete_keyA(HKEY base, char const *name)
419 res = RegOpenKeyExA(base, name, 0, KEY_READ | KEY_WRITE, &key);
420 if (res == ERROR_FILE_NOT_FOUND) return ERROR_SUCCESS;
421 if (res != ERROR_SUCCESS) return res;
422 res = recursive_delete_key(key);
427 /***********************************************************************
428 * recursive_delete_keyW
430 static LONG recursive_delete_keyW(HKEY base, WCHAR const *name)
435 res = RegOpenKeyExW(base, name, 0, KEY_READ | KEY_WRITE, &key);
436 if (res == ERROR_FILE_NOT_FOUND) return ERROR_SUCCESS;
437 if (res != ERROR_SUCCESS) return res;
438 res = recursive_delete_key(key);
443 /***********************************************************************
446 static struct regsvr_coclass const coclass_list[] = {
447 { &CLSID_DOMDocument,
455 { &CLSID_DOMFreeThreadedDocument,
456 "Free threaded XML DOM Document",
460 "Free threaded XML DOM Document",
461 "Microsoft.FreeThreadedXMLDOM"
463 { &CLSID_XMLHTTPRequest,
471 { &CLSID_XMLDSOControl,
472 "XML Data Source Object",
476 "XML Data Source Object",
479 { &CLSID_XMLDocument,
487 { NULL } /* list terminator */
490 /***********************************************************************
493 static struct regsvr_interface const interface_list[] = {
494 { NULL } /* list terminator */
497 /***********************************************************************
498 * DllRegisterServer (OLEAUT32.@)
500 HRESULT WINAPI DllRegisterServer(void)
506 hr = register_coclasses(coclass_list);
508 hr = register_interfaces(interface_list);
512 /***********************************************************************
513 * DllUnregisterServer (OLEAUT32.@)
515 HRESULT WINAPI DllUnregisterServer(void)
521 hr = unregister_coclasses(coclass_list);
523 hr = unregister_interfaces(interface_list);