source: trunk/src/shlwapi/reg.c@ 5655

Last change on this file since 5655 was 5618, checked in by sandervl, 24 years ago

resync with latest wine

File size: 13.7 KB
Line 
1/*
2 * SHLWAPI registry functions
3 */
4
5#include <string.h>
6#include "windef.h"
7#include "winbase.h"
8#include "wingdi.h"
9#include "winuser.h"
10#include "winerror.h"
11#include "winreg.h"
12#include "debugtools.h"
13#include "shlwapi.h"
14#include "wine/unicode.h"
15
16DEFAULT_DEBUG_CHANNEL(shell);
17
18static const char *lpszContentTypeA = "Content Type";
19static const WCHAR lpszContentTypeW[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
20
21/*************************************************************************
22 * SHRegGetUSValueA [SHLWAPI.@]
23 *
24 * Gets a user-specific registry value
25 */
26LONG WINAPI SHRegGetUSValueA(
27 LPCSTR pSubKey,
28 LPCSTR pValue,
29 LPDWORD pwType,
30 LPVOID pvData,
31 LPDWORD pbData,
32 BOOL fIgnoreHKCU,
33 LPVOID pDefaultData,
34 DWORD wDefaultDataSize)
35{
36 FIXME("(%p),stub!\n", pSubKey);
37 return ERROR_SUCCESS; /* return success */
38}
39
40/*************************************************************************
41 * SHRegGetUSValueW [SHLWAPI.@]
42 *
43 * Gets a user-specific registry value
44 */
45LONG WINAPI SHRegGetUSValueW(
46 LPCWSTR pSubKey,
47 LPCWSTR pValue,
48 LPDWORD pwType,
49 LPVOID pvData,
50 LPDWORD pbData,
51 BOOL flagIgnoreHKCU,
52 LPVOID pDefaultData,
53 DWORD wDefaultDataSize)
54{
55 FIXME("(%p),stub!\n", pSubKey);
56 return ERROR_SUCCESS; /* return success */
57}
58
59/*************************************************************************
60 * SHRegOpenUSKeyA [SHLWAPI.@]
61 *
62 * Openss a user-specific registry key
63 */
64LONG WINAPI SHRegOpenUSKeyA(
65 LPCSTR Path,
66 REGSAM AccessType,
67 HKEY hRelativeUSKey,
68 HKEY hNewUSKey,
69 BOOL fIgnoreHKCU)
70{
71 FIXME("stub!\n");
72 return ERROR_SUCCESS; /* return success */
73}
74
75/*************************************************************************
76 * SHRegOpenUSKeyW [SHLWAPI.@]
77 *
78 * Openss a user-specific registry key
79 */
80LONG WINAPI SHRegOpenUSKeyW(
81 LPCSTR Path,
82 REGSAM AccessType,
83 HKEY hRelativeUSKey,
84 HKEY hNewUSKey,
85 BOOL fIgnoreHKCU)
86{
87 FIXME("stub!\n");
88 return ERROR_SUCCESS; /* return success */
89}
90
91#ifndef __WIN32OS2__
92/*************************************************************************
93 * SHRegGetBoolUSValueA [SHLWAPI.@]
94 */
95BOOL WINAPI SHRegGetBoolUSValueA(
96 LPCSTR pszSubKey,
97 LPCSTR pszValue,
98 BOOL fIgnoreHKCU,
99 BOOL fDefault)
100{
101 FIXME("%s %s\n", pszSubKey,pszValue);
102 return fDefault;
103}
104
105/*************************************************************************
106 * SHRegGetBoolUSValueW [SHLWAPI.@]
107 */
108BOOL WINAPI SHRegGetBoolUSValueW(
109 LPCWSTR pszSubKey,
110 LPCWSTR pszValue,
111 BOOL fIgnoreHKCU,
112 BOOL fDefault)
113{
114 FIXME("%s %s\n", debugstr_w(pszSubKey),debugstr_w(pszValue));
115 return fDefault;
116}
117#endif
118
119/*************************************************************************
120 * SHRegQueryUSValueA [SHLWAPI]
121 */
122LONG WINAPI SHRegQueryUSValueA(
123 HKEY hUSKey, /* [in] FIXME: HUSKEY */
124 LPCSTR pszValue,
125 LPDWORD pdwType,
126 void *pvData,
127 LPDWORD pcbData,
128 BOOL fIgnoreHKCU,
129 void *pvDefaultData,
130 DWORD dwDefaultDataSize)
131{
132 FIXME("%s stub\n",pszValue);
133 return 1;
134}
135
136/*************************************************************************
137 * SHRegQueryUSValueA [SHLWAPI]
138 */
139LONG WINAPI SHRegQueryUSValueW(
140 HKEY hUSKey, /* [in] FIXME: HUSKEY */
141 LPCSTR pszValue,
142 LPDWORD pdwType,
143 void *pvData,
144 LPDWORD pcbData,
145 BOOL fIgnoreHKCU,
146 void *pvDefaultData,
147 DWORD dwDefaultDataSize)
148{
149 FIXME("%s stub\n",pszValue);
150 return 1;
151}
152
153/*************************************************************************
154 * SHRegGetPathA [SHLWAPI.@]
155 */
156DWORD WINAPI SHRegGetPathA(
157 HKEY hKey,
158 LPCSTR pcszSubKey,
159 LPCSTR pcszValue,
160 LPSTR pszPath,
161 DWORD dwFlags)
162{
163 FIXME("%s %s\n", pcszSubKey, pcszValue);
164 return 0;
165}
166
167/*************************************************************************
168 * SHRegGetPathW [SHLWAPI.@]
169 */
170DWORD WINAPI SHRegGetPathW(
171 HKEY hKey,
172 LPCWSTR pcszSubKey,
173 LPCWSTR pcszValue,
174 LPWSTR pszPath,
175 DWORD dwFlags)
176{
177 FIXME("%s %s\n", debugstr_w(pcszSubKey), debugstr_w(pcszValue));
178 return 0;
179}
180
181/*************************************************************************
182 * SHGetValueA [SHLWAPI.@]
183 *
184 * Gets a value from the registry
185 */
186DWORD WINAPI SHGetValueA(
187 HKEY hkey,
188 LPCSTR pSubKey,
189 LPCSTR pValue,
190 LPDWORD pwType,
191 LPVOID pvData,
192 LPDWORD pbData)
193{
194 HKEY hSubKey;
195 DWORD res;
196
197 TRACE("(%s %s)\n", pSubKey, pValue);
198
199 if((res = RegOpenKeyA(hkey, pSubKey, &hSubKey))) return res;
200 res = RegQueryValueExA(hSubKey, pValue, 0, pwType, pvData, pbData);
201 RegCloseKey( hSubKey );
202
203 return res;
204}
205
206/*************************************************************************
207 * SHGetValueW [SHLWAPI.@]
208 *
209 * Gets a value from the registry
210 */
211DWORD WINAPI SHGetValueW(
212 HKEY hkey,
213 LPCWSTR pSubKey,
214 LPCWSTR pValue,
215 LPDWORD pwType,
216 LPVOID pvData,
217 LPDWORD pbData)
218{
219 HKEY hSubKey;
220 DWORD res;
221
222 TRACE("(%s %s)\n", debugstr_w(pSubKey), debugstr_w(pValue));
223
224 if((res = RegOpenKeyW(hkey, pSubKey, &hSubKey))) return res;
225 res = RegQueryValueExW(hSubKey, pValue, 0, pwType, pvData, pbData);
226 RegCloseKey( hSubKey );
227
228 return res;
229}
230
231/*************************************************************************
232 * SHSetValueA [SHLWAPI.@]
233 */
234HRESULT WINAPI SHSetValueA(
235 HKEY hkey,
236 LPCSTR pszSubKey,
237 LPCSTR pszValue,
238 DWORD dwType,
239 LPCVOID pvData,
240 DWORD cbData)
241{
242 HKEY subkey;
243 HRESULT hres;
244
245 hres = RegCreateKeyA(hkey,pszSubKey,&subkey);
246 if (!hres)
247 return hres;
248 hres = RegSetValueExA(subkey,pszValue,0,dwType,pvData,cbData);
249 RegCloseKey(subkey);
250 return hres;
251}
252
253/*************************************************************************
254 * SHSetValueW [SHLWAPI.@]
255 */
256HRESULT WINAPI SHSetValueW(
257 HKEY hkey,
258 LPCWSTR pszSubKey,
259 LPCWSTR pszValue,
260 DWORD dwType,
261 LPCVOID pvData,
262 DWORD cbData)
263{
264 HKEY subkey;
265 HRESULT hres;
266
267 hres = RegCreateKeyW(hkey,pszSubKey,&subkey);
268 if (!hres)
269 return hres;
270 hres = RegSetValueExW(subkey,pszValue,0,dwType,pvData,cbData);
271 RegCloseKey(subkey);
272 return hres;
273}
274
275/*************************************************************************
276 * SHQueryValueExA [SHLWAPI.@]
277 *
278 */
279HRESULT WINAPI SHQueryValueExA(
280 HKEY hkey,
281 LPSTR lpValueName,
282 LPDWORD lpReserved,
283 LPDWORD lpType,
284 LPBYTE lpData,
285 LPDWORD lpcbData)
286{
287 TRACE("0x%04x %s %p %p %p %p\n", hkey, lpValueName, lpReserved, lpType, lpData, lpcbData);
288 return RegQueryValueExA (hkey, lpValueName, lpReserved, lpType, lpData, lpcbData);
289}
290
291
292/*************************************************************************
293 * SHQueryValueExW [SHLWAPI.@]
294 *
295 * FIXME
296 * if the datatype REG_EXPAND_SZ then expand the string and change
297 * *pdwType to REG_SZ.
298 */
299HRESULT WINAPI SHQueryValueExW (
300 HKEY hkey,
301 LPWSTR pszValue,
302 LPDWORD pdwReserved,
303 LPDWORD pdwType,
304 LPVOID pvData,
305 LPDWORD pcbData)
306{
307 WARN("0x%04x %s %p %p %p %p semi-stub\n",
308 hkey, debugstr_w(pszValue), pdwReserved, pdwType, pvData, pcbData);
309 return RegQueryValueExW ( hkey, pszValue, pdwReserved, pdwType, pvData, pcbData);
310}
311
312/*************************************************************************
313 * SHDeleteKeyA [SHLWAPI.@]
314 *
315 * It appears this function is made available to account for the differences
316 * between the Win9x and WinNT/2k RegDeleteKeyA functions.
317 *
318 * According to docs, Win9x RegDeleteKeyA will delete all subkeys, whereas
319 * WinNt/2k will only delete the key if empty.
320 */
321HRESULT WINAPI SHDeleteKeyA(
322 HKEY hKey,
323 LPCSTR lpszSubKey)
324{
325 DWORD r, dwKeyCount, dwSize, i, dwMaxSubkeyLen;
326 HKEY hSubKey;
327 LPSTR lpszName;
328
329 TRACE("hkey=0x%08x, %s\n", hKey, debugstr_a(lpszSubKey));
330
331 hSubKey = 0;
332 r = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
333 if(r != ERROR_SUCCESS)
334 return r;
335
336 /* find how many subkeys there are */
337 dwKeyCount = 0;
338 dwMaxSubkeyLen = 0;
339 r = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, &dwKeyCount,
340 &dwMaxSubkeyLen, NULL, NULL, NULL, NULL, NULL, NULL);
341 if(r != ERROR_SUCCESS)
342 {
343 RegCloseKey(hSubKey);
344 return r;
345 }
346
347 /* alloc memory for the longest string terminating 0 */
348 dwMaxSubkeyLen++;
349 lpszName = HeapAlloc(GetProcessHeap(), 0, dwMaxSubkeyLen*sizeof(CHAR));
350 if(!lpszName)
351 {
352 RegCloseKey(hSubKey);
353 return ERROR_NOT_ENOUGH_MEMORY;
354 }
355
356 /* recursively delete all the subkeys */
357 for(i=0; i<dwKeyCount; i++)
358 {
359 dwSize = dwMaxSubkeyLen;
360 r = RegEnumKeyExA(hSubKey, i, lpszName, &dwSize, NULL, NULL, NULL, NULL);
361 if(r != ERROR_SUCCESS)
362 break;
363 r = SHDeleteKeyA(hSubKey, lpszName);
364 if(r != ERROR_SUCCESS)
365 break;
366 }
367
368 HeapFree(GetProcessHeap(), 0, lpszName);
369
370 RegCloseKey(hSubKey);
371
372 if(r == ERROR_SUCCESS)
373 r = RegDeleteKeyA(hKey, lpszSubKey);
374
375 return r;
376}
377
378/*************************************************************************
379 * SHDeleteKeyW [SHLWAPI.@]
380 *
381 * It appears this function is made available to account for the differences
382 * between the Win9x and WinNT/2k RegDeleteKeyA functions.
383 *
384 * According to docs, Win9x RegDeleteKeyA will delete all subkeys, whereas
385 * WinNt/2k will only delete the key if empty.
386 */
387HRESULT WINAPI SHDeleteKeyW(
388 HKEY hkey,
389 LPCWSTR pszSubKey)
390{
391 FIXME("hkey=0x%08x, %s\n", hkey, debugstr_w(pszSubKey));
392 return 0;
393}
394
395/*************************************************************************
396 * SHDeleteValueA [SHLWAPI.@]
397 *
398 * Function opens the key, get/set/delete the value, then close the key.
399 */
400HRESULT WINAPI SHDeleteValueA(HKEY hkey, LPCSTR pszSubKey, LPCSTR pszValue) {
401 HKEY subkey;
402 HRESULT hres;
403
404 hres = RegOpenKeyA(hkey,pszSubKey,&subkey);
405 if (hres)
406 return hres;
407 hres = RegDeleteValueA(subkey,pszValue);
408 RegCloseKey(subkey);
409 return hres;
410}
411
412/*************************************************************************
413 * SHDeleteValueW [SHLWAPI.@]
414 *
415 * Function opens the key, get/set/delete the value, then close the key.
416 */
417HRESULT WINAPI SHDeleteValueW(HKEY hkey, LPCWSTR pszSubKey, LPCWSTR pszValue) {
418 HKEY subkey;
419 HRESULT hres;
420
421 hres = RegOpenKeyW(hkey,pszSubKey,&subkey);
422 if (hres)
423 return hres;
424 hres = RegDeleteValueW(subkey,pszValue);
425 RegCloseKey(subkey);
426 return hres;
427}
428
429/*************************************************************************
430 * SHDeleteEmptyKeyA [SHLWAPI.@]
431 *
432 * It appears this function is made available to account for the differences
433 * between the Win9x and WinNT/2k RegDeleteKeyA functions.
434 *
435 * According to docs, Win9x RegDeleteKeyA will delete all subkeys, whereas
436 * WinNt/2k will only delete the key if empty.
437 */
438DWORD WINAPI SHDeleteEmptyKeyA(HKEY hKey, LPCSTR lpszSubKey)
439{
440 DWORD r, dwKeyCount;
441 HKEY hSubKey;
442
443 TRACE("hkey=0x%08x, %s\n", hKey, debugstr_a(lpszSubKey));
444
445 hSubKey = 0;
446 r = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
447 if(r != ERROR_SUCCESS)
448 return r;
449
450 dwKeyCount = 0;
451 r = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, &dwKeyCount,
452 NULL, NULL, NULL, NULL, NULL, NULL, NULL);
453 if(r != ERROR_SUCCESS)
454 return r;
455
456 RegCloseKey(hSubKey);
457
458 if(dwKeyCount)
459 return ERROR_KEY_HAS_CHILDREN;
460
461 r = RegDeleteKeyA(hKey, lpszSubKey);
462
463 return r;
464}
465
466/*************************************************************************
467 * SHDeleteEmptyKeyW [SHLWAPI.@]
468 *
469 * It appears this function is made available to account for the differences
470 * between the Win9x and WinNT/2k RegDeleteKeyA functions.
471 *
472 * According to docs, Win9x RegDeleteKeyA will delete all subkeys, whereas
473 * WinNt/2k will only delete the key if empty.
474 */
475DWORD WINAPI SHDeleteEmptyKeyW(HKEY hKey, LPCWSTR lpszSubKey)
476{
477 FIXME("hkey=0x%08x, %s\n", hKey, debugstr_w(lpszSubKey));
478 return 0;
479}
480
481/*************************************************************************
482 * SHLWAPI_205 [SHLWAPI.205]
483 *
484 * Wrapper for SHGetValueA in case machine is in safe mode.
485 */
486DWORD WINAPI SHLWAPI_205(HKEY hkey, LPCSTR pSubKey, LPCSTR pValue,
487 LPDWORD pwType, LPVOID pvData, LPDWORD pbData)
488{
489 if (GetSystemMetrics(SM_CLEANBOOT))
490 return ERROR_INVALID_FUNCTION;
491 return SHGetValueA(hkey, pSubKey, pValue, pwType, pvData, pbData);
492}
493
494/*************************************************************************
495 * SHLWAPI_206 [SHLWAPI.206]
496 *
497 * Unicode version of SHLWAPI_205.
498 */
499DWORD WINAPI SHLWAPI_206(HKEY hkey, LPCWSTR pSubKey, LPCWSTR pValue,
500 LPDWORD pwType, LPVOID pvData, LPDWORD pbData)
501{
502 if (GetSystemMetrics(SM_CLEANBOOT))
503 return ERROR_INVALID_FUNCTION;
504 return SHGetValueW(hkey, pSubKey, pValue, pwType, pvData, pbData);
505}
506
507/*************************************************************************
508 * SHLWAPI_320 [SHLWAPI.320]
509 *
510 */
511BOOL WINAPI SHLWAPI_320(LPCSTR lpszSubKey, LPCSTR lpszValue)
512{
513 DWORD dwLen = strlen(lpszValue);
514 HRESULT ret = SHSetValueA(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeA,
515 REG_SZ, lpszValue, dwLen);
516 return ret ? FALSE : TRUE;
517}
518
519/*************************************************************************
520 * SHLWAPI_321 [SHLWAPI.321]
521 *
522 * Unicode version of SHLWAPI_320.
523 */
524BOOL WINAPI SHLWAPI_321(LPCWSTR lpszSubKey, LPCWSTR lpszValue)
525{
526 DWORD dwLen = strlenW(lpszValue);
527 HRESULT ret = SHSetValueW(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeW,
528 REG_SZ, lpszValue, dwLen);
529 return ret ? FALSE : TRUE;
530}
531
532/*************************************************************************
533 * SHLWAPI_322 [SHLWAPI.322]
534 *
535 */
536BOOL WINAPI SHLWAPI_322(LPCSTR lpszSubKey)
537{
538 HRESULT ret = SHDeleteValueA(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeA);
539 return ret ? FALSE : TRUE;
540}
541
542/*************************************************************************
543 * SHLWAPI_323 [SHLWAPI.323]
544 *
545 * Unicode version of SHLWAPI_322.
546 */
547BOOL WINAPI SHLWAPI_323(LPCWSTR lpszSubKey)
548{
549 HRESULT ret = SHDeleteValueW(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeW);
550 return ret ? FALSE : TRUE;
551}
552
Note: See TracBrowser for help on using the repository browser.