jscript: Add Italian translation.
[wine.git] / dlls / msdaps / regsvr.c
blobcb83fe0d14edc55711042adbd92db54f1d1e8cb8
1 /*
2 * self-registerable dll functions for msdaps.dll
4 * Copyright (C) 2004 Raphael Junqueira
5 * 2010 Huw Davies
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
22 #define COBJMACROS
24 #include "config.h"
26 #include <stdarg.h>
27 #include <string.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "winreg.h"
33 #include "winerror.h"
35 #include "ole2.h"
36 #include "olectl.h"
37 #include "oleauto.h"
39 #include "row_server.h"
41 #include "wine/debug.h"
42 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(oledb);
46 extern HRESULT WINAPI msdaps_DllRegisterServer(void) DECLSPEC_HIDDEN;
47 extern HRESULT WINAPI msdaps_DllUnregisterServer(void) DECLSPEC_HIDDEN;
50 /***********************************************************************
51 * interface for self-registering
53 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 struct regsvr_coclass
68 CLSID const *clsid; /* NULL for end of list */
69 LPCSTR name; /* can be NULL to omit */
70 LPCSTR iph32; /* can be NULL to omit */
71 LPCSTR ips; /* can be NULL to omit */
72 LPCSTR ips32; /* can be NULL to omit */
73 LPCSTR ips32_tmodel; /* can be NULL to omit, if apartment, iph32 must be set */
74 DWORD flags; /* set defines below */
75 LPCSTR progid; /* can be NULL to omit */
76 LPCSTR viprogid; /* can be NULL to omit */
77 LPCSTR progid_extra; /* can be NULL to omit */
78 LPCSTR dllversion; /* can be NULL to omit */
81 /* flags for regsvr_coclass.flags */
82 #define PROGID_CLSID 0x00000010 /* add a clsid key to the progid */
84 static HRESULT register_coclasses(struct regsvr_coclass const *list);
85 static HRESULT unregister_coclasses(struct regsvr_coclass 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 curver_keyname[7] = {
106 'C', 'u', 'r', 'V', 'e', 'r', 0 };
107 static WCHAR const iph32_keyname[] = {
108 'I', 'n', 'P', 'r', 'o', 'c', 'H', 'a', 'n', 'd', 'l', 'e', 'r',
109 '3', '2', 0 };
110 static WCHAR const ips_keyname[13] = {
111 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
112 0 };
113 static WCHAR const ips32_keyname[15] = {
114 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
115 '3', '2', 0 };
116 static WCHAR const progid_keyname[7] = {
117 'P', 'r', 'o', 'g', 'I', 'D', 0 };
118 static WCHAR const viprogid_keyname[25] = {
119 'V', 'e', 'r', 's', 'i', 'o', 'n', 'I', 'n', 'd', 'e', 'p',
120 'e', 'n', 'd', 'e', 'n', 't', 'P', 'r', 'o', 'g', 'I', 'D',
121 0 };
122 static WCHAR const dllversion_keyname[11] = {
123 'D', 'l', 'l', 'V', 'e', 'r', 's', 'i', 'o', 'n', 0 };
124 static char const tmodel_valuename[] = "ThreadingModel";
126 /***********************************************************************
127 * static helper functions
129 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid);
130 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
131 WCHAR const *value);
132 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
133 char const *value);
134 static LONG register_progid(WCHAR const *clsid,
135 char const *progid, char const *curver_progid,
136 char const *name, char const *extra);
138 /***********************************************************************
139 * register_interfaces
141 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)
152 WCHAR buf[39];
153 HKEY iid_key;
155 StringFromGUID2(list->iid, buf, 39);
156 res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0,
157 KEY_READ | KEY_WRITE, NULL, &iid_key, NULL);
158 if (res != ERROR_SUCCESS) goto error_close_interface_key;
160 if (list->name)
162 res = RegSetValueExA(iid_key, NULL, 0, REG_SZ,
163 (CONST BYTE*)(list->name),
164 strlen(list->name) + 1);
165 if (res != ERROR_SUCCESS) goto error_close_iid_key;
168 if (list->base_iid)
170 res = register_key_guid(iid_key, base_ifa_keyname, list->base_iid);
171 if (res != ERROR_SUCCESS) goto error_close_iid_key;
174 if (0 <= list->num_methods)
176 static WCHAR const fmt[3] = { '%', 'd', 0 };
177 HKEY key;
179 res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0,
180 KEY_READ | KEY_WRITE, NULL, &key, NULL);
181 if (res != ERROR_SUCCESS) goto error_close_iid_key;
183 sprintfW(buf, fmt, list->num_methods);
184 res = RegSetValueExW(key, NULL, 0, REG_SZ,
185 (CONST BYTE*)buf,
186 (lstrlenW(buf) + 1) * sizeof(WCHAR));
187 RegCloseKey(key);
189 if (res != ERROR_SUCCESS) goto error_close_iid_key;
192 if (list->ps_clsid)
194 res = register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid);
195 if (res != ERROR_SUCCESS) goto error_close_iid_key;
198 if (list->ps_clsid32)
200 res = register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32);
201 if (res != ERROR_SUCCESS) goto error_close_iid_key;
204 error_close_iid_key:
205 RegCloseKey(iid_key);
208 error_close_interface_key:
209 RegCloseKey(interface_key);
210 error_return:
211 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
214 /***********************************************************************
215 * unregister_interfaces
217 static HRESULT unregister_interfaces(struct regsvr_interface const *list)
219 LONG res = ERROR_SUCCESS;
220 HKEY interface_key;
222 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0,
223 KEY_READ | KEY_WRITE, &interface_key);
224 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
225 if (res != ERROR_SUCCESS) goto error_return;
227 for (; res == ERROR_SUCCESS && list->iid; ++list)
229 WCHAR buf[39];
231 StringFromGUID2(list->iid, buf, 39);
232 res = RegDeleteTreeW(interface_key, buf);
233 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
236 RegCloseKey(interface_key);
237 error_return:
238 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
241 /***********************************************************************
242 * register_coclasses
244 static HRESULT register_coclasses(struct regsvr_coclass const *list)
246 LONG res = ERROR_SUCCESS;
247 HKEY coclass_key;
249 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
250 KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
251 if (res != ERROR_SUCCESS) goto error_return;
253 for (; res == ERROR_SUCCESS && list->clsid; ++list)
255 WCHAR buf[39];
256 HKEY clsid_key;
258 StringFromGUID2(list->clsid, buf, 39);
259 res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
260 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
261 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
263 if (list->name)
265 res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
266 (CONST BYTE*)(list->name),
267 strlen(list->name) + 1);
268 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
271 if (list->iph32)
273 HKEY iph32_key;
275 res = RegCreateKeyExW(clsid_key, iph32_keyname, 0, NULL, 0,
276 KEY_READ | KEY_WRITE, NULL,
277 &iph32_key, NULL);
278 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
280 res = RegSetValueExA(iph32_key, NULL, 0, REG_SZ,
281 (CONST BYTE*)list->iph32,
282 lstrlenA(list->iph32) + 1);
283 RegCloseKey(iph32_key);
284 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
287 if (list->ips)
289 res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
290 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
293 if (list->ips32)
295 HKEY ips32_key;
297 res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
298 KEY_READ | KEY_WRITE, NULL,
299 &ips32_key, NULL);
300 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
302 res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
303 (CONST BYTE*)list->ips32,
304 lstrlenA(list->ips32) + 1);
305 if (res == ERROR_SUCCESS && list->ips32_tmodel)
306 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
307 (CONST BYTE*)list->ips32_tmodel,
308 strlen(list->ips32_tmodel) + 1);
309 RegCloseKey(ips32_key);
310 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
313 if (list->progid)
315 res = register_key_defvalueA(clsid_key, progid_keyname,
316 list->progid);
317 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
319 res = register_progid(list->flags & PROGID_CLSID ? buf : NULL,
320 list->progid, NULL,
321 list->name, list->progid_extra);
322 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
325 if (list->viprogid)
327 res = register_key_defvalueA(clsid_key, viprogid_keyname,
328 list->viprogid);
329 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
331 res = register_progid(list->flags & PROGID_CLSID ? buf : NULL,
332 list->viprogid, list->progid,
333 list->name, list->progid_extra);
334 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
337 if (list->dllversion)
339 HKEY dllver_key;
341 res = RegCreateKeyExW(clsid_key, dllversion_keyname, 0, NULL, 0,
342 KEY_READ | KEY_WRITE, NULL,
343 &dllver_key, NULL);
344 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
346 res = RegSetValueExA(dllver_key, NULL, 0, REG_SZ,
347 (CONST BYTE*)list->dllversion,
348 lstrlenA(list->dllversion) + 1);
349 RegCloseKey(dllver_key);
350 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
354 error_close_clsid_key:
355 RegCloseKey(clsid_key);
358 error_close_coclass_key:
359 RegCloseKey(coclass_key);
360 error_return:
361 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
364 /***********************************************************************
365 * unregister_coclasses
367 static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
369 LONG res = ERROR_SUCCESS;
370 HKEY coclass_key;
372 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
373 KEY_READ | KEY_WRITE, &coclass_key);
374 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
375 if (res != ERROR_SUCCESS) goto error_return;
377 for (; res == ERROR_SUCCESS && list->clsid; ++list)
379 WCHAR buf[39];
381 StringFromGUID2(list->clsid, buf, 39);
382 res = RegDeleteTreeW(coclass_key, buf);
383 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
384 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
386 if (list->progid)
388 res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->progid);
389 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
390 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
393 if (list->viprogid)
395 res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->viprogid);
396 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
397 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
401 error_close_coclass_key:
402 RegCloseKey(coclass_key);
403 error_return:
404 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
407 /***********************************************************************
408 * register_key_guid
410 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid)
412 WCHAR buf[39];
414 StringFromGUID2(guid, buf, 39);
415 return register_key_defvalueW(base, name, buf);
418 /***********************************************************************
419 * register_key_defvalueW
421 static LONG register_key_defvalueW(HKEY base, WCHAR const *name, 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 * register_key_defvalueA
438 static LONG register_key_defvalueA(HKEY base, WCHAR const *name, char const *value)
440 LONG res;
441 HKEY key;
443 res = RegCreateKeyExW(base, name, 0, NULL, 0,
444 KEY_READ | KEY_WRITE, NULL, &key, NULL);
445 if (res != ERROR_SUCCESS) return res;
446 res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
447 lstrlenA(value) + 1);
448 RegCloseKey(key);
449 return res;
452 /***********************************************************************
453 * register_progid
455 static LONG register_progid(WCHAR const *clsid, char const *progid,
456 char const *curver_progid, char const *name,
457 char const *extra)
459 LONG res;
460 HKEY progid_key;
462 res = RegCreateKeyExA(HKEY_CLASSES_ROOT, progid, 0,
463 NULL, 0, KEY_READ | KEY_WRITE, NULL,
464 &progid_key, NULL);
465 if (res != ERROR_SUCCESS) return res;
467 if (name)
469 res = RegSetValueExA(progid_key, NULL, 0, REG_SZ,
470 (CONST BYTE*)name, strlen(name) + 1);
471 if (res != ERROR_SUCCESS) goto error_close_progid_key;
474 if (clsid)
476 res = register_key_defvalueW(progid_key, clsid_keyname, clsid);
477 if (res != ERROR_SUCCESS) goto error_close_progid_key;
480 if (curver_progid)
482 res = register_key_defvalueA(progid_key, curver_keyname, curver_progid);
483 if (res != ERROR_SUCCESS) goto error_close_progid_key;
486 if (extra)
488 HKEY extra_key;
490 res = RegCreateKeyExA(progid_key, extra, 0,
491 NULL, 0, KEY_READ | KEY_WRITE, NULL,
492 &extra_key, NULL);
493 if (res == ERROR_SUCCESS)
494 RegCloseKey(extra_key);
497 error_close_progid_key:
498 RegCloseKey(progid_key);
499 return res;
502 /***********************************************************************
503 * coclass list
505 static struct regsvr_coclass const coclass_list[] =
508 &CLSID_wine_row_proxy,
509 "Wine OLE DB Row Proxy",
510 NULL,
511 NULL,
512 "msdaps.dll",
513 "Both",
514 PROGID_CLSID,
515 "WINEDBROWPRX.AsProxy.1",
516 "WINEDBROWPRX.AsProxy",
517 NULL,
518 NULL
521 &CLSID_wine_row_server,
522 "Wine OLE DB Row Server",
523 NULL,
524 NULL,
525 "msdaps.dll",
526 "Both",
527 PROGID_CLSID,
528 "WINEDBROWPRX.AsServer.1",
529 "WINEDBROWPRX.AsServer",
530 NULL,
531 NULL
534 &CLSID_wine_rowset_proxy,
535 "Wine OLE DB Rowset Proxy",
536 NULL,
537 NULL,
538 "msdaps.dll",
539 "Both",
540 PROGID_CLSID,
541 "WINEDBRSTPRX.AsProxy.1",
542 "WINEDBRSTPRX.AsProxy",
543 NULL,
544 NULL
547 &CLSID_wine_rowset_server,
548 "Wine OLE DB Rowset Server",
549 NULL,
550 NULL,
551 "msdaps.dll",
552 "Both",
553 PROGID_CLSID,
554 "WINEDBRSTPRX.AsServer.1",
555 "WINEDBRSTPRX.AsServer",
556 NULL,
557 NULL
559 { NULL } /* list terminator */
562 /***********************************************************************
563 * interface list
565 static struct regsvr_interface const interface_list[] =
567 { NULL } /* list terminator */
570 /***********************************************************************
571 * DllRegisterServer
573 HRESULT WINAPI DllRegisterServer(void)
575 HRESULT hr;
577 TRACE("\n");
579 hr = register_coclasses(coclass_list);
581 if (SUCCEEDED(hr))
582 hr = register_interfaces(interface_list);
584 if (SUCCEEDED(hr))
585 hr = msdaps_DllRegisterServer();
587 return hr;
590 /***********************************************************************
591 * DllUnregisterServer
593 HRESULT WINAPI DllUnregisterServer(void)
595 HRESULT hr;
597 TRACE("\n");
599 hr = unregister_coclasses(coclass_list);
601 if (SUCCEEDED(hr))
602 hr = unregister_interfaces(interface_list);
604 if (SUCCEEDED(hr))
605 hr = msdaps_DllUnregisterServer();
607 return hr;