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.
17 #define WIN32_LEAN_AND_MEAN
26 static HKEY hRootKey=HKEY_LOCAL_MACHINE;
29 void registry_setpath(HKEY hKey)
31 hRootKey = HKEY_LOCAL_MACHINE;
36 registry_handle *registry_open(const char *path)
43 registry_handle *handle;
45 // Find number of keys
46 regpath = (char *)malloc(strlen(path)+1);
47 if (!regpath) return NULL;
49 strcpy(regpath, path);
52 regtoken = strtok(regpath, "\\");
61 regtoken = strtok(NULL, "\\");
65 handle = (registry_handle*)malloc(sizeof(registry_handle));
67 handle->hKey = (HKEY *)malloc(sizeof(HKEY)*keys);
73 memset(handle->hKey, 0, sizeof(HKEY)*keys);
77 strcpy(regpath, path);
78 regtoken = strtok(regpath, "\\");
80 if (regtoken) mprintf((0, "%s\\", regtoken));
82 lres = RegOpenKeyEx(hRootKey, regtoken, 0, KEY_EXECUTE | KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE, &handle->hKey[i]);
83 if (lres != ERROR_SUCCESS)
84 goto RegistryOpen_Cleanup;
86 regtoken = strtok(NULL, "\\");
88 if (regtoken) mprintf((0, "%s\\", regtoken));
93 lres = RegOpenKeyEx(handle->hKey[i-1], regtoken, 0, KEY_EXECUTE | KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE, &handle->hKey[i]);
94 if (lres != ERROR_SUCCESS)
95 goto RegistryOpen_Cleanup;
97 regtoken = strtok(NULL, "\\");
98 if (regtoken) mprintf((0, "%s\\", regtoken));
108 RegistryOpen_Cleanup:
109 for (i = handle->keys-1; i >=0; i--)
110 if (handle->hKey[i]) {
111 RegCloseKey(handle->hKey[i]);
122 int registry_getint(registry_handle *handle, const char *label, int *val)
129 lres = RegQueryValueEx(handle->hKey[handle->keys-1], label, NULL,
130 &type, (LPBYTE)val, &size);
131 if (lres != ERROR_SUCCESS) return 0;
132 if (type != REG_DWORD) return 0;
138 int registry_getstring(registry_handle *handle, const char *label, char *str, int bufsize)
144 lres = RegQueryValueEx(handle->hKey[handle->keys-1], label, NULL, &type,
147 if (lres != ERROR_SUCCESS) return 0;
148 if (type != REG_SZ && type != REG_EXPAND_SZ) return 0;
155 int registry_close(registry_handle *handle)
159 for (i = handle->keys-1; i >=0; i--)
160 if (handle->hKey[i]) {
161 RegCloseKey(handle->hKey[i]);
176 int registry_create(const char *name)
178 HANDLE hSubKey, hGroupKey, hOurKey;
182 result = RegOpenKeyEx(HKEY_CURRENT_USER, REG_DIR_PARENT, 0, KEY_ALL_ACCESS,
184 if (result!=ERROR_SUCCESS) return 0;
185 result = RegOpenKeyEx(hSubKey, REG_DIR_GROUP, 0, KEY_ALL_ACCESS, &hGroupKey);
186 if (result!=ERROR_SUCCESS) {
187 result = RegCreateKeyEx(hSubKey, REG_DIR_GROUP, 0, NULL, 0, KEY_ALL_ACCESS, NULL,
189 if (result!=ERROR_SUCCESS) {
190 RegCloseKey(hSubKey);
193 result = RegCreateKeyEx(hGroupKey, name, 0, NULL, 0, KEY_ALL_ACCESS, NULL,
195 if (result !=ERROR_SUCCESS) {
196 RegCloseKey(hGroupKey);
197 RegCloseKey(hSubKey);
201 RegCloseKey(hOurKey);
202 RegCloseKey(hGroupKey);
203 RegCloseKey(hSubKey);
208 int registry_delete(const char *name)
215 int registry_open(const char *name)
221 Assert(hMyRegKey == NULL);
223 strcpy(path, REG_DIR_PATH);
226 result = RegOpenKeyEx(HKEY_CURRENT_USER, path, 0, 0, &hKey);
227 if (result != ERROR_SUCCESS) return 0;
237 Assert(hMyRegKey != NULL);
238 RegCloseKey(hMyRegKey);
245 int registry_addint(const char *valname, int val)
249 result = RegSetValueEx(hMyRegKey, valname, 0, REG_DWORD, &val, sizeof(val));
251 if (result != ERROR_SUCCESS) return 0;
256 int registry_addstring(const char *valname, const char *str)
260 result = RegSetValueEx(hMyRegKey, valname, 0, REG_SZ, str, lstrlen(str));
262 if (result != ERROR_SUCCESS) return 0;