crypt32: Implement CryptFindLocalizedName.
[wine/hacks.git] / dlls / msi / regsvr.c
blobdf8955a5168410c3e66a8e98b329bb7c8b73edc9
1 /*
2 * self-registerable dll functions for msi.dll
4 * Copyright (C) 2004 Raphael Junqueira
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 #define COBJMACROS
23 #include "config.h"
25 #include <stdarg.h>
26 #include <string.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "winreg.h"
32 #include "winerror.h"
34 #include "ole2.h"
35 #include "olectl.h"
36 #include "oleauto.h"
38 #include "wine/debug.h"
40 #include "msi.h"
41 #include "initguid.h"
42 #include "msipriv.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msi);
47 * Near the bottom of this file are the exported DllRegisterServer and
48 * DllUnregisterServer, which make all this worthwhile.
51 /***********************************************************************
52 * interface for self-registering
54 struct regsvr_interface {
55 IID const *iid; /* NULL for end of list */
56 LPCSTR name; /* can be NULL to omit */
57 IID const *base_iid; /* can be NULL to omit */
58 int num_methods; /* can be <0 to omit */
59 CLSID const *ps_clsid; /* can be NULL to omit */
60 CLSID const *ps_clsid32; /* can be NULL to omit */
63 static HRESULT register_interfaces(struct regsvr_interface const *list);
64 static HRESULT unregister_interfaces(struct regsvr_interface const *list);
66 /**
67 * @todo: maybe adding typelibs support here
68 * [Software\\Classes\\CLSID\\{000C1090-0000-0000-C000-000000000046}\\TypeLib] 1080380217
69 * @="{000C1092-0000-0000-C000-000000000046}"
71 struct regsvr_coclass {
72 CLSID const *clsid; /* NULL for end of list */
73 LPCSTR name; /* can be NULL to omit */
74 LPCSTR iph32; /* can be NULL to omit */
75 LPCSTR ips; /* can be NULL to omit */
76 LPCSTR ips32; /* can be NULL to omit */
77 LPCSTR ips32_tmodel; /* can be NULL to omit, if apartment, iph32 must be set */
78 DWORD flags;
79 LPCSTR progid; /* can be NULL to omit */
80 LPCSTR viprogid; /* can be NULL to omit */
81 LPCSTR progid_extra; /* can be NULL to omit */
84 /* flags for regsvr_coclass.flags */
85 #define PROGID_CLSID 0x00000010
87 static HRESULT register_coclasses(struct regsvr_coclass const *list);
88 static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
90 /***********************************************************************
91 * static string constants
93 static WCHAR const interface_keyname[10] = {
94 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
95 static WCHAR const base_ifa_keyname[14] = {
96 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
97 'e', 0 };
98 static WCHAR const num_methods_keyname[11] = {
99 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
100 static WCHAR const ps_clsid_keyname[15] = {
101 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
102 'i', 'd', 0 };
103 static WCHAR const ps_clsid32_keyname[17] = {
104 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
105 'i', 'd', '3', '2', 0 };
106 static WCHAR const clsid_keyname[6] = {
107 'C', 'L', 'S', 'I', 'D', 0 };
108 static WCHAR const curver_keyname[7] = {
109 'C', 'u', 'r', 'V', 'e', 'r', 0 };
110 static WCHAR const iph32_keyname[] = {
111 'I', 'n', 'P', 'r', 'o', 'c', 'H', 'a', 'n', 'd', 'l', 'e', 'r',
112 '3', '2', 0 };
113 static WCHAR const ips_keyname[13] = {
114 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
115 0 };
116 static WCHAR const ips32_keyname[15] = {
117 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
118 '3', '2', 0 };
119 static WCHAR const progid_keyname[7] = {
120 'P', 'r', 'o', 'g', 'I', 'D', 0 };
121 static WCHAR const viprogid_keyname[25] = {
122 'V', 'e', 'r', 's', 'i', 'o', 'n', 'I', 'n', 'd', 'e', 'p',
123 'e', 'n', 'd', 'e', 'n', 't', 'P', 'r', 'o', 'g', 'I', 'D',
124 0 };
125 static char const tmodel_valuename[] = "ThreadingModel";
127 /***********************************************************************
128 * static helper functions
130 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid);
131 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
132 WCHAR const *value);
133 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
134 char const *value);
135 static LONG register_progid(WCHAR const *clsid,
136 char const *progid, char const *curver_progid,
137 char const *name, char const *extra);
139 /***********************************************************************
140 * register_interfaces
142 static HRESULT register_interfaces(struct regsvr_interface const *list) {
143 LONG res = ERROR_SUCCESS;
144 HKEY interface_key;
146 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, NULL, 0,
147 KEY_READ | KEY_WRITE, NULL, &interface_key, NULL);
148 if (res != ERROR_SUCCESS) goto error_return;
150 for (; res == ERROR_SUCCESS && list->iid; ++list) {
151 WCHAR buf[39];
152 HKEY iid_key;
154 StringFromGUID2(list->iid, buf, 39);
155 res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0,
156 KEY_READ | KEY_WRITE, NULL, &iid_key, NULL);
157 if (res != ERROR_SUCCESS) goto error_close_interface_key;
159 if (list->name) {
160 res = RegSetValueExA(iid_key, NULL, 0, REG_SZ,
161 (CONST BYTE*)(list->name),
162 strlen(list->name) + 1);
163 if (res != ERROR_SUCCESS) goto error_close_iid_key;
166 if (list->base_iid) {
167 res = register_key_guid(iid_key, base_ifa_keyname, list->base_iid);
168 if (res != ERROR_SUCCESS) goto error_close_iid_key;
171 if (0 <= list->num_methods) {
172 static WCHAR const fmt[3] = { '%', 'd', 0 };
173 HKEY key;
175 res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0,
176 KEY_READ | KEY_WRITE, NULL, &key, NULL);
177 if (res != ERROR_SUCCESS) goto error_close_iid_key;
179 wsprintfW(buf, fmt, list->num_methods);
180 res = RegSetValueExW(key, NULL, 0, REG_SZ,
181 (CONST BYTE*)buf,
182 (lstrlenW(buf) + 1) * sizeof(WCHAR));
183 RegCloseKey(key);
185 if (res != ERROR_SUCCESS) goto error_close_iid_key;
188 if (list->ps_clsid) {
189 res = register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid);
190 if (res != ERROR_SUCCESS) goto error_close_iid_key;
193 if (list->ps_clsid32) {
194 res = register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32);
195 if (res != ERROR_SUCCESS) goto error_close_iid_key;
198 error_close_iid_key:
199 RegCloseKey(iid_key);
202 error_close_interface_key:
203 RegCloseKey(interface_key);
204 error_return:
205 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
208 /***********************************************************************
209 * unregister_interfaces
211 static HRESULT unregister_interfaces(struct regsvr_interface const *list) {
212 LONG res = ERROR_SUCCESS;
213 HKEY interface_key;
215 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0,
216 KEY_READ | KEY_WRITE, &interface_key);
217 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
218 if (res != ERROR_SUCCESS) goto error_return;
220 for (; res == ERROR_SUCCESS && list->iid; ++list) {
221 WCHAR buf[39];
223 StringFromGUID2(list->iid, buf, 39);
224 res = RegDeleteTreeW(interface_key, buf);
225 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
228 RegCloseKey(interface_key);
229 error_return:
230 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
233 /***********************************************************************
234 * register_coclasses
236 static HRESULT register_coclasses(struct regsvr_coclass const *list) {
237 LONG res = ERROR_SUCCESS;
238 HKEY coclass_key;
240 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
241 KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
242 if (res != ERROR_SUCCESS) goto error_return;
244 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
245 WCHAR buf[39];
246 HKEY clsid_key;
248 StringFromGUID2(list->clsid, buf, 39);
249 res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
250 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
251 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
253 if (list->name) {
254 res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
255 (CONST BYTE*)(list->name),
256 strlen(list->name) + 1);
257 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
260 if (list->iph32) {
261 HKEY iph32_key;
263 res = RegCreateKeyExW(clsid_key, iph32_keyname, 0, NULL, 0,
264 KEY_READ | KEY_WRITE, NULL,
265 &iph32_key, NULL);
266 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
268 res = RegSetValueExA(iph32_key, NULL, 0, REG_SZ,
269 (CONST BYTE*)list->iph32,
270 lstrlenA(list->iph32) + 1);
271 RegCloseKey(iph32_key);
272 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
275 if (list->ips) {
276 res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
277 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
280 if (list->ips32) {
281 HKEY ips32_key;
283 res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
284 KEY_READ | KEY_WRITE, NULL,
285 &ips32_key, NULL);
286 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
288 res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
289 (CONST BYTE*)list->ips32,
290 lstrlenA(list->ips32) + 1);
291 if (res == ERROR_SUCCESS && list->ips32_tmodel)
292 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
293 (CONST BYTE*)list->ips32_tmodel,
294 strlen(list->ips32_tmodel) + 1);
295 RegCloseKey(ips32_key);
296 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
299 if (list->progid) {
300 res = register_key_defvalueA(clsid_key, progid_keyname,
301 list->progid);
302 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
304 res = register_progid(list->flags & PROGID_CLSID ? buf : NULL,
305 list->progid, NULL,
306 list->name, list->progid_extra);
307 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
310 if (list->viprogid) {
311 res = register_key_defvalueA(clsid_key, viprogid_keyname,
312 list->viprogid);
313 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
315 res = register_progid(list->flags & PROGID_CLSID ? buf : NULL,
316 list->viprogid, list->progid,
317 list->name, list->progid_extra);
318 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
321 error_close_clsid_key:
322 RegCloseKey(clsid_key);
325 error_close_coclass_key:
326 RegCloseKey(coclass_key);
327 error_return:
328 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
331 /***********************************************************************
332 * unregister_coclasses
334 static HRESULT unregister_coclasses(struct regsvr_coclass const *list) {
335 LONG res = ERROR_SUCCESS;
336 HKEY coclass_key;
338 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
339 KEY_READ | KEY_WRITE, &coclass_key);
340 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
341 if (res != ERROR_SUCCESS) goto error_return;
343 for (; res == ERROR_SUCCESS && list->clsid; ++list) {
344 WCHAR buf[39];
346 StringFromGUID2(list->clsid, buf, 39);
347 res = RegDeleteTreeW(coclass_key, buf);
348 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
349 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
351 if (list->progid) {
352 res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->progid);
353 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
354 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
357 if (list->viprogid) {
358 res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->viprogid);
359 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
360 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
364 error_close_coclass_key:
365 RegCloseKey(coclass_key);
366 error_return:
367 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
370 /***********************************************************************
371 * regsvr_key_guid
373 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid) {
374 WCHAR buf[39];
376 StringFromGUID2(guid, buf, 39);
377 return register_key_defvalueW(base, name, buf);
380 /***********************************************************************
381 * regsvr_key_defvalueW
383 static LONG register_key_defvalueW(
384 HKEY base,
385 WCHAR const *name,
386 WCHAR const *value) {
387 LONG res;
388 HKEY key;
390 res = RegCreateKeyExW(base, name, 0, NULL, 0,
391 KEY_READ | KEY_WRITE, NULL, &key, NULL);
392 if (res != ERROR_SUCCESS) return res;
393 res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
394 (lstrlenW(value) + 1) * sizeof(WCHAR));
395 RegCloseKey(key);
396 return res;
399 /***********************************************************************
400 * regsvr_key_defvalueA
402 static LONG register_key_defvalueA(
403 HKEY base,
404 WCHAR const *name,
405 char const *value) {
406 LONG res;
407 HKEY key;
409 res = RegCreateKeyExW(base, name, 0, NULL, 0,
410 KEY_READ | KEY_WRITE, NULL, &key, NULL);
411 if (res != ERROR_SUCCESS) return res;
412 res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
413 lstrlenA(value) + 1);
414 RegCloseKey(key);
415 return res;
418 /***********************************************************************
419 * regsvr_progid
421 static LONG register_progid(
422 WCHAR const *clsid,
423 char const *progid,
424 char const *curver_progid,
425 char const *name,
426 char const *extra) {
427 LONG res;
428 HKEY progid_key;
430 res = RegCreateKeyExA(HKEY_CLASSES_ROOT, progid, 0,
431 NULL, 0, KEY_READ | KEY_WRITE, NULL,
432 &progid_key, NULL);
433 if (res != ERROR_SUCCESS) return res;
435 if (name) {
436 res = RegSetValueExA(progid_key, NULL, 0, REG_SZ,
437 (CONST BYTE*)name, strlen(name) + 1);
438 if (res != ERROR_SUCCESS) goto error_close_progid_key;
441 if (clsid) {
442 res = register_key_defvalueW(progid_key, clsid_keyname, clsid);
443 if (res != ERROR_SUCCESS) goto error_close_progid_key;
446 if (curver_progid) {
447 res = register_key_defvalueA(progid_key, curver_keyname,
448 curver_progid);
449 if (res != ERROR_SUCCESS) goto error_close_progid_key;
452 if (extra) {
453 HKEY extra_key;
455 res = RegCreateKeyExA(progid_key, extra, 0,
456 NULL, 0, KEY_READ | KEY_WRITE, NULL,
457 &extra_key, NULL);
458 if (res == ERROR_SUCCESS)
459 RegCloseKey(extra_key);
462 error_close_progid_key:
463 RegCloseKey(progid_key);
464 return res;
467 /***********************************************************************
468 * coclass list
470 static struct regsvr_coclass const coclass_list[] = {
472 &CLSID_IMsiServer,
473 "Msi install server",
474 "ole32.dll",
475 NULL,
476 "msi.dll",
477 "Apartment",
478 PROGID_CLSID,
479 "IMsiServer",
480 NULL
483 &CLSID_IMsiServerMessage,
484 "Wine Installer Message RPC",
485 NULL,
486 NULL,
487 "msi.dll",
488 NULL,
489 PROGID_CLSID,
490 "WindowsInstaller.Message",
491 NULL
494 &CLSID_IMsiServerX1,
495 "Msi install server",
496 "ole32.dll",
497 NULL,
498 "msi.dll",
499 "Apartment",
501 "WindowsInstaller.Installer",
502 NULL
505 &CLSID_IMsiServerX2,
506 "Msi install server",
507 "ole32.dll",
508 NULL,
509 "msi.dll",
510 "Apartment",
511 PROGID_CLSID,
512 "WindowsInstaller.Installer",
513 NULL
516 &CLSID_IMsiServerX3,
517 "Msi install server",
518 "ole32.dll",
519 NULL,
520 "msi.dll",
521 "Apartment",
523 "WindowsInstaller.Installer",
524 NULL
526 { NULL } /* list terminator */
529 /***********************************************************************
530 * interface list
533 * we should declare: (@see ole32/regsvr.c for examples)
534 [-HKEY_CLASSES_ROOT\Interface\{000C101D-0000-0000-C000-000000000046}]
535 [-HKEY_CLASSES_ROOT\Interface\{000C1025-0000-0000-C000-000000000046}]
536 [-HKEY_CLASSES_ROOT\Interface\{000C1033-0000-0000-C000-000000000046}]
537 [-HKEY_CLASSES_ROOT\Interface\{000C1090-0000-0000-C000-000000000046}]
538 [-HKEY_CLASSES_ROOT\Interface\{000C1093-0000-0000-C000-000000000046}]
539 [-HKEY_CLASSES_ROOT\Interface\{000C1095-0000-0000-C000-000000000046}]
540 [-HKEY_CLASSES_ROOT\Interface\{000C109A-0000-0000-C000-000000000046}]
541 [-HKEY_CLASSES_ROOT\Interface\{000C109B-0000-0000-C000-000000000046}]
542 [-HKEY_CLASSES_ROOT\Interface\{000C109C-0000-0000-C000-000000000046}]
543 [-HKEY_CLASSES_ROOT\Interface\{000C109D-0000-0000-C000-000000000046}]
544 [-HKEY_CLASSES_ROOT\Interface\{000C109E-0000-0000-C000-000000000046}]
545 [-HKEY_CLASSES_ROOT\Interface\{000C109F-0000-0000-C000-000000000046}]
548 static struct regsvr_interface const interface_list[] = {
549 { &CLSID_IMsiServer,
550 "IMsiServer",
551 NULL,
553 NULL,
554 NULL },
555 { NULL } /* list terminator */
558 static HRESULT register_msiexec(void)
560 static const WCHAR key[] = {
561 'S','o','f','t','w','a','r','e',
562 '\\','M','i','c','r','o','s','o','f','t',
563 '\\','W','i','n','d','o','w','s',
564 '\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
565 '\\','I','n','s','t','a','l','l','e','r',0 };
566 static const WCHAR val[] = {
567 'I','n','s','t','a','l','l','e','r','L','o','c','a','t','i','o','n',0 };
568 WCHAR path[MAX_PATH];
569 HKEY hkey;
570 LONG res;
571 INT len;
573 len = GetSystemDirectoryW(path, MAX_PATH);
574 if (!len || len > MAX_PATH)
575 return E_FAIL;
577 res = RegCreateKeyExW(HKEY_LOCAL_MACHINE, key, 0,
578 NULL, 0, KEY_READ | KEY_WRITE, NULL,
579 &hkey, NULL);
580 if (res != ERROR_SUCCESS)
581 return E_FAIL;
583 res = RegSetValueExW(hkey, val, 0, REG_SZ,
584 (BYTE*)path, (len + 1)*sizeof(WCHAR));
586 RegCloseKey(hkey);
588 return (res == ERROR_SUCCESS) ? S_OK : E_FAIL;
591 /***********************************************************************
592 * DllRegisterServer (MSI.@)
594 HRESULT WINAPI DllRegisterServer(void)
596 LPWSTR path = NULL;
597 ITypeLib *tl;
598 HRESULT hr;
600 TRACE("\n");
602 hr = register_coclasses(coclass_list);
603 if (SUCCEEDED(hr))
604 hr = register_interfaces(interface_list);
605 if (SUCCEEDED(hr))
606 hr = register_msiexec();
608 tl = get_msi_typelib( &path );
609 if (tl)
611 hr = RegisterTypeLib( tl, path, NULL );
612 ITypeLib_Release( tl );
614 else
615 hr = E_FAIL;
617 return hr;
620 /***********************************************************************
621 * DllUnregisterServer (MSI.@)
623 HRESULT WINAPI DllUnregisterServer(void)
625 HRESULT hr;
627 TRACE("\n");
629 hr = unregister_coclasses(coclass_list);
630 if (SUCCEEDED(hr))
631 hr = unregister_interfaces(interface_list);
632 return hr;