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