Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenregsvr.c
Go to the documentation of this file.
00001 /* 00002 * self-registerable dll functions for dinput8.dll 00003 * 00004 * Copyright (C) 2003 John K. Hohm 00005 * Copyright (C) 2007 Francois Gouget for CodeWeavers 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 00022 #include <stdarg.h> 00023 #include <string.h> 00024 00025 #include "windef.h" 00026 #include "winbase.h" 00027 #include "winreg.h" 00028 #include "wingdi.h" 00029 #include "winuser.h" 00030 #include "winerror.h" 00031 00032 #include "dinput.h" 00033 00034 #include "wine/debug.h" 00035 00036 WINE_DEFAULT_DEBUG_CHANNEL(dinput); 00037 00038 /* 00039 * Near the bottom of this file are the exported DllRegisterServer and 00040 * DllUnregisterServer, which make all this worthwhile. 00041 */ 00042 00043 /*********************************************************************** 00044 * interface for self-registering 00045 */ 00046 00047 struct regsvr_coclass 00048 { 00049 CLSID const *clsid; /* NULL for end of list */ 00050 LPCSTR name; /* can be NULL to omit */ 00051 LPCSTR ips; /* can be NULL to omit */ 00052 LPCSTR ips32; /* can be NULL to omit */ 00053 LPCSTR ips32_tmodel; /* can be NULL to omit */ 00054 LPCSTR clsid_str; /* can be NULL to omit */ 00055 LPCSTR progid; /* can be NULL to omit */ 00056 }; 00057 00058 static HRESULT register_coclasses(struct regsvr_coclass const *list); 00059 static HRESULT unregister_coclasses(struct regsvr_coclass const *list); 00060 00061 /*********************************************************************** 00062 * static string constants 00063 */ 00064 static WCHAR const interface_keyname[10] = { 00065 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 'e', 0 }; 00066 static WCHAR const base_ifa_keyname[14] = { 00067 'B', 'a', 's', 'e', 'I', 'n', 't', 'e', 'r', 'f', 'a', 'c', 00068 'e', 0 }; 00069 static WCHAR const num_methods_keyname[11] = { 00070 'N', 'u', 'm', 'M', 'e', 't', 'h', 'o', 'd', 's', 0 }; 00071 static WCHAR const ps_clsid_keyname[15] = { 00072 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's', 00073 'i', 'd', 0 }; 00074 static WCHAR const ps_clsid32_keyname[17] = { 00075 'P', 'r', 'o', 'x', 'y', 'S', 't', 'u', 'b', 'C', 'l', 's', 00076 'i', 'd', '3', '2', 0 }; 00077 static WCHAR const clsid_keyname[6] = { 00078 'C', 'L', 'S', 'I', 'D', 0 }; 00079 static WCHAR const ips_keyname[13] = { 00080 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r', 00081 0 }; 00082 static WCHAR const ips32_keyname[15] = { 00083 'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r', 00084 '3', '2', 0 }; 00085 static WCHAR const progid_keyname[7] = { 00086 'P', 'r', 'o', 'g', 'I', 'D', 0 }; 00087 static char const tmodel_valuename[] = "ThreadingModel"; 00088 00089 /*********************************************************************** 00090 * static helper functions 00091 */ 00092 static LONG register_key_defvalueW(HKEY base, WCHAR const *name, 00093 WCHAR const *value); 00094 static LONG register_key_defvalueA(HKEY base, WCHAR const *name, 00095 char const *value); 00096 00097 /*********************************************************************** 00098 * register_coclasses 00099 */ 00100 static HRESULT register_coclasses(struct regsvr_coclass const *list) 00101 { 00102 LONG res = ERROR_SUCCESS; 00103 HKEY coclass_key; 00104 00105 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0, 00106 KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL); 00107 if (res != ERROR_SUCCESS) goto error_return; 00108 00109 for (; res == ERROR_SUCCESS && list->clsid; ++list) { 00110 WCHAR buf[39]; 00111 HKEY clsid_key; 00112 00113 StringFromGUID2(list->clsid, buf, 39); 00114 res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0, 00115 KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL); 00116 if (res != ERROR_SUCCESS) goto error_close_coclass_key; 00117 00118 if (list->name) { 00119 res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ, 00120 (CONST BYTE*)(list->name), 00121 strlen(list->name) + 1); 00122 if (res != ERROR_SUCCESS) goto error_close_clsid_key; 00123 } 00124 00125 if (list->ips) { 00126 res = register_key_defvalueA(clsid_key, ips_keyname, list->ips); 00127 if (res != ERROR_SUCCESS) goto error_close_clsid_key; 00128 } 00129 00130 if (list->ips32) { 00131 HKEY ips32_key; 00132 00133 res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0, 00134 KEY_READ | KEY_WRITE, NULL, 00135 &ips32_key, NULL); 00136 if (res != ERROR_SUCCESS) goto error_close_clsid_key; 00137 00138 res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ, 00139 (CONST BYTE*)list->ips32, 00140 lstrlenA(list->ips32) + 1); 00141 if (res == ERROR_SUCCESS && list->ips32_tmodel) 00142 res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ, 00143 (CONST BYTE*)list->ips32_tmodel, 00144 strlen(list->ips32_tmodel) + 1); 00145 RegCloseKey(ips32_key); 00146 if (res != ERROR_SUCCESS) goto error_close_clsid_key; 00147 } 00148 00149 if (list->clsid_str) { 00150 res = register_key_defvalueA(clsid_key, clsid_keyname, 00151 list->clsid_str); 00152 if (res != ERROR_SUCCESS) goto error_close_clsid_key; 00153 } 00154 00155 if (list->progid) { 00156 HKEY progid_key; 00157 00158 res = register_key_defvalueA(clsid_key, progid_keyname, 00159 list->progid); 00160 if (res != ERROR_SUCCESS) goto error_close_clsid_key; 00161 00162 res = RegCreateKeyExA(HKEY_CLASSES_ROOT, list->progid, 0, 00163 NULL, 0, KEY_READ | KEY_WRITE, NULL, 00164 &progid_key, NULL); 00165 if (res != ERROR_SUCCESS) goto error_close_clsid_key; 00166 00167 res = register_key_defvalueW(progid_key, clsid_keyname, buf); 00168 RegCloseKey(progid_key); 00169 if (res != ERROR_SUCCESS) goto error_close_clsid_key; 00170 } 00171 00172 error_close_clsid_key: 00173 RegCloseKey(clsid_key); 00174 } 00175 00176 error_close_coclass_key: 00177 RegCloseKey(coclass_key); 00178 error_return: 00179 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK; 00180 } 00181 00182 /*********************************************************************** 00183 * unregister_coclasses 00184 */ 00185 static HRESULT unregister_coclasses(struct regsvr_coclass const *list) 00186 { 00187 LONG res = ERROR_SUCCESS; 00188 HKEY coclass_key; 00189 00190 res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, 00191 KEY_READ | KEY_WRITE, &coclass_key); 00192 if (res == ERROR_FILE_NOT_FOUND) return S_OK; 00193 if (res != ERROR_SUCCESS) goto error_return; 00194 00195 for (; res == ERROR_SUCCESS && list->clsid; ++list) { 00196 WCHAR buf[39]; 00197 00198 StringFromGUID2(list->clsid, buf, 39); 00199 res = RegDeleteTreeW(coclass_key, buf); 00200 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS; 00201 if (res != ERROR_SUCCESS) goto error_close_coclass_key; 00202 00203 if (list->progid) { 00204 res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->progid); 00205 if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS; 00206 if (res != ERROR_SUCCESS) goto error_close_coclass_key; 00207 } 00208 } 00209 00210 error_close_coclass_key: 00211 RegCloseKey(coclass_key); 00212 error_return: 00213 return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK; 00214 } 00215 00216 /*********************************************************************** 00217 * regsvr_key_defvalueW 00218 */ 00219 static LONG register_key_defvalueW( 00220 HKEY base, 00221 WCHAR const *name, 00222 WCHAR const *value) 00223 { 00224 LONG res; 00225 HKEY key; 00226 00227 res = RegCreateKeyExW(base, name, 0, NULL, 0, 00228 KEY_READ | KEY_WRITE, NULL, &key, NULL); 00229 if (res != ERROR_SUCCESS) return res; 00230 res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value, 00231 (lstrlenW(value) + 1) * sizeof(WCHAR)); 00232 RegCloseKey(key); 00233 return res; 00234 } 00235 00236 /*********************************************************************** 00237 * regsvr_key_defvalueA 00238 */ 00239 static LONG register_key_defvalueA( 00240 HKEY base, 00241 WCHAR const *name, 00242 char const *value) 00243 { 00244 LONG res; 00245 HKEY key; 00246 00247 res = RegCreateKeyExW(base, name, 0, NULL, 0, 00248 KEY_READ | KEY_WRITE, NULL, &key, NULL); 00249 if (res != ERROR_SUCCESS) return res; 00250 res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value, 00251 lstrlenA(value) + 1); 00252 RegCloseKey(key); 00253 return res; 00254 } 00255 00256 /*********************************************************************** 00257 * coclass list 00258 */ 00259 00260 static struct regsvr_coclass const coclass_list[] = { 00261 { &CLSID_DirectInput8, 00262 "DirectInput8 Object", 00263 NULL, 00264 "dinput8.dll", 00265 "Both" 00266 }, 00267 { NULL } /* list terminator */ 00268 }; 00269 00270 /*********************************************************************** 00271 * DllRegisterServer (DINPUT8.@) 00272 */ 00273 HRESULT WINAPI DllRegisterServer(void) 00274 { 00275 HRESULT hr; 00276 00277 TRACE("\n"); 00278 00279 hr = register_coclasses(coclass_list); 00280 return hr; 00281 } 00282 00283 /*********************************************************************** 00284 * DllUnregisterServer (DINPUT8.@) 00285 */ 00286 HRESULT WINAPI DllUnregisterServer(void) 00287 { 00288 HRESULT hr; 00289 00290 TRACE("\n"); 00291 00292 hr = unregister_coclasses(coclass_list); 00293 return hr; 00294 } Generated on Sat May 26 2012 04:20:03 for ReactOS by
1.7.6.1
|