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

Last change on this file since 7611 was 7508, checked in by sandervl, 24 years ago

removed TRACE/WARN macro redefinition

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