wined3d: Use dst_fbo to do the depth blit.
[wine] / dlls / dinput8 / regsvr.c
1 /*
2  *      self-registerable dll functions for dinput8.dll
3  *
4  * Copyright (C) 2003 John K. Hohm
5  * Copyright (C) 2007 Francois Gouget for CodeWeavers
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include <stdarg.h>
23 #include <string.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winerror.h"
31
32 #include "dinput.h"
33
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
37
38 /*
39  * Near the bottom of this file are the exported DllRegisterServer and
40  * DllUnregisterServer, which make all this worthwhile.
41  */
42
43 /***********************************************************************
44  *              interface for self-registering
45  */
46
47 struct regsvr_coclass
48 {
49     CLSID const *clsid;         /* NULL for end of list */
50     LPCSTR name;                /* can be NULL to omit */
51     LPCSTR ips;                 /* can be NULL to omit */
52     LPCSTR ips32;               /* can be NULL to omit */
53     LPCSTR ips32_tmodel;        /* can be NULL to omit */
54     LPCSTR clsid_str;           /* can be NULL to omit */
55     LPCSTR progid;              /* can be NULL to omit */
56 };
57
58 static HRESULT register_coclasses(struct regsvr_coclass const *list);
59 static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
60
61 /***********************************************************************
62  *              static string constants
63  */
64 static WCHAR const interface_keyname[10] = {
65     'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 };
66 static WCHAR const base_ifa_keyname[14] = {
67     'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c',
68     'e', 0 };
69 static WCHAR const num_methods_keyname[11] = {
70     'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 };
71 static WCHAR const ps_clsid_keyname[15] = {
72     'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
73     'i', 'd', 0 };
74 static WCHAR const ps_clsid32_keyname[17] = {
75     'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's',
76     'i', 'd', '3', '2', 0 };
77 static WCHAR const clsid_keyname[6] = {
78     'C', 'L', 'S', 'I', 'D', 0 };
79 static WCHAR const ips_keyname[13] = {
80     'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
81     0 };
82 static WCHAR const ips32_keyname[15] = {
83     'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
84     '3', '2', 0 };
85 static WCHAR const progid_keyname[7] = {
86     'P', 'r', 'o', 'g', 'I', 'D', 0 };
87 static char const tmodel_valuename[] = "ThreadingModel";
88
89 /***********************************************************************
90  *              static helper functions
91  */
92 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
93                                    WCHAR const *value);
94 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
95                                    char const *value);
96
97 /***********************************************************************
98  *              register_coclasses
99  */
100 static HRESULT register_coclasses(struct regsvr_coclass const *list)
101 {
102     LONG res = ERROR_SUCCESS;
103     HKEY coclass_key;
104
105     res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
106                           KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
107     if (res != ERROR_SUCCESS) goto error_return;
108
109     for (; res == ERROR_SUCCESS && list->clsid; ++list) {
110         WCHAR buf[39];
111         HKEY clsid_key;
112
113         StringFromGUID2(list->clsid, buf, 39);
114         res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
115                               KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
116         if (res != ERROR_SUCCESS) goto error_close_coclass_key;
117
118         if (list->name) {
119             res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
120                                  (CONST BYTE*)(list->name),
121                                  strlen(list->name) + 1);
122             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
123         }
124
125         if (list->ips) {
126             res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
127             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
128         }
129
130         if (list->ips32) {
131             HKEY ips32_key;
132
133             res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
134                                   KEY_READ | KEY_WRITE, NULL,
135                                   &ips32_key, NULL);
136             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
137
138             res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
139                                  (CONST BYTE*)list->ips32,
140                                  lstrlenA(list->ips32) + 1);
141             if (res == ERROR_SUCCESS && list->ips32_tmodel)
142                 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
143                                      (CONST BYTE*)list->ips32_tmodel,
144                                      strlen(list->ips32_tmodel) + 1);
145             RegCloseKey(ips32_key);
146             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
147         }
148
149         if (list->clsid_str) {
150             res = register_key_defvalueA(clsid_key, clsid_keyname,
151                                          list->clsid_str);
152             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
153         }
154
155         if (list->progid) {
156             HKEY progid_key;
157
158             res = register_key_defvalueA(clsid_key, progid_keyname,
159                                          list->progid);
160             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
161
162             res = RegCreateKeyExA(HKEY_CLASSES_ROOT, list->progid, 0,
163                                   NULL, 0, KEY_READ | KEY_WRITE, NULL,
164                                   &progid_key, NULL);
165             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
166
167             res = register_key_defvalueW(progid_key, clsid_keyname, buf);
168             RegCloseKey(progid_key);
169             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
170         }
171
172     error_close_clsid_key:
173         RegCloseKey(clsid_key);
174     }
175
176 error_close_coclass_key:
177     RegCloseKey(coclass_key);
178 error_return:
179     return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
180 }
181
182 /***********************************************************************
183  *              unregister_coclasses
184  */
185 static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
186 {
187     LONG res = ERROR_SUCCESS;
188     HKEY coclass_key;
189
190     res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
191                         KEY_READ | KEY_WRITE, &coclass_key);
192     if (res == ERROR_FILE_NOT_FOUND) return S_OK;
193     if (res != ERROR_SUCCESS) goto error_return;
194
195     for (; res == ERROR_SUCCESS && list->clsid; ++list) {
196         WCHAR buf[39];
197
198         StringFromGUID2(list->clsid, buf, 39);
199         res = RegDeleteTreeW(coclass_key, buf);
200         if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
201         if (res != ERROR_SUCCESS) goto error_close_coclass_key;
202
203         if (list->progid) {
204             res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->progid);
205             if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
206             if (res != ERROR_SUCCESS) goto error_close_coclass_key;
207         }
208     }
209
210 error_close_coclass_key:
211     RegCloseKey(coclass_key);
212 error_return:
213     return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
214 }
215
216 /***********************************************************************
217  *              regsvr_key_defvalueW
218  */
219 static LONG register_key_defvalueW(
220     HKEY base,
221     WCHAR const *name,
222     WCHAR const *value)
223 {
224     LONG res;
225     HKEY key;
226
227     res = RegCreateKeyExW(base, name, 0, NULL, 0,
228                           KEY_READ | KEY_WRITE, NULL, &key, NULL);
229     if (res != ERROR_SUCCESS) return res;
230     res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
231                          (lstrlenW(value) + 1) * sizeof(WCHAR));
232     RegCloseKey(key);
233     return res;
234 }
235
236 /***********************************************************************
237  *              regsvr_key_defvalueA
238  */
239 static LONG register_key_defvalueA(
240     HKEY base,
241     WCHAR const *name,
242     char const *value)
243 {
244     LONG res;
245     HKEY key;
246
247     res = RegCreateKeyExW(base, name, 0, NULL, 0,
248                           KEY_READ | KEY_WRITE, NULL, &key, NULL);
249     if (res != ERROR_SUCCESS) return res;
250     res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
251                          lstrlenA(value) + 1);
252     RegCloseKey(key);
253     return res;
254 }
255
256 /***********************************************************************
257  *              coclass list
258  */
259
260 static struct regsvr_coclass const coclass_list[] = {
261     {   &CLSID_DirectInput8,
262         "DirectInput8 Object",
263         NULL,
264         "dinput8.dll",
265         "Both"
266     },
267     { NULL }                    /* list terminator */
268 };
269
270 /***********************************************************************
271  *              DllRegisterServer (DINPUT8.@)
272  */
273 HRESULT WINAPI DllRegisterServer(void)
274 {
275     HRESULT hr;
276
277     TRACE("\n");
278
279     hr = register_coclasses(coclass_list);
280     return hr;
281 }
282
283 /***********************************************************************
284  *              DllUnregisterServer (DINPUT8.@)
285  */
286 HRESULT WINAPI DllUnregisterServer(void)
287 {
288     HRESULT hr;
289
290     TRACE("\n");
291
292     hr = unregister_coclasses(coclass_list);
293     return hr;
294 }