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

Last change on this file since 7504 was 7502, checked in by phaller, 24 years ago

Fixed out-of-scope FIXME,TRACE,WARN macros

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