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

Last change on this file since 7029 was 6712, checked in by sandervl, 24 years ago

restored old version

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