2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 #pragma off (unreferenced)
16 static char rcsid[] = "$Id: winregs.c,v 1.1.1.1 2001-01-19 03:30:15 bradleyb Exp $";
17 #pragma on (unreferenced)
21 #define WIN32_LEAN_AND_MEAN
30 static HKEY hRootKey=HKEY_LOCAL_MACHINE;
33 void registry_setpath(HKEY hKey)
35 hRootKey = HKEY_LOCAL_MACHINE;
40 registry_handle *registry_open(const char *path)
47 registry_handle *handle;
49 // Find number of keys
50 regpath = (char *)malloc(strlen(path)+1);
51 if (!regpath) return NULL;
53 strcpy(regpath, path);
56 regtoken = strtok(regpath, "\\");
65 regtoken = strtok(NULL, "\\");
69 handle = (registry_handle*)malloc(sizeof(registry_handle));
71 handle->hKey = (HKEY *)malloc(sizeof(HKEY)*keys);
77 memset(handle->hKey, 0, sizeof(HKEY)*keys);
81 strcpy(regpath, path);
82 regtoken = strtok(regpath, "\\");
84 if (regtoken) mprintf((0, "%s\\", regtoken));
86 lres = RegOpenKeyEx(hRootKey, regtoken, 0, KEY_EXECUTE | KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE, &handle->hKey[i]);
87 if (lres != ERROR_SUCCESS)
88 goto RegistryOpen_Cleanup;
90 regtoken = strtok(NULL, "\\");
92 if (regtoken) mprintf((0, "%s\\", regtoken));
97 lres = RegOpenKeyEx(handle->hKey[i-1], regtoken, 0, KEY_EXECUTE | KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE, &handle->hKey[i]);
98 if (lres != ERROR_SUCCESS)
99 goto RegistryOpen_Cleanup;
101 regtoken = strtok(NULL, "\\");
102 if (regtoken) mprintf((0, "%s\\", regtoken));
112 RegistryOpen_Cleanup:
113 for (i = handle->keys-1; i >=0; i--)
114 if (handle->hKey[i]) {
115 RegCloseKey(handle->hKey[i]);
126 int registry_getint(registry_handle *handle, const char *label, int *val)
133 lres = RegQueryValueEx(handle->hKey[handle->keys-1], label, NULL,
134 &type, (LPBYTE)val, &size);
135 if (lres != ERROR_SUCCESS) return 0;
136 if (type != REG_DWORD) return 0;
142 int registry_getstring(registry_handle *handle, const char *label, char *str, int bufsize)
148 lres = RegQueryValueEx(handle->hKey[handle->keys-1], label, NULL, &type,
151 if (lres != ERROR_SUCCESS) return 0;
152 if (type != REG_SZ && type != REG_EXPAND_SZ) return 0;
159 int registry_close(registry_handle *handle)
163 for (i = handle->keys-1; i >=0; i--)
164 if (handle->hKey[i]) {
165 RegCloseKey(handle->hKey[i]);
180 int registry_create(const char *name)
182 HANDLE hSubKey, hGroupKey, hOurKey;
186 result = RegOpenKeyEx(HKEY_CURRENT_USER, REG_DIR_PARENT, 0, KEY_ALL_ACCESS,
188 if (result!=ERROR_SUCCESS) return 0;
189 result = RegOpenKeyEx(hSubKey, REG_DIR_GROUP, 0, KEY_ALL_ACCESS, &hGroupKey);
190 if (result!=ERROR_SUCCESS) {
191 result = RegCreateKeyEx(hSubKey, REG_DIR_GROUP, 0, NULL, 0, KEY_ALL_ACCESS, NULL,
193 if (result!=ERROR_SUCCESS) {
194 RegCloseKey(hSubKey);
197 result = RegCreateKeyEx(hGroupKey, name, 0, NULL, 0, KEY_ALL_ACCESS, NULL,
199 if (result !=ERROR_SUCCESS) {
200 RegCloseKey(hGroupKey);
201 RegCloseKey(hSubKey);
205 RegCloseKey(hOurKey);
206 RegCloseKey(hGroupKey);
207 RegCloseKey(hSubKey);
212 int registry_delete(const char *name)
219 int registry_open(const char *name)
225 Assert(hMyRegKey == NULL);
227 strcpy(path, REG_DIR_PATH);
230 result = RegOpenKeyEx(HKEY_CURRENT_USER, path, 0, 0, &hKey);
231 if (result != ERROR_SUCCESS) return 0;
241 Assert(hMyRegKey != NULL);
242 RegCloseKey(hMyRegKey);
249 int registry_addint(const char *valname, int val)
253 result = RegSetValueEx(hMyRegKey, valname, 0, REG_DWORD, &val, sizeof(val));
255 if (result != ERROR_SUCCESS) return 0;
260 int registry_addstring(const char *valname, const char *str)
264 result = RegSetValueEx(hMyRegKey, valname, 0, REG_SZ, str, lstrlen(str));
266 if (result != ERROR_SUCCESS) return 0;