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