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

Last change on this file since 6502 was 5753, checked in by sandervl, 24 years ago

added/implemented functions

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