ole32: Rename PROPSET_BLOCK_SIZE to RAW_DIRENTRY_SIZE.
[wine/testsucceed.git] / dlls / oledb32 / regsvr.c
blobb7fbf8e0f50108932abe97395b36754e1afe8640
1 /*
2 * self-registerable dll functions for oledb32.dll
4 * Copyright (C) 2004 Raphael Junqueira
5 * 2009 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 "msdaguid.h"
41 #include "wine/debug.h"
42 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(oledb);
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
56 IID const *iid; /* NULL for end of list */
57 LPCSTR name; /* can be NULL to omit */
58 IID const *base_iid; /* can be NULL to omit */
59 int num_methods; /* can be <0 to omit */
60 CLSID const *ps_clsid; /* can be NULL to omit */
61 CLSID const *ps_clsid32; /* can be NULL to omit */
64 static HRESULT register_interfaces(struct regsvr_interface const *list);
65 static HRESULT unregister_interfaces(struct regsvr_interface const *list);
67 struct regsvr_coclass
69 CLSID const *clsid; /* NULL for end of list */
70 LPCSTR name; /* can be NULL to omit */
71 LPCSTR iph32; /* can be NULL to omit */
72 LPCSTR ips; /* can be NULL to omit */
73 LPCSTR ips32; /* can be NULL to omit */
74 LPCSTR ips32_tmodel; /* can be NULL to omit, if apartment, iph32 must be set */
75 DWORD flags; /* set defines below */
76 LPCSTR progid; /* can be NULL to omit */
77 LPCSTR viprogid; /* can be NULL to omit */
78 LPCSTR progid_extra; /* can be NULL to omit */
79 LPCSTR dllversion; /* can be NULL to omit */
82 /* flags for regsvr_coclass.flags */
83 #define PROGID_CLSID 0x00000010 /* add a clsid key to the progid */
85 static HRESULT register_coclasses(struct regsvr_coclass const *list);
86 static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
88 /***********************************************************************
89 * static string constants
91 static WCHAR const interface_keyname[10] = {
92 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
93 static WCHAR const base_ifa_keyname[14] = {
94 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
95 'e', 0 };
96 static WCHAR const num_methods_keyname[11] = {
97 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
98 static WCHAR const ps_clsid_keyname[15] = {
99 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
100 'i', 'd', 0 };
101 static WCHAR const ps_clsid32_keyname[17] = {
102 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
103 'i', 'd', '3', '2', 0 };
104 static WCHAR const clsid_keyname[6] = {
105 'C', 'L', 'S', 'I', 'D', 0 };
106 static WCHAR const curver_keyname[7] = {
107 'C', 'u', 'r', 'V', 'e', 'r', 0 };
108 static WCHAR const iph32_keyname[] = {
109 'I', 'n', 'P', 'r', 'o', 'c', 'H', 'a', 'n', 'd', 'l', 'e', 'r',
110 '3', '2', 0 };
111 static WCHAR const ips_keyname[13] = {
112 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
113 0 };
114 static WCHAR const ips32_keyname[15] = {
115 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
116 '3', '2', 0 };
117 static WCHAR const progid_keyname[7] = {
118 'P', 'r', 'o', 'g', 'I', 'D', 0 };
119 static WCHAR const viprogid_keyname[25] = {
120 'V', 'e', 'r', 's', 'i', 'o', 'n', 'I', 'n', 'd', 'e', 'p',
121 'e', 'n', 'd', 'e', 'n', 't', 'P', 'r', 'o', 'g', 'I', 'D',
122 0 };
123 static WCHAR const dllversion_keyname[11] = {
124 'D', 'l', 'l', 'V', 'e', 'r', 's', 'i', 'o', 'n', 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)
144 LONG res = ERROR_SUCCESS;
145 HKEY interface_key;
147 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, NULL, 0,
148 KEY_READ | KEY_WRITE, NULL, &interface_key, NULL);
149 if (res != ERROR_SUCCESS) goto error_return;
151 for (; res == ERROR_SUCCESS && list->iid; ++list)
153 WCHAR buf[39];
154 HKEY iid_key;
156 StringFromGUID2(list->iid, buf, 39);
157 res = RegCreateKeyExW(interface_key, buf, 0, NULL, 0,
158 KEY_READ | KEY_WRITE, NULL, &iid_key, NULL);
159 if (res != ERROR_SUCCESS) goto error_close_interface_key;
161 if (list->name)
163 res = RegSetValueExA(iid_key, NULL, 0, REG_SZ,
164 (CONST BYTE*)(list->name),
165 strlen(list->name) + 1);
166 if (res != ERROR_SUCCESS) goto error_close_iid_key;
169 if (list->base_iid)
171 res = register_key_guid(iid_key, base_ifa_keyname, list->base_iid);
172 if (res != ERROR_SUCCESS) goto error_close_iid_key;
175 if (0 <= list->num_methods)
177 static WCHAR const fmt[3] = { '%', 'd', 0 };
178 HKEY key;
180 res = RegCreateKeyExW(iid_key, num_methods_keyname, 0, NULL, 0,
181 KEY_READ | KEY_WRITE, NULL, &key, NULL);
182 if (res != ERROR_SUCCESS) goto error_close_iid_key;
184 sprintfW(buf, fmt, list->num_methods);
185 res = RegSetValueExW(key, NULL, 0, REG_SZ,
186 (CONST BYTE*)buf,
187 (lstrlenW(buf) + 1) * sizeof(WCHAR));
188 RegCloseKey(key);
190 if (res != ERROR_SUCCESS) goto error_close_iid_key;
193 if (list->ps_clsid)
195 res = register_key_guid(iid_key, ps_clsid_keyname, list->ps_clsid);
196 if (res != ERROR_SUCCESS) goto error_close_iid_key;
199 if (list->ps_clsid32)
201 res = register_key_guid(iid_key, ps_clsid32_keyname, list->ps_clsid32);
202 if (res != ERROR_SUCCESS) goto error_close_iid_key;
205 error_close_iid_key:
206 RegCloseKey(iid_key);
209 error_close_interface_key:
210 RegCloseKey(interface_key);
211 error_return:
212 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
215 /***********************************************************************
216 * unregister_interfaces
218 static HRESULT unregister_interfaces(struct regsvr_interface const *list)
220 LONG res = ERROR_SUCCESS;
221 HKEY interface_key;
223 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0,
224 KEY_READ | KEY_WRITE, &interface_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->iid; ++list)
230 WCHAR buf[39];
232 StringFromGUID2(list->iid, buf, 39);
233 res = RegDeleteTreeW(interface_key, buf);
234 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
237 RegCloseKey(interface_key);
238 error_return:
239 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
242 /***********************************************************************
243 * register_coclasses
245 static HRESULT register_coclasses(struct regsvr_coclass const *list)
247 LONG res = ERROR_SUCCESS;
248 HKEY coclass_key;
250 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
251 KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
252 if (res != ERROR_SUCCESS) goto error_return;
254 for (; res == ERROR_SUCCESS && list->clsid; ++list)
256 WCHAR buf[39];
257 HKEY clsid_key;
259 StringFromGUID2(list->clsid, buf, 39);
260 res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
261 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
262 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
264 if (list->name)
266 res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
267 (CONST BYTE*)(list->name),
268 strlen(list->name) + 1);
269 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
272 if (list->iph32)
274 HKEY iph32_key;
276 res = RegCreateKeyExW(clsid_key, iph32_keyname, 0, NULL, 0,
277 KEY_READ | KEY_WRITE, NULL,
278 &iph32_key, NULL);
279 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
281 res = RegSetValueExA(iph32_key, NULL, 0, REG_SZ,
282 (CONST BYTE*)list->iph32,
283 lstrlenA(list->iph32) + 1);
284 RegCloseKey(iph32_key);
285 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
288 if (list->ips)
290 res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
291 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
294 if (list->ips32)
296 HKEY ips32_key;
298 res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
299 KEY_READ | KEY_WRITE, NULL,
300 &ips32_key, NULL);
301 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
303 res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
304 (CONST BYTE*)list->ips32,
305 lstrlenA(list->ips32) + 1);
306 if (res == ERROR_SUCCESS && list->ips32_tmodel)
307 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
308 (CONST BYTE*)list->ips32_tmodel,
309 strlen(list->ips32_tmodel) + 1);
310 RegCloseKey(ips32_key);
311 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
314 if (list->progid)
316 res = register_key_defvalueA(clsid_key, progid_keyname,
317 list->progid);
318 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
320 res = register_progid(list->flags & PROGID_CLSID ? buf : NULL,
321 list->progid, NULL,
322 list->name, list->progid_extra);
323 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
326 if (list->viprogid)
328 res = register_key_defvalueA(clsid_key, viprogid_keyname,
329 list->viprogid);
330 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
332 res = register_progid(list->flags & PROGID_CLSID ? buf : NULL,
333 list->viprogid, list->progid,
334 list->name, list->progid_extra);
335 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
338 if (list->dllversion)
340 HKEY dllver_key;
342 res = RegCreateKeyExW(clsid_key, dllversion_keyname, 0, NULL, 0,
343 KEY_READ | KEY_WRITE, NULL,
344 &dllver_key, NULL);
345 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
347 res = RegSetValueExA(dllver_key, NULL, 0, REG_SZ,
348 (CONST BYTE*)list->dllversion,
349 lstrlenA(list->dllversion) + 1);
350 RegCloseKey(dllver_key);
351 if (res != ERROR_SUCCESS) goto error_close_clsid_key;
355 error_close_clsid_key:
356 RegCloseKey(clsid_key);
359 error_close_coclass_key:
360 RegCloseKey(coclass_key);
361 error_return:
362 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
365 /***********************************************************************
366 * unregister_coclasses
368 static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
370 LONG res = ERROR_SUCCESS;
371 HKEY coclass_key;
373 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
374 KEY_READ | KEY_WRITE, &coclass_key);
375 if (res == ERROR_FILE_NOT_FOUND) return S_OK;
376 if (res != ERROR_SUCCESS) goto error_return;
378 for (; res == ERROR_SUCCESS && list->clsid; ++list)
380 WCHAR buf[39];
382 StringFromGUID2(list->clsid, buf, 39);
383 res = RegDeleteTreeW(coclass_key, buf);
384 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
385 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
387 if (list->progid)
389 res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->progid);
390 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
391 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
394 if (list->viprogid)
396 res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->viprogid);
397 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
398 if (res != ERROR_SUCCESS) goto error_close_coclass_key;
402 error_close_coclass_key:
403 RegCloseKey(coclass_key);
404 error_return:
405 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
408 /***********************************************************************
409 * register_key_guid
411 static LONG register_key_guid(HKEY base, WCHAR const *name, GUID const *guid)
413 WCHAR buf[39];
415 StringFromGUID2(guid, buf, 39);
416 return register_key_defvalueW(base, name, buf);
419 /***********************************************************************
420 * register_key_defvalueW
422 static LONG register_key_defvalueW(HKEY base, WCHAR const *name, WCHAR const *value)
424 LONG res;
425 HKEY key;
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));
432 RegCloseKey(key);
433 return res;
436 /***********************************************************************
437 * register_key_defvalueA
439 static LONG register_key_defvalueA(HKEY base, WCHAR const *name, char const *value)
441 LONG res;
442 HKEY key;
444 res = RegCreateKeyExW(base, name, 0, NULL, 0,
445 KEY_READ | KEY_WRITE, NULL, &key, NULL);
446 if (res != ERROR_SUCCESS) return res;
447 res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
448 lstrlenA(value) + 1);
449 RegCloseKey(key);
450 return res;
453 /***********************************************************************
454 * register_progid
456 static LONG register_progid(WCHAR const *clsid, char const *progid,
457 char const *curver_progid, char const *name,
458 char const *extra)
460 LONG res;
461 HKEY progid_key;
463 res = RegCreateKeyExA(HKEY_CLASSES_ROOT, progid, 0,
464 NULL, 0, KEY_READ | KEY_WRITE, NULL,
465 &progid_key, NULL);
466 if (res != ERROR_SUCCESS) return res;
468 if (name)
470 res = RegSetValueExA(progid_key, NULL, 0, REG_SZ,
471 (CONST BYTE*)name, strlen(name) + 1);
472 if (res != ERROR_SUCCESS) goto error_close_progid_key;
475 if (clsid)
477 res = register_key_defvalueW(progid_key, clsid_keyname, clsid);
478 if (res != ERROR_SUCCESS) goto error_close_progid_key;
481 if (curver_progid)
483 res = register_key_defvalueA(progid_key, curver_keyname, curver_progid);
484 if (res != ERROR_SUCCESS) goto error_close_progid_key;
487 if (extra)
489 HKEY extra_key;
491 res = RegCreateKeyExA(progid_key, extra, 0,
492 NULL, 0, KEY_READ | KEY_WRITE, NULL,
493 &extra_key, NULL);
494 if (res == ERROR_SUCCESS)
495 RegCloseKey(extra_key);
498 error_close_progid_key:
499 RegCloseKey(progid_key);
500 return res;
503 /***********************************************************************
504 * coclass list
506 static struct regsvr_coclass const coclass_list[] =
509 &CLSID_OLEDB_CONVERSIONLIBRARY,
510 "OLE DB Data Conversion Library",
511 NULL,
512 NULL,
513 "oledb32.dll",
514 "Both",
515 PROGID_CLSID,
516 "MSDADC.1",
517 "MSDADC",
518 NULL,
519 NULL
521 { NULL } /* list terminator */
524 /***********************************************************************
525 * interface list
527 static struct regsvr_interface const interface_list[] =
529 { NULL } /* list terminator */
532 /***********************************************************************
533 * DllRegisterServer
535 HRESULT WINAPI DllRegisterServer(void)
537 HRESULT hr;
539 TRACE("\n");
541 hr = register_coclasses(coclass_list);
542 if (SUCCEEDED(hr))
543 hr = register_interfaces(interface_list);
544 return hr;
547 /***********************************************************************
548 * DllUnregisterServer
550 HRESULT WINAPI DllUnregisterServer(void)
552 HRESULT hr;
554 TRACE("\n");
556 hr = unregister_coclasses(coclass_list);
557 if (SUCCEEDED(hr))
558 hr = unregister_interfaces(interface_list);
559 return hr;