1 /**
2  * Windows API header module
3  *
4  * Translated from MinGW Windows headers
5  *
6  * Authors: Stewart Gordon
7  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
8  * Source: $(DRUNTIMESRC core/sys/windows/_winreg.d)
9  */
10 module core.sys.windows.winreg;
11 version (Windows):
12 
13 version (ANSI) {} else version = Unicode;
14 pragma(lib, "advapi32");
15 
16 import core.sys.windows.w32api, core.sys.windows.winbase, core.sys.windows.windef;
17 
18 enum : HKEY { // for some reason, DMD errors if I don't give all the values explicitly
19     HKEY_CLASSES_ROOT        = cast(HKEY) 0x80000000,
20     HKEY_CURRENT_USER        = cast(HKEY) 0x80000001,
21     HKEY_LOCAL_MACHINE       = cast(HKEY) 0x80000002,
22     HKEY_USERS               = cast(HKEY) 0x80000003,
23     HKEY_PERFORMANCE_DATA    = cast(HKEY) 0x80000004,
24     HKEY_CURRENT_CONFIG      = cast(HKEY) 0x80000005,
25     HKEY_DYN_DATA            = cast(HKEY) 0x80000006,
26     HKEY_PERFORMANCE_TEXT    = cast(HKEY) 0x80000050,
27     HKEY_PERFORMANCE_NLSTEXT = cast(HKEY) 0x80000060,
28 }
29 
30 //enum : DWORD {
31 //    REG_OPTION_NON_VOLATILE,
32 //    REG_OPTION_VOLATILE
33 //}
34 
35 enum : DWORD {
36     REG_CREATED_NEW_KEY = 1,
37     REG_OPENED_EXISTING_KEY
38 }
39 
40 enum : DWORD {
41     REG_NONE                       = 0,
42     REG_SZ,
43     REG_EXPAND_SZ,
44     REG_BINARY,
45     REG_DWORD_LITTLE_ENDIAN,
46     REG_DWORD                      = REG_DWORD_LITTLE_ENDIAN,
47     REG_DWORD_BIG_ENDIAN,
48     REG_LINK,
49     REG_MULTI_SZ,
50     REG_RESOURCE_LIST,
51     REG_FULL_RESOURCE_DESCRIPTOR,
52     REG_RESOURCE_REQUIREMENTS_LIST,
53     REG_QWORD_LITTLE_ENDIAN,
54     REG_QWORD                      = REG_QWORD_LITTLE_ENDIAN
55 }
56 
57 enum DWORD
58     REG_NOTIFY_CHANGE_NAME       = 1,
59     REG_NOTIFY_CHANGE_ATTRIBUTES = 2,
60     REG_NOTIFY_CHANGE_LAST_SET   = 4,
61     REG_NOTIFY_CHANGE_SECURITY   = 8;
62 
63 alias ACCESS_MASK REGSAM;
64 
65 struct VALENTA {
66     LPSTR ve_valuename;
67     DWORD ve_valuelen;
68     DWORD_PTR ve_valueptr;
69     DWORD ve_type;
70 }
71 alias VALENTA* PVALENTA;
72 
73 struct VALENTW {
74     LPWSTR ve_valuename;
75     DWORD  ve_valuelen;
76     DWORD_PTR ve_valueptr;
77     DWORD  ve_type;
78 }
79 alias VALENTW* PVALENTW;
80 
81 // RRF - Registry Routine Flags (for RegGetValue)
82 static if (_WIN32_WINNT >= 0x600) {
83     enum : DWORD {
84         RRF_RT_REG_NONE      = 0x00000001,
85         RRF_RT_REG_SZ        = 0x00000002,
86         RRF_RT_REG_EXPAND_SZ = 0x00000004,
87         RRF_RT_REG_BINARY    = 0x00000008,
88         RRF_RT_REG_DWORD     = 0x00000010,
89         RRF_RT_REG_MULTI_SZ  = 0x00000020,
90         RRF_RT_REG_QWORD     = 0x00000040,
91         RRF_RT_DWORD         = RRF_RT_REG_BINARY | RRF_RT_REG_DWORD,
92         RRF_RT_QWORD         = RRF_RT_REG_BINARY | RRF_RT_REG_QWORD,
93         RRF_RT_ANY           = 0x0000FFFF,
94         RRF_NOEXPAND         = 0x10000000,
95         RRF_ZEROONFAILURE    = 0x20000000
96     }
97 }
98 
99 extern (Windows) nothrow @nogc {
100     LONG RegCloseKey(const scope HKEY);
101     LONG RegConnectRegistryA(LPCSTR, HKEY, PHKEY);
102     LONG RegConnectRegistryW(LPCWSTR, HKEY, PHKEY);
103     LONG RegCreateKeyExA(const scope HKEY, LPCSTR, DWORD, LPSTR, DWORD, REGSAM,
104       LPSECURITY_ATTRIBUTES, PHKEY, PDWORD);
105     LONG RegCreateKeyExW(const scope HKEY, LPCWSTR, DWORD, LPWSTR, DWORD, REGSAM,
106       LPSECURITY_ATTRIBUTES, PHKEY, PDWORD);
107     LONG RegDeleteKeyA(const scope HKEY, LPCSTR);
108     LONG RegDeleteKeyW(const scope HKEY, LPCWSTR);
109     LONG RegDeleteValueA(const scope HKEY, LPCSTR);
110     LONG RegDeleteValueW(const scope HKEY, LPCWSTR);
111     LONG RegEnumKeyExA(const scope HKEY, DWORD, LPSTR, PDWORD, PDWORD, LPSTR, PDWORD,
112       PFILETIME);
113     LONG RegEnumKeyExW(const scope HKEY, DWORD, LPWSTR, PDWORD, PDWORD, LPWSTR, PDWORD,
114       PFILETIME);
115     LONG RegEnumValueA(const scope HKEY, DWORD, LPSTR, PDWORD, PDWORD, PDWORD, LPBYTE,
116       PDWORD);
117     LONG RegEnumValueW(const scope HKEY, DWORD, LPWSTR, PDWORD, PDWORD, PDWORD, LPBYTE,
118       PDWORD);
119     LONG RegFlushKey(const scope HKEY);
120     LONG RegLoadKeyA(const scope HKEY, LPCSTR, LPCSTR);
121     LONG RegLoadKeyW(const scope HKEY, LPCWSTR, LPCWSTR);
122     LONG RegOpenKeyExA(const scope HKEY, LPCSTR, DWORD, REGSAM, PHKEY);
123     LONG RegOpenKeyExW(const scope HKEY, LPCWSTR, DWORD, REGSAM, PHKEY);
124     LONG RegQueryInfoKeyA(const scope HKEY, LPSTR, PDWORD, PDWORD, PDWORD, PDWORD,
125       PDWORD, PDWORD, PDWORD, PDWORD, PDWORD, PFILETIME);
126     LONG RegQueryInfoKeyW(const scope HKEY, LPWSTR, PDWORD, PDWORD, PDWORD, PDWORD,
127       PDWORD, PDWORD, PDWORD, PDWORD, PDWORD, PFILETIME);
128     LONG RegQueryMultipleValuesA(const scope HKEY, PVALENTA, DWORD, LPSTR, LPDWORD);
129     LONG RegQueryMultipleValuesW(const scope HKEY, PVALENTW, DWORD, LPWSTR, LPDWORD);
130     LONG RegQueryValueExA(const scope HKEY, LPCSTR, LPDWORD, LPDWORD, /*LPBYTE*/LPVOID, LPDWORD);
131     LONG RegQueryValueExW(const scope HKEY, LPCWSTR, LPDWORD, LPDWORD, /*LPBYTE*/LPVOID, LPDWORD);
132     LONG RegReplaceKeyA(const scope HKEY, LPCSTR, LPCSTR, LPCSTR);
133     LONG RegReplaceKeyW(const scope HKEY, LPCWSTR, LPCWSTR, LPCWSTR);
134     LONG RegSaveKeyA(const scope HKEY, LPCSTR, LPSECURITY_ATTRIBUTES);
135     LONG RegSaveKeyW(const scope HKEY, LPCWSTR, LPSECURITY_ATTRIBUTES);
136     LONG RegSetKeySecurity(const scope HKEY, SECURITY_INFORMATION, PSECURITY_DESCRIPTOR);
137     LONG RegSetValueExA(const scope HKEY, LPCSTR, DWORD, DWORD, const(BYTE)*, DWORD);
138     LONG RegSetValueExW(const scope HKEY, LPCWSTR, DWORD, DWORD, const(BYTE)*, DWORD);
139     LONG RegUnLoadKeyA(const scope HKEY, LPCSTR);
140     LONG RegUnLoadKeyW(const scope HKEY, LPCWSTR);
141     LONG RegNotifyChangeKeyValue(const scope HKEY, BOOL, DWORD, HANDLE, BOOL);
142 
143     BOOL AbortSystemShutdownA(LPCSTR);
144     BOOL AbortSystemShutdownW(LPCWSTR);
145     BOOL InitiateSystemShutdownA(LPSTR, LPSTR, DWORD, BOOL, BOOL);
146     BOOL InitiateSystemShutdownW(LPWSTR, LPWSTR, DWORD, BOOL, BOOL);
147     LONG RegGetKeySecurity(const scope HKEY, SECURITY_INFORMATION,
148       PSECURITY_DESCRIPTOR, PDWORD);
149     LONG RegRestoreKeyA(const scope HKEY, LPCSTR, DWORD);
150     LONG RegRestoreKeyW(const scope HKEY, LPCWSTR, DWORD);
151     LONG RegSetKeySecurity(const scope HKEY, SECURITY_INFORMATION,
152       PSECURITY_DESCRIPTOR);
153 
154     static if (_WIN32_WINNT >= 0x500) {
155         LONG RegDisablePredefinedCache();
156         LONG RegOpenCurrentUser(REGSAM, PHKEY);
157         LONG RegOpenUserClassesRoot(HANDLE, DWORD, REGSAM, PHKEY);
158     }
159 
160     static if (_WIN32_WINNT >= 0x501) {
161         LONG RegSaveKeyExA(const scope HKEY, LPCSTR, LPSECURITY_ATTRIBUTES, DWORD);
162         LONG RegSaveKeyExW(const scope HKEY, LPCWSTR, LPSECURITY_ATTRIBUTES, DWORD);
163     }
164 
165     static if (_WIN32_WINNT >= 0x600) {
166         LONG RegGetValueA(const scope HKEY hkey, LPCSTR lpSubKey, LPCSTR lpValue,
167           DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData);
168         LONG RegGetValueW(const scope HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpValue,
169           DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData);
170     }
171 
172     //deprecated {
173         LONG RegCreateKeyA(const scope HKEY, LPCSTR, PHKEY);
174         LONG RegCreateKeyW(const scope HKEY, LPCWSTR, PHKEY);
175         LONG RegEnumKeyA(const scope HKEY, DWORD, LPSTR, DWORD);
176         LONG RegEnumKeyW(const scope HKEY, DWORD, LPWSTR, DWORD);
177         LONG RegOpenKeyA(const scope HKEY, LPCSTR, PHKEY);
178         LONG RegOpenKeyW(const scope HKEY, LPCWSTR, PHKEY);
179         LONG RegQueryValueA(const scope HKEY, LPCSTR, LPSTR, PLONG);
180         LONG RegQueryValueW(const scope HKEY, LPCWSTR, LPWSTR, PLONG);
181         LONG RegSetValueA(const scope HKEY, LPCSTR, DWORD, LPCSTR, DWORD);
182         LONG RegSetValueW(const scope HKEY, LPCWSTR, DWORD, LPCWSTR, DWORD);
183     //}
184 }
185 
186 version (Unicode) {
187     alias VALENTW VALENT;
188     alias RegConnectRegistryW RegConnectRegistry;
189     alias RegCreateKeyExW RegCreateKeyEx;
190     alias RegDeleteKeyW RegDeleteKey;
191     alias RegDeleteValueW RegDeleteValue;
192     alias RegEnumKeyExW RegEnumKeyEx;
193     alias RegEnumValueW RegEnumValue;
194     alias RegLoadKeyW RegLoadKey;
195     alias RegOpenKeyExW RegOpenKeyEx;
196     alias RegQueryInfoKeyW RegQueryInfoKey;
197     alias RegQueryMultipleValuesW RegQueryMultipleValues;
198     alias RegQueryValueExW RegQueryValueEx;
199     alias RegReplaceKeyW RegReplaceKey;
200     alias RegSaveKeyW RegSaveKey;
201     alias RegSetValueExW RegSetValueEx;
202     alias RegUnLoadKeyW RegUnLoadKey;
203 
204     alias AbortSystemShutdownW AbortSystemShutdown;
205     alias InitiateSystemShutdownW InitiateSystemShutdown;
206     alias RegRestoreKeyW RegRestoreKey;
207     static if (_WIN32_WINNT >= 0x501) {
208         alias RegSaveKeyExA RegSaveKeyEx;
209     }
210     static if (_WIN32_WINNT >= 0x600) {
211         alias RegGetValueW RegGetValue;
212     }
213     //deprecated {
214         alias RegCreateKeyW RegCreateKey;
215         alias RegEnumKeyW RegEnumKey;
216         alias RegOpenKeyW RegOpenKey;
217         alias RegQueryValueW RegQueryValue;
218         alias RegSetValueW RegSetValue;
219     //}
220 } else {
221     alias VALENTA VALENT;
222     alias RegConnectRegistryA RegConnectRegistry;
223     alias RegCreateKeyExA RegCreateKeyEx;
224     alias RegDeleteKeyA RegDeleteKey;
225     alias RegDeleteValueA RegDeleteValue;
226     alias RegEnumKeyExA RegEnumKeyEx;
227     alias RegEnumValueA RegEnumValue;
228     alias RegLoadKeyA RegLoadKey;
229     alias RegOpenKeyExA RegOpenKeyEx;
230     alias RegQueryInfoKeyA RegQueryInfoKey;
231     alias RegQueryMultipleValuesA RegQueryMultipleValues;
232     alias RegQueryValueExA RegQueryValueEx;
233     alias RegReplaceKeyA RegReplaceKey;
234     alias RegSaveKeyA RegSaveKey;
235     alias RegSetValueExA RegSetValueEx;
236     alias RegUnLoadKeyA RegUnLoadKey;
237     alias AbortSystemShutdownA AbortSystemShutdown;
238     alias InitiateSystemShutdownA InitiateSystemShutdown;
239     alias RegRestoreKeyW RegRestoreKey;
240     static if (_WIN32_WINNT >= 0x501) {
241         alias RegSaveKeyExA RegSaveKeyEx;
242     }
243     static if (_WIN32_WINNT >= 0x600) {
244         alias RegGetValueA RegGetValue;
245     }
246     //deprecated {
247         alias RegCreateKeyA RegCreateKey;
248         alias RegEnumKeyA RegEnumKey;
249         alias RegOpenKeyA RegOpenKey;
250         alias RegQueryValueA RegQueryValue;
251         alias RegSetValueA RegSetValue;
252     //}
253 }
254 
255 alias VALENT* PVALENT;