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 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
);
78 LPCSTR name
; /* NULL for end of list */
79 LPCSTR description
; /* can be NULL to omit */
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',
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',
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',
108 static WCHAR
const ips32_keyname
[15] = {
109 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
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
,
129 static LONG
register_key_defvalueA(HKEY base
, WCHAR
const *name
,
131 static LONG
recursive_delete_key(HKEY key
);
132 static LONG
recursive_delete_keyA(HKEY base
, char const *name
);
133 static LONG
recursive_delete_keyW(HKEY base
, WCHAR
const *name
);
135 /***********************************************************************
136 * register_interfaces
138 static HRESULT
register_interfaces(struct regsvr_interface
const *list
)
140 LONG res
= ERROR_SUCCESS
;
143 res
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, interface_keyname
, 0, NULL
, 0,
144 KEY_READ
| KEY_WRITE
, NULL
, &interface_key
, NULL
);
145 if (res
!= ERROR_SUCCESS
) goto error_return
;
147 for (; res
== ERROR_SUCCESS
&& list
->iid
; ++list
) {
151 StringFromGUID2(list
->iid
, buf
, 39);
152 res
= RegCreateKeyExW(interface_key
, buf
, 0, NULL
, 0,
153 KEY_READ
| KEY_WRITE
, NULL
, &iid_key
, NULL
);
154 if (res
!= ERROR_SUCCESS
) goto error_close_interface_key
;
157 res
= RegSetValueExA(iid_key
, NULL
, 0, REG_SZ
,
158 (CONST BYTE
*)(list
->name
),
159 strlen(list
->name
) + 1);
160 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
163 if (list
->base_iid
) {
164 res
= register_key_guid(iid_key
, base_ifa_keyname
, list
->base_iid
);
165 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
168 if (0 <= list
->num_methods
) {
169 static WCHAR
const fmt
[3] = { '%', 'd', 0 };
172 res
= RegCreateKeyExW(iid_key
, num_methods_keyname
, 0, NULL
, 0,
173 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
174 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
176 wsprintfW(buf
, fmt
, list
->num_methods
);
177 res
= RegSetValueExW(key
, NULL
, 0, REG_SZ
,
179 (lstrlenW(buf
) + 1) * sizeof(WCHAR
));
182 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
185 if (list
->ps_clsid
) {
186 res
= register_key_guid(iid_key
, ps_clsid_keyname
, list
->ps_clsid
);
187 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
190 if (list
->ps_clsid32
) {
191 res
= register_key_guid(iid_key
, ps_clsid32_keyname
, list
->ps_clsid32
);
192 if (res
!= ERROR_SUCCESS
) goto error_close_iid_key
;
196 RegCloseKey(iid_key
);
199 error_close_interface_key
:
200 RegCloseKey(interface_key
);
202 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
205 /***********************************************************************
206 * unregister_interfaces
208 static HRESULT
unregister_interfaces(struct regsvr_interface
const *list
)
210 LONG res
= ERROR_SUCCESS
;
213 res
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, interface_keyname
, 0,
214 KEY_READ
| KEY_WRITE
, &interface_key
);
215 if (res
== ERROR_FILE_NOT_FOUND
) return S_OK
;
216 if (res
!= ERROR_SUCCESS
) goto error_return
;
218 for (; res
== ERROR_SUCCESS
&& list
->iid
; ++list
) {
221 StringFromGUID2(list
->iid
, buf
, 39);
222 res
= recursive_delete_keyW(interface_key
, buf
);
225 RegCloseKey(interface_key
);
227 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
230 /***********************************************************************
233 static HRESULT
register_coclasses(struct regsvr_coclass
const *list
)
235 LONG res
= ERROR_SUCCESS
;
238 res
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, clsid_keyname
, 0, NULL
, 0,
239 KEY_READ
| KEY_WRITE
, NULL
, &coclass_key
, NULL
);
240 if (res
!= ERROR_SUCCESS
) goto error_return
;
242 for (; res
== ERROR_SUCCESS
&& list
->clsid
; ++list
) {
246 StringFromGUID2(list
->clsid
, buf
, 39);
247 res
= RegCreateKeyExW(coclass_key
, buf
, 0, NULL
, 0,
248 KEY_READ
| KEY_WRITE
, NULL
, &clsid_key
, NULL
);
249 if (res
!= ERROR_SUCCESS
) goto error_close_coclass_key
;
252 res
= RegSetValueExA(clsid_key
, NULL
, 0, REG_SZ
,
253 (CONST BYTE
*)(list
->name
),
254 strlen(list
->name
) + 1);
255 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
259 res
= register_key_defvalueA(clsid_key
, ips_keyname
, list
->ips
);
260 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
266 res
= RegCreateKeyExW(clsid_key
, ips32_keyname
, 0, NULL
, 0,
267 KEY_READ
| KEY_WRITE
, NULL
,
269 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
271 res
= RegSetValueExA(ips32_key
, NULL
, 0, REG_SZ
,
272 (CONST BYTE
*)list
->ips32
,
273 lstrlenA(list
->ips32
) + 1);
274 if (res
== ERROR_SUCCESS
&& list
->ips32_tmodel
)
275 res
= RegSetValueExA(ips32_key
, tmodel_valuename
, 0, REG_SZ
,
276 (CONST BYTE
*)list
->ips32_tmodel
,
277 strlen(list
->ips32_tmodel
) + 1);
278 RegCloseKey(ips32_key
);
279 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
287 buffer
= HeapAlloc(GetProcessHeap(), 0, strlen(list
->progid
) + strlen(list
->version
) + 2);
289 res
= ERROR_OUTOFMEMORY
;
290 goto error_close_clsid_key
;
292 strcpy(buffer
, list
->progid
);
294 strcat(buffer
, list
->version
);
297 progid
= list
->progid
;
298 res
= register_key_defvalueA(clsid_key
, progid_keyname
,
300 HeapFree(GetProcessHeap(), 0, buffer
);
301 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
304 res
= register_key_defvalueA(clsid_key
, versionindependentprogid_keyname
,
306 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
311 res
= register_key_defvalueA(clsid_key
, version_keyname
,
313 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
316 error_close_clsid_key
:
317 RegCloseKey(clsid_key
);
320 error_close_coclass_key
:
321 RegCloseKey(coclass_key
);
323 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
326 /***********************************************************************
327 * unregister_coclasses
329 static HRESULT
unregister_coclasses(struct regsvr_coclass
const *list
)
331 LONG res
= ERROR_SUCCESS
;
334 res
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, clsid_keyname
, 0,
335 KEY_READ
| KEY_WRITE
, &coclass_key
);
336 if (res
== ERROR_FILE_NOT_FOUND
) return S_OK
;
337 if (res
!= ERROR_SUCCESS
) goto error_return
;
339 for (; res
== ERROR_SUCCESS
&& list
->clsid
; ++list
) {
342 StringFromGUID2(list
->clsid
, buf
, 39);
343 res
= recursive_delete_keyW(coclass_key
, buf
);
344 if (res
!= ERROR_SUCCESS
) goto error_close_coclass_key
;
347 error_close_coclass_key
:
348 RegCloseKey(coclass_key
);
350 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
353 /***********************************************************************
356 static HRESULT
register_progids(struct progid
const *list
)
358 LONG res
= ERROR_SUCCESS
;
360 for (; res
== ERROR_SUCCESS
&& list
->name
; ++list
) {
364 res
= RegCreateKeyExA(HKEY_CLASSES_ROOT
, list
->name
, 0,
365 NULL
, 0, KEY_READ
| KEY_WRITE
, NULL
,
367 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
369 res
= RegSetValueExA(progid_key
, NULL
, 0, REG_SZ
,
370 (CONST BYTE
*)list
->description
,
371 strlen(list
->description
) + 1);
372 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
374 StringFromGUID2(list
->clsid
, buf
, 39);
376 res
= register_key_defvalueW(progid_key
, clsid_keyname
, buf
);
377 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
380 res
= register_key_defvalueA(progid_key
, curver_keyname
, list
->curver
);
381 if (res
!= ERROR_SUCCESS
) goto error_close_clsid_key
;
384 error_close_clsid_key
:
385 RegCloseKey(progid_key
);
388 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
391 /***********************************************************************
394 static HRESULT
unregister_progids(struct progid
const *list
)
396 LONG res
= ERROR_SUCCESS
;
398 for (; res
== ERROR_SUCCESS
&& list
->name
; ++list
) {
399 res
= recursive_delete_keyA(HKEY_CLASSES_ROOT
, list
->name
);
402 return res
!= ERROR_SUCCESS
? HRESULT_FROM_WIN32(res
) : S_OK
;
405 /***********************************************************************
408 static LONG
register_key_guid(HKEY base
, WCHAR
const *name
, GUID
const *guid
)
412 StringFromGUID2(guid
, buf
, 39);
413 return register_key_defvalueW(base
, name
, buf
);
416 /***********************************************************************
417 * regsvr_key_defvalueW
419 static LONG
register_key_defvalueW(
427 res
= RegCreateKeyExW(base
, name
, 0, NULL
, 0,
428 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
429 if (res
!= ERROR_SUCCESS
) return res
;
430 res
= RegSetValueExW(key
, NULL
, 0, REG_SZ
, (CONST BYTE
*)value
,
431 (lstrlenW(value
) + 1) * sizeof(WCHAR
));
436 /***********************************************************************
437 * regsvr_key_defvalueA
439 static LONG
register_key_defvalueA(
447 res
= RegCreateKeyExW(base
, name
, 0, NULL
, 0,
448 KEY_READ
| KEY_WRITE
, NULL
, &key
, NULL
);
449 if (res
!= ERROR_SUCCESS
) return res
;
450 res
= RegSetValueExA(key
, NULL
, 0, REG_SZ
, (CONST BYTE
*)value
,
451 lstrlenA(value
) + 1);
456 /***********************************************************************
457 * recursive_delete_key
459 static LONG
recursive_delete_key(HKEY key
)
462 WCHAR subkey_name
[MAX_PATH
];
467 cName
= sizeof(subkey_name
) / sizeof(WCHAR
);
468 res
= RegEnumKeyExW(key
, 0, subkey_name
, &cName
,
469 NULL
, NULL
, NULL
, NULL
);
470 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
) {
471 res
= ERROR_SUCCESS
; /* presumably we're done enumerating */
474 res
= RegOpenKeyExW(key
, subkey_name
, 0,
475 KEY_READ
| KEY_WRITE
, &subkey
);
476 if (res
== ERROR_FILE_NOT_FOUND
) continue;
477 if (res
!= ERROR_SUCCESS
) break;
479 res
= recursive_delete_key(subkey
);
481 if (res
!= ERROR_SUCCESS
) break;
484 if (res
== ERROR_SUCCESS
) res
= RegDeleteKeyW(key
, 0);
488 /***********************************************************************
489 * recursive_delete_keyA
491 static LONG
recursive_delete_keyA(HKEY base
, char const *name
)
496 res
= RegOpenKeyExA(base
, name
, 0, KEY_READ
| KEY_WRITE
, &key
);
497 if (res
== ERROR_FILE_NOT_FOUND
) return ERROR_SUCCESS
;
498 if (res
!= ERROR_SUCCESS
) return res
;
499 res
= recursive_delete_key(key
);
504 /***********************************************************************
505 * recursive_delete_keyW
507 static LONG
recursive_delete_keyW(HKEY base
, WCHAR
const *name
)
512 res
= RegOpenKeyExW(base
, name
, 0, KEY_READ
| KEY_WRITE
, &key
);
513 if (res
== ERROR_FILE_NOT_FOUND
) return ERROR_SUCCESS
;
514 if (res
!= ERROR_SUCCESS
) return res
;
515 res
= recursive_delete_key(key
);
520 /***********************************************************************
523 static struct regsvr_coclass
const coclass_list
[] = {
524 { &CLSID_DOMDocument
,
532 { &CLSID_DOMFreeThreadedDocument
,
533 "Free threaded XML DOM Document",
537 "Microsoft.FreeThreadedXMLDOM",
540 { &CLSID_XMLHTTPRequest
,
548 { &CLSID_XMLDSOControl
,
549 "XML Data Source Object",
556 { &CLSID_XMLDocument
,
563 { NULL
} /* list terminator */
566 /***********************************************************************
569 static struct regsvr_interface
const interface_list
[] = {
570 { NULL
} /* list terminator */
573 /***********************************************************************
576 static struct progid
const progid_list
[] = {
577 { "Microsoft.XMLDOM",
580 "Microsoft.XMLDOM.1.0"
582 { "Microsoft.XMLDOM.1.0",
587 { "MSXML.DOMDocument",
590 "Microsoft.XMLDOM.1.0"
592 { "Microsoft.FreeThreadedXMLDOM",
593 "Free threaded XML DOM Document",
594 &CLSID_DOMFreeThreadedDocument
,
595 "Microsoft.FreeThreadedXMLDOM.1.0"
597 { "Microsoft.FreeThreadedXMLDOM.1.0",
598 "Free threaded XML DOM Document",
599 &CLSID_DOMFreeThreadedDocument
,
602 { "MSXML.FreeThreadedDOMDocument",
603 "Free threaded XML DOM Document",
604 &CLSID_DOMFreeThreadedDocument
,
605 "Microsoft.FreeThreadedXMLDOM.1.0"
607 { "Microsoft.XMLHTTP",
609 &CLSID_XMLHTTPRequest
,
610 "Microsoft.XMLHTTP.1.0"
612 { "Microsoft.XMLHTTP.1.0",
614 &CLSID_XMLHTTPRequest
,
617 { "Microsoft.XMLDSO",
618 "XML Data Source Object",
619 &CLSID_XMLDSOControl
,
620 "Microsoft.XMLDSO.1.0"
622 { "Microsoft.XMLDSO.1.0",
623 "XML Data Source Object",
624 &CLSID_XMLDSOControl
,
632 { NULL
} /* list terminator */
635 /***********************************************************************
636 * DllRegisterServer (OLEAUT32.@)
638 HRESULT WINAPI
DllRegisterServer(void)
644 hr
= register_coclasses(coclass_list
);
646 hr
= register_interfaces(interface_list
);
648 hr
= register_progids(progid_list
);
652 /***********************************************************************
653 * DllUnregisterServer (OLEAUT32.@)
655 HRESULT WINAPI
DllUnregisterServer(void)
661 hr
= unregister_coclasses(coclass_list
);
663 hr
= unregister_interfaces(interface_list
);
665 hr
= unregister_progids(progid_list
);