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

Last change on this file since 6666 was 6650, checked in by bird, 24 years ago

Added $Id:$ keyword.

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