1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#include <windows.h>
#include "leash-int.h"
static
LONG
write_registry_setting_ex(
HKEY hRoot,
char* setting,
DWORD type,
void* buffer,
size_t size
)
{
HKEY hKey = 0;
LONG rc = 0;
if (rc = RegCreateKeyEx(hRoot, LEASH_SETTINGS_REGISTRY_KEY_NAME, 0, 0, 0,
KEY_ALL_ACCESS, 0, &hKey, 0))
goto cleanup;
rc = RegSetValueEx(hKey, setting, 0, type, (LPBYTE)buffer, size);
cleanup:
if (hKey)
RegCloseKey(hKey);
return rc;
}
LONG
write_registry_setting(
char* setting,
DWORD type,
void* buffer,
size_t size
)
{
return write_registry_setting_ex(HKEY_CURRENT_USER,
setting,
type,
buffer,
size);
}
static
LONG
read_registry_setting_ex(
HKEY hRoot,
char* setting,
void* buffer,
size_t size
)
{
HKEY hKey = 0;
LONG rc = 0;
DWORD dwType;
DWORD dwCount;
if (rc = RegOpenKeyEx(hRoot,
LEASH_SETTINGS_REGISTRY_KEY_NAME,
0, KEY_QUERY_VALUE, &hKey))
goto cleanup;
memset(buffer, 0, size);
dwCount = size;
rc = RegQueryValueEx(hKey, setting, NULL, &dwType, (LPBYTE)buffer,
&dwCount);
cleanup:
if (hKey)
RegCloseKey(hKey);
return rc;
}
LONG
read_registry_setting_user(
char* setting,
void* buffer,
size_t size
)
{
return read_registry_setting_ex(HKEY_CURRENT_USER, setting, buffer, size);
}
static
LONG
read_registry_setting_machine(
char* setting,
void* buffer,
size_t size
)
{
return read_registry_setting_ex(HKEY_LOCAL_MACHINE, setting, buffer, size);
}
LONG
read_registry_setting(
char* setting,
void* buffer,
size_t size
)
{
LONG rc;
rc = read_registry_setting_user(setting, buffer, size);
if (!rc) return rc;
rc = read_registry_setting_machine(setting, buffer, size);
return rc;
}
|