2 * SHLWAPI registry functions
4 * Copyright 1998 Juergen Schmied
5 * Copyright 2001 Guy Albertelli
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/debug.h"
29 #define NO_SHLWAPI_STREAM
31 #include "wine/unicode.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
35 /* Key/Value names for MIME content types */
36 static const char lpszContentTypeA
[] = "Content Type";
37 static const WCHAR lpszContentTypeW
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
39 static const char szMimeDbContentA
[] = "MIME\\Database\\Content Type\\";
40 static const WCHAR szMimeDbContentW
[] = { 'M', 'I', 'M','E','\\',
41 'D','a','t','a','b','a','s','e','\\','C','o','n','t','e','n','t',
42 ' ','T','y','p','e','\\', 0 };
43 static const DWORD dwLenMimeDbContent
= 27; /* strlen of szMimeDbContentA/W */
45 static const char szExtensionA
[] = "Extension";
46 static const WCHAR szExtensionW
[] = { 'E', 'x', 't','e','n','s','i','o','n','\0' };
48 /* internal structure of what the HUSKEY points to */
50 HKEY HKCUstart
; /* Start key in CU hive */
51 HKEY HKCUkey
; /* Opened key in CU hive */
52 HKEY HKLMstart
; /* Start key in LM hive */
53 HKEY HKLMkey
; /* Opened key in LM hive */
54 WCHAR lpszPath
[MAX_PATH
];
55 } SHUSKEY
, *LPSHUSKEY
;
57 DWORD WINAPI
SHStringFromGUIDW(REFGUID
,LPWSTR
,INT
);
58 HRESULT WINAPI
SHRegGetCLSIDKeyW(REFGUID
,LPCWSTR
,BOOL
,BOOL
,PHKEY
);
62 #define REG_HKLM FALSE
63 /*************************************************************************
64 * REG_GetHKEYFromHUSKEY
66 * Function: Return the proper registry key from the HUSKEY structure
67 * also allow special predefined values.
69 static HKEY WINAPI
REG_GetHKEYFromHUSKEY(HUSKEY hUSKey
, BOOL which
)
71 HKEY test
= (HKEY
) hUSKey
;
72 LPSHUSKEY mihk
= (LPSHUSKEY
) hUSKey
;
74 if ((test
== HKEY_CLASSES_ROOT
) ||
75 (test
== HKEY_CURRENT_CONFIG
) ||
76 (test
== HKEY_CURRENT_USER
) ||
77 (test
== HKEY_DYN_DATA
) ||
78 (test
== HKEY_LOCAL_MACHINE
) ||
79 (test
== HKEY_PERFORMANCE_DATA
) ||
80 /* FIXME: need to define for Win2k, ME, XP
81 * (test == HKEY_PERFORMANCE_TEXT) ||
82 * (test == HKEY_PERFORMANCE_NLSTEXT) ||
84 (test
== HKEY_USERS
)) return test
;
85 if (which
== REG_HKCU
) return mihk
->HKCUkey
;
90 /*************************************************************************
91 * SHRegOpenUSKeyA [SHLWAPI.@]
93 * Open a user-specific registry key.
96 * Path [I] Key name to open
97 * AccessType [I] Access type
98 * hRelativeUSKey [I] Relative user key
99 * phNewUSKey [O] Destination for created key
100 * fIgnoreHKCU [I] TRUE=Don't check HKEY_CURRENT_USER
103 * Success: ERROR_SUCCESS
104 * Failure: An error code from RegOpenKeyExA().
106 LONG WINAPI
SHRegOpenUSKeyA(LPCSTR Path
, REGSAM AccessType
, HUSKEY hRelativeUSKey
,
107 PHUSKEY phNewUSKey
, BOOL fIgnoreHKCU
)
109 WCHAR szPath
[MAX_PATH
];
112 MultiByteToWideChar(CP_ACP
, 0, Path
, -1, szPath
, MAX_PATH
);
114 return SHRegOpenUSKeyW(Path
? szPath
: NULL
, AccessType
, hRelativeUSKey
,
115 phNewUSKey
, fIgnoreHKCU
);
118 /*************************************************************************
119 * SHRegOpenUSKeyW [SHLWAPI.@]
121 * See SHRegOpenUSKeyA.
123 LONG WINAPI
SHRegOpenUSKeyW(LPCWSTR Path
, REGSAM AccessType
, HUSKEY hRelativeUSKey
,
124 PHUSKEY phNewUSKey
, BOOL fIgnoreHKCU
)
126 LONG ret2
, ret1
= ~ERROR_SUCCESS
;
129 TRACE("(%s,0x%x,%p,%p,%d)\n", debugstr_w(Path
),(LONG
)AccessType
,
130 hRelativeUSKey
, phNewUSKey
, fIgnoreHKCU
);
135 /* Create internal HUSKEY */
136 hKey
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*hKey
));
137 lstrcpynW(hKey
->lpszPath
, Path
, sizeof(hKey
->lpszPath
)/sizeof(WCHAR
));
141 hKey
->HKCUstart
= SHRegDuplicateHKey(REG_GetHKEYFromHUSKEY(hRelativeUSKey
, REG_HKCU
));
142 hKey
->HKLMstart
= SHRegDuplicateHKey(REG_GetHKEYFromHUSKEY(hRelativeUSKey
, REG_HKLM
));
144 /* FIXME: if either of these keys is NULL, create the start key from
145 * the relative keys start+path
150 hKey
->HKCUstart
= HKEY_CURRENT_USER
;
151 hKey
->HKLMstart
= HKEY_LOCAL_MACHINE
;
156 ret1
= RegOpenKeyExW(hKey
->HKCUstart
, hKey
->lpszPath
, 0, AccessType
, &hKey
->HKCUkey
);
161 ret2
= RegOpenKeyExW(hKey
->HKLMstart
, hKey
->lpszPath
, 0, AccessType
, &hKey
->HKLMkey
);
166 TRACE("one or more opens failed: HKCU=%d HKLM=%d\n", ret1
, ret2
);
170 /* Neither open succeeded: fail */
171 SHRegCloseUSKey(hKey
);
175 TRACE("HUSKEY=%p\n", hKey
);
177 *phNewUSKey
= (HUSKEY
)hKey
;
178 return ERROR_SUCCESS
;
181 /*************************************************************************
182 * SHRegCloseUSKey [SHLWAPI.@]
184 * Close a user-specific registry key
187 * Success: ERROR_SUCCESS
188 * Failure: An error code from RegCloseKey().
190 LONG WINAPI
SHRegCloseUSKey(
191 HUSKEY hUSKey
) /* [I] Key to close */
193 LPSHUSKEY hKey
= (LPSHUSKEY
)hUSKey
;
194 LONG ret
= ERROR_SUCCESS
;
197 ret
= RegCloseKey(hKey
->HKCUkey
);
198 if (hKey
->HKCUstart
&& hKey
->HKCUstart
!= HKEY_CURRENT_USER
)
199 ret
= RegCloseKey(hKey
->HKCUstart
);
201 ret
= RegCloseKey(hKey
->HKLMkey
);
202 if (hKey
->HKLMstart
&& hKey
->HKLMstart
!= HKEY_LOCAL_MACHINE
)
203 ret
= RegCloseKey(hKey
->HKCUstart
);
205 HeapFree(GetProcessHeap(), 0, hKey
);
209 /*************************************************************************
210 * SHRegCreateUSKeyA [SHLWAPI.@]
212 * Create or open a user-specific registry key.
215 * pszPath [I] Key name to create or open.
216 * samDesired [I] Wanted security access.
217 * hRelativeUSKey [I] Base path if pszPath is relative. NULL otherwise.
218 * phNewUSKey [O] Receives a handle to the new or openened key.
219 * dwFlags [I] Base key under which the key should be opened.
222 * Success: ERROR_SUCCESS
223 * Failure: Nonzero error code from winerror.h
225 LONG WINAPI
SHRegCreateUSKeyA(LPCSTR pszPath
, REGSAM samDesired
, HUSKEY hRelativeUSKey
,
226 PHUSKEY phNewUSKey
, DWORD dwFlags
)
228 FIXME("(%s, 0x%08x, %p, %p, 0x%08x) stub\n", debugstr_a(pszPath
), samDesired
,
229 hRelativeUSKey
, phNewUSKey
, dwFlags
);
230 return ERROR_SUCCESS
;
233 /*************************************************************************
234 * SHRegCreateUSKeyW [SHLWAPI.@]
236 * See SHRegCreateUSKeyA.
238 LONG WINAPI
SHRegCreateUSKeyW(LPCWSTR pszPath
, REGSAM samDesired
, HUSKEY hRelativeUSKey
,
239 PHUSKEY phNewUSKey
, DWORD dwFlags
)
241 FIXME("(%s, 0x%08x, %p, %p, 0x%08x) stub\n", debugstr_w(pszPath
), samDesired
,
242 hRelativeUSKey
, phNewUSKey
, dwFlags
);
243 return ERROR_SUCCESS
;
246 /*************************************************************************
247 * SHRegDeleteEmptyUSKeyA [SHLWAPI.@]
249 * Delete an empty user-specific registry key.
252 * hUSKey [I] Handle to an open registry key.
253 * pszValue [I] Empty key name.
254 * delRegFlags [I] Flag that specifies the base from which to delete
258 * Success: ERROR_SUCCESS
259 * Failure: Nonzero error code from winerror.h
261 LONG WINAPI
SHRegDeleteEmptyUSKeyA(HUSKEY hUSKey
, LPCSTR pszValue
, SHREGDEL_FLAGS delRegFlags
)
263 FIXME("(%p, %s, 0x%08x) stub\n", hUSKey
, debugstr_a(pszValue
), delRegFlags
);
264 return ERROR_SUCCESS
;
267 /*************************************************************************
268 * SHRegDeleteEmptyUSKeyW [SHLWAPI.@]
270 * See SHRegDeleteEmptyUSKeyA.
272 LONG WINAPI
SHRegDeleteEmptyUSKeyW(HUSKEY hUSKey
, LPCWSTR pszValue
, SHREGDEL_FLAGS delRegFlags
)
274 FIXME("(%p, %s, 0x%08x) stub\n", hUSKey
, debugstr_w(pszValue
), delRegFlags
);
275 return ERROR_SUCCESS
;
278 /*************************************************************************
279 * SHRegDeleteUSValueA [SHLWAPI.@]
281 * Delete a user-specific registry value.
284 * hUSKey [I] Handle to an open registry key.
285 * pszValue [I] Specifies the value to delete.
286 * delRegFlags [I] Flag that specifies the base of the key from which to
290 * Success: ERROR_SUCCESS
291 * Failure: Nonzero error code from winerror.h
293 LONG WINAPI
SHRegDeleteUSValueA(HUSKEY hUSKey
, LPCSTR pszValue
, SHREGDEL_FLAGS delRegFlags
)
295 FIXME("(%p, %s, 0x%08x) stub\n", hUSKey
, debugstr_a(pszValue
), delRegFlags
);
296 return ERROR_SUCCESS
;
299 /*************************************************************************
300 * SHRegDeleteUSValueW [SHLWAPI.@]
302 * See SHRegDeleteUSValueA.
304 LONG WINAPI
SHRegDeleteUSValueW(HUSKEY hUSKey
, LPCWSTR pszValue
, SHREGDEL_FLAGS delRegFlags
)
306 FIXME("(%p, %s, 0x%08x) stub\n", hUSKey
, debugstr_w(pszValue
), delRegFlags
);
307 return ERROR_SUCCESS
;
310 /*************************************************************************
311 * SHRegEnumUSValueA [SHLWAPI.@]
313 * Enumerate values of a specified registry key.
316 * hUSKey [I] Handle to an open registry key.
317 * dwIndex [I] Index of the value to be retrieved.
318 * pszValueName [O] Buffer to receive the value name.
319 * pcchValueNameLen [I] Size of pszValueName in characters.
320 * pdwType [O] Receives data type of the value.
321 * pvData [O] Receives value data. May be NULL.
322 * pcbData [I/O] Size of pvData in bytes.
323 * enumRegFlags [I] Flag that specifies the base key under which to
327 * Success: ERROR_SUCCESS
328 * Failure: Nonzero error code from winerror.h
330 LONG WINAPI
SHRegEnumUSValueA(HUSKEY hUSKey
, DWORD dwIndex
, LPSTR pszValueName
,
331 LPDWORD pcchValueNameLen
, LPDWORD pdwType
, LPVOID pvData
,
332 LPDWORD pcbData
, SHREGENUM_FLAGS enumRegFlags
)
334 FIXME("(%p, 0x%08x, %s, %p, %p, %p, %p, 0x%08x) stub\n", hUSKey
, dwIndex
,
335 debugstr_a(pszValueName
), pcchValueNameLen
, pdwType
, pvData
, pcbData
, enumRegFlags
);
336 return ERROR_INVALID_FUNCTION
;
339 /*************************************************************************
340 * SHRegEnumUSValueW [SHLWAPI.@]
342 * See SHRegEnumUSValueA.
344 LONG WINAPI
SHRegEnumUSValueW(HUSKEY hUSKey
, DWORD dwIndex
, LPWSTR pszValueName
,
345 LPDWORD pcchValueNameLen
, LPDWORD pdwType
, LPVOID pvData
,
346 LPDWORD pcbData
, SHREGENUM_FLAGS enumRegFlags
)
348 FIXME("(%p, 0x%08x, %s, %p, %p, %p, %p, 0x%08x) stub\n", hUSKey
, dwIndex
,
349 debugstr_w(pszValueName
), pcchValueNameLen
, pdwType
, pvData
, pcbData
, enumRegFlags
);
350 return ERROR_INVALID_FUNCTION
;
353 /*************************************************************************
354 * SHRegQueryUSValueA [SHLWAPI.@]
356 * Query a user-specific registry value.
359 * Success: ERROR_SUCCESS
360 * Failure: An error code from RegQueryValueExA().
362 LONG WINAPI
SHRegQueryUSValueA(
363 HUSKEY hUSKey
, /* [I] Key to query */
364 LPCSTR pszValue
, /* [I] Value name under hUSKey */
365 LPDWORD pdwType
, /* [O] Destination for value type */
366 LPVOID pvData
, /* [O] Destination for value data */
367 LPDWORD pcbData
, /* [O] Destination for value length */
368 BOOL fIgnoreHKCU
, /* [I] TRUE=Don't check HKEY_CURRENT_USER */
369 LPVOID pvDefaultData
, /* [I] Default data if pszValue does not exist */
370 DWORD dwDefaultDataSize
) /* [I] Length of pvDefaultData */
372 LONG ret
= ~ERROR_SUCCESS
;
377 /* if user wants HKCU, and it exists, then try it */
378 if (!fIgnoreHKCU
&& (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKCU
))) {
379 ret
= RegQueryValueExA(dokey
,
380 pszValue
, 0, pdwType
, pvData
, pcbData
);
381 TRACE("HKCU RegQueryValue returned %08x\n", ret
);
384 /* if HKCU did not work and HKLM exists, then try it */
385 if ((ret
!= ERROR_SUCCESS
) &&
386 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKLM
))) {
387 ret
= RegQueryValueExA(dokey
,
388 pszValue
, 0, pdwType
, pvData
, pcbData
);
389 TRACE("HKLM RegQueryValue returned %08x\n", ret
);
392 /* if neither worked, and default data exists, then use it */
393 if (ret
!= ERROR_SUCCESS
) {
394 if (pvDefaultData
&& (dwDefaultDataSize
!= 0)) {
395 maxmove
= (dwDefaultDataSize
>= *pcbData
) ? *pcbData
: dwDefaultDataSize
;
396 src
= (CHAR
*)pvDefaultData
;
398 for(i
=0; i
<maxmove
; i
++) *dst
++ = *src
++;
400 TRACE("setting default data\n");
408 /*************************************************************************
409 * SHRegQueryUSValueW [SHLWAPI.@]
411 * See SHRegQueryUSValueA.
413 LONG WINAPI
SHRegQueryUSValueW(
420 LPVOID pvDefaultData
,
421 DWORD dwDefaultDataSize
)
423 LONG ret
= ~ERROR_SUCCESS
;
428 /* if user wants HKCU, and it exists, then try it */
429 if (!fIgnoreHKCU
&& (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKCU
))) {
430 ret
= RegQueryValueExW(dokey
,
431 pszValue
, 0, pdwType
, pvData
, pcbData
);
432 TRACE("HKCU RegQueryValue returned %08x\n", ret
);
435 /* if HKCU did not work and HKLM exists, then try it */
436 if ((ret
!= ERROR_SUCCESS
) &&
437 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKLM
))) {
438 ret
= RegQueryValueExW(dokey
,
439 pszValue
, 0, pdwType
, pvData
, pcbData
);
440 TRACE("HKLM RegQueryValue returned %08x\n", ret
);
443 /* if neither worked, and default data exists, then use it */
444 if (ret
!= ERROR_SUCCESS
) {
445 if (pvDefaultData
&& (dwDefaultDataSize
!= 0)) {
446 maxmove
= (dwDefaultDataSize
>= *pcbData
) ? *pcbData
: dwDefaultDataSize
;
447 src
= (CHAR
*)pvDefaultData
;
449 for(i
=0; i
<maxmove
; i
++) *dst
++ = *src
++;
451 TRACE("setting default data\n");
458 /*************************************************************************
459 * SHRegGetUSValueA [SHLWAPI.@]
461 * Get a user-specific registry value.
464 * Success: ERROR_SUCCESS
465 * Failure: An error code from SHRegOpenUSKeyA() or SHRegQueryUSValueA().
468 * This function opens pSubKey, queries the value, and then closes the key.
470 LONG WINAPI
SHRegGetUSValueA(
471 LPCSTR pSubKey
, /* [I] Key name to open */
472 LPCSTR pValue
, /* [I] Value name to open */
473 LPDWORD pwType
, /* [O] Destination for the type of the value */
474 LPVOID pvData
, /* [O] Destination for the value */
475 LPDWORD pcbData
, /* [I] Destination for the length of the value **/
476 BOOL flagIgnoreHKCU
, /* [I] TRUE=Don't check HKEY_CURRENT_USER */
477 LPVOID pDefaultData
, /* [I] Default value if it doesn't exist */
478 DWORD wDefaultDataSize
) /* [I] Length of pDefaultData */
483 if (!pvData
|| !pcbData
) return ERROR_INVALID_FUNCTION
; /* FIXME:wrong*/
484 TRACE("key '%s', value '%s', datalen %d, %s\n",
485 debugstr_a(pSubKey
), debugstr_a(pValue
), *pcbData
,
486 (flagIgnoreHKCU
) ? "Ignoring HKCU" : "Tries HKCU then HKLM");
488 ret
= SHRegOpenUSKeyA(pSubKey
, 0x1, 0, &myhuskey
, flagIgnoreHKCU
);
489 if (ret
== ERROR_SUCCESS
) {
490 ret
= SHRegQueryUSValueA(myhuskey
, pValue
, pwType
, pvData
,
491 pcbData
, flagIgnoreHKCU
, pDefaultData
,
493 SHRegCloseUSKey(myhuskey
);
498 /*************************************************************************
499 * SHRegGetUSValueW [SHLWAPI.@]
501 * See SHRegGetUSValueA.
503 LONG WINAPI
SHRegGetUSValueW(
511 DWORD wDefaultDataSize
)
516 if (!pvData
|| !pcbData
) return ERROR_INVALID_FUNCTION
; /* FIXME:wrong*/
517 TRACE("key '%s', value '%s', datalen %d, %s\n",
518 debugstr_w(pSubKey
), debugstr_w(pValue
), *pcbData
,
519 (flagIgnoreHKCU
) ? "Ignoring HKCU" : "Tries HKCU then HKLM");
521 ret
= SHRegOpenUSKeyW(pSubKey
, 0x1, 0, &myhuskey
, flagIgnoreHKCU
);
522 if (ret
== ERROR_SUCCESS
) {
523 ret
= SHRegQueryUSValueW(myhuskey
, pValue
, pwType
, pvData
,
524 pcbData
, flagIgnoreHKCU
, pDefaultData
,
526 SHRegCloseUSKey(myhuskey
);
531 /*************************************************************************
532 * SHRegSetUSValueA [SHLWAPI.@]
534 * Set a user-specific registry value.
537 * pszSubKey [I] Name of key to set the value in
538 * pszValue [I] Name of value under pszSubKey to set the value in
539 * dwType [I] Type of the value
540 * pvData [I] Data to set as the value
541 * cbData [I] length of pvData
542 * dwFlags [I] SHREGSET_ flags from "shlwapi.h"
545 * Success: ERROR_SUCCESS
546 * Failure: An error code from SHRegOpenUSKeyA() or SHRegWriteUSValueA(), or
547 * ERROR_INVALID_FUNCTION if pvData is NULL.
550 * This function opens pszSubKey, sets the value, and then closes the key.
552 LONG WINAPI
SHRegSetUSValueA(LPCSTR pszSubKey
, LPCSTR pszValue
, DWORD dwType
,
553 LPVOID pvData
, DWORD cbData
, DWORD dwFlags
)
555 BOOL ignoreHKCU
= TRUE
;
559 TRACE("(%s,%s,%d,%p,%d,0x%08x\n", debugstr_a(pszSubKey
), debugstr_a(pszValue
),
560 dwType
, pvData
, cbData
, dwFlags
);
563 return ERROR_INVALID_FUNCTION
;
565 if (dwFlags
& SHREGSET_HKCU
|| dwFlags
& SHREGSET_FORCE_HKCU
)
568 ret
= SHRegOpenUSKeyA(pszSubKey
, KEY_ALL_ACCESS
, 0, &hkey
, ignoreHKCU
);
569 if (ret
== ERROR_SUCCESS
)
571 ret
= SHRegWriteUSValueA(hkey
, pszValue
, dwType
, pvData
, cbData
, dwFlags
);
572 SHRegCloseUSKey(hkey
);
577 /*************************************************************************
578 * SHRegSetUSValueW [SHLWAPI.@]
580 * See SHRegSetUSValueA.
582 LONG WINAPI
SHRegSetUSValueW(LPCWSTR pszSubKey
, LPCWSTR pszValue
, DWORD dwType
,
583 LPVOID pvData
, DWORD cbData
, DWORD dwFlags
)
585 BOOL ignoreHKCU
= TRUE
;
589 TRACE("(%s,%s,%d,%p,%d,0x%08x\n", debugstr_w(pszSubKey
), debugstr_w(pszValue
),
590 dwType
, pvData
, cbData
, dwFlags
);
593 return ERROR_INVALID_FUNCTION
;
595 if (dwFlags
& SHREGSET_HKCU
|| dwFlags
& SHREGSET_FORCE_HKCU
)
598 ret
= SHRegOpenUSKeyW(pszSubKey
, KEY_ALL_ACCESS
, 0, &hkey
, ignoreHKCU
);
599 if (ret
== ERROR_SUCCESS
)
601 ret
= SHRegWriteUSValueW(hkey
, pszValue
, dwType
, pvData
, cbData
, dwFlags
);
602 SHRegCloseUSKey(hkey
);
607 /*************************************************************************
608 * SHRegGetBoolUSValueA [SHLWAPI.@]
610 * Get a user-specific registry boolean value.
613 * Success: ERROR_SUCCESS
614 * Failure: An error code from SHRegOpenUSKeyA() or SHRegQueryUSValueA().
617 * This function opens pszSubKey, queries the value, and then closes the key.
619 * Boolean values are one of the following:
620 * True: YES,TRUE,non-zero
623 BOOL WINAPI
SHRegGetBoolUSValueA(
624 LPCSTR pszSubKey
, /* [I] Key name to open */
625 LPCSTR pszValue
, /* [I] Value name to open */
626 BOOL fIgnoreHKCU
, /* [I] TRUE=Don't check HKEY_CURRENT_USER */
627 BOOL fDefault
) /* [I] Default value to use if pszValue is not present */
630 DWORD type
, datalen
, work
;
634 TRACE("key '%s', value '%s', %s\n",
635 debugstr_a(pszSubKey
), debugstr_a(pszValue
),
636 (fIgnoreHKCU
) ? "Ignoring HKCU" : "Tries HKCU then HKLM");
638 datalen
= sizeof(data
)-1;
639 if (!(retvalue
= SHRegGetUSValueA( pszSubKey
, pszValue
, &type
,
641 fIgnoreHKCU
, 0, 0))) {
642 /* process returned data via type into bool */
645 data
[9] = '\0'; /* set end of string */
646 if (lstrcmpiA(data
, "YES") == 0) ret
= TRUE
;
647 if (lstrcmpiA(data
, "TRUE") == 0) ret
= TRUE
;
648 if (lstrcmpiA(data
, "NO") == 0) ret
= FALSE
;
649 if (lstrcmpiA(data
, "FALSE") == 0) ret
= FALSE
;
652 work
= *(LPDWORD
)data
;
657 ret
= (data
[0] != '\0');
661 FIXME("Unsupported registry data type %d\n", type
);
664 TRACE("got value (type=%d), returning <%s>\n", type
,
665 (ret
) ? "TRUE" : "FALSE");
669 TRACE("returning default data <%s>\n",
670 (ret
) ? "TRUE" : "FALSE");
675 /*************************************************************************
676 * SHRegGetBoolUSValueW [SHLWAPI.@]
678 * See SHRegGetBoolUSValueA.
680 BOOL WINAPI
SHRegGetBoolUSValueW(
686 static const WCHAR wYES
[]= {'Y','E','S','\0'};
687 static const WCHAR wTRUE
[]= {'T','R','U','E','\0'};
688 static const WCHAR wNO
[]= {'N','O','\0'};
689 static const WCHAR wFALSE
[]={'F','A','L','S','E','\0'};
691 DWORD type
, datalen
, work
;
695 TRACE("key '%s', value '%s', %s\n",
696 debugstr_w(pszSubKey
), debugstr_w(pszValue
),
697 (fIgnoreHKCU
) ? "Ignoring HKCU" : "Tries HKCU then HKLM");
699 datalen
= (sizeof(data
)-1) * sizeof(WCHAR
);
700 if (!(retvalue
= SHRegGetUSValueW( pszSubKey
, pszValue
, &type
,
702 fIgnoreHKCU
, 0, 0))) {
703 /* process returned data via type into bool */
706 data
[9] = L
'\0'; /* set end of string */
707 if (lstrcmpiW(data
, wYES
)==0 || lstrcmpiW(data
, wTRUE
)==0)
709 else if (lstrcmpiW(data
, wNO
)==0 || lstrcmpiW(data
, wFALSE
)==0)
713 work
= *(LPDWORD
)data
;
718 ret
= (data
[0] != L
'\0');
722 FIXME("Unsupported registry data type %d\n", type
);
725 TRACE("got value (type=%d), returning <%s>\n", type
,
726 (ret
) ? "TRUE" : "FALSE");
730 TRACE("returning default data <%s>\n",
731 (ret
) ? "TRUE" : "FALSE");
736 /*************************************************************************
737 * SHRegQueryInfoUSKeyA [SHLWAPI.@]
739 * Get information about a user-specific registry key.
742 * Success: ERROR_SUCCESS
743 * Failure: An error code from RegQueryInfoKeyA().
745 LONG WINAPI
SHRegQueryInfoUSKeyA(
746 HUSKEY hUSKey
, /* [I] Key to query */
747 LPDWORD pcSubKeys
, /* [O] Destination for number of sub keys */
748 LPDWORD pcchMaxSubKeyLen
, /* [O] Destination for the length of the biggest sub key name */
749 LPDWORD pcValues
, /* [O] Destination for number of values */
750 LPDWORD pcchMaxValueNameLen
,/* [O] Destination for the length of the biggest value */
751 SHREGENUM_FLAGS enumRegFlags
) /* [in] SHREGENUM_ flags from "shlwapi.h" */
756 TRACE("(%p,%p,%p,%p,%p,%d)\n",
757 hUSKey
,pcSubKeys
,pcchMaxSubKeyLen
,pcValues
,
758 pcchMaxValueNameLen
,enumRegFlags
);
760 /* if user wants HKCU, and it exists, then try it */
761 if (((enumRegFlags
== SHREGENUM_HKCU
) ||
762 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
763 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKCU
))) {
764 ret
= RegQueryInfoKeyA(dokey
, 0, 0, 0,
765 pcSubKeys
, pcchMaxSubKeyLen
, 0,
766 pcValues
, pcchMaxValueNameLen
, 0, 0, 0);
767 if ((ret
== ERROR_SUCCESS
) ||
768 (enumRegFlags
== SHREGENUM_HKCU
))
771 if (((enumRegFlags
== SHREGENUM_HKLM
) ||
772 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
773 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKLM
))) {
774 return RegQueryInfoKeyA(dokey
, 0, 0, 0,
775 pcSubKeys
, pcchMaxSubKeyLen
, 0,
776 pcValues
, pcchMaxValueNameLen
, 0, 0, 0);
778 return ERROR_INVALID_FUNCTION
;
781 /*************************************************************************
782 * SHRegQueryInfoUSKeyW [SHLWAPI.@]
784 * See SHRegQueryInfoUSKeyA.
786 LONG WINAPI
SHRegQueryInfoUSKeyW(
789 LPDWORD pcchMaxSubKeyLen
,
791 LPDWORD pcchMaxValueNameLen
,
792 SHREGENUM_FLAGS enumRegFlags
)
797 TRACE("(%p,%p,%p,%p,%p,%d)\n",
798 hUSKey
,pcSubKeys
,pcchMaxSubKeyLen
,pcValues
,
799 pcchMaxValueNameLen
,enumRegFlags
);
801 /* if user wants HKCU, and it exists, then try it */
802 if (((enumRegFlags
== SHREGENUM_HKCU
) ||
803 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
804 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKCU
))) {
805 ret
= RegQueryInfoKeyW(dokey
, 0, 0, 0,
806 pcSubKeys
, pcchMaxSubKeyLen
, 0,
807 pcValues
, pcchMaxValueNameLen
, 0, 0, 0);
808 if ((ret
== ERROR_SUCCESS
) ||
809 (enumRegFlags
== SHREGENUM_HKCU
))
812 if (((enumRegFlags
== SHREGENUM_HKLM
) ||
813 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
814 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKLM
))) {
815 return RegQueryInfoKeyW(dokey
, 0, 0, 0,
816 pcSubKeys
, pcchMaxSubKeyLen
, 0,
817 pcValues
, pcchMaxValueNameLen
, 0, 0, 0);
819 return ERROR_INVALID_FUNCTION
;
822 /*************************************************************************
823 * SHRegEnumUSKeyA [SHLWAPI.@]
825 * Enumerate a user-specific registry key.
828 * Success: ERROR_SUCCESS
829 * Failure: An error code from RegEnumKeyExA().
831 LONG WINAPI
SHRegEnumUSKeyA(
832 HUSKEY hUSKey
, /* [in] Key to enumerate */
833 DWORD dwIndex
, /* [in] Index within hUSKey */
834 LPSTR pszName
, /* [out] Name of the enumerated value */
835 LPDWORD pcchValueNameLen
, /* [in/out] Length of pszName */
836 SHREGENUM_FLAGS enumRegFlags
) /* [in] SHREGENUM_ flags from "shlwapi.h" */
840 TRACE("(%p,%d,%p,%p(%d),%d)\n",
841 hUSKey
, dwIndex
, pszName
, pcchValueNameLen
,
842 *pcchValueNameLen
, enumRegFlags
);
844 if (((enumRegFlags
== SHREGENUM_HKCU
) ||
845 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
846 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKCU
))) {
847 return RegEnumKeyExA(dokey
, dwIndex
, pszName
, pcchValueNameLen
,
851 if (((enumRegFlags
== SHREGENUM_HKLM
) ||
852 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
853 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKLM
))) {
854 return RegEnumKeyExA(dokey
, dwIndex
, pszName
, pcchValueNameLen
,
857 FIXME("no support for SHREGENUM_BOTH\n");
858 return ERROR_INVALID_FUNCTION
;
861 /*************************************************************************
862 * SHRegEnumUSKeyW [SHLWAPI.@]
864 * See SHRegEnumUSKeyA.
866 LONG WINAPI
SHRegEnumUSKeyW(
870 LPDWORD pcchValueNameLen
,
871 SHREGENUM_FLAGS enumRegFlags
)
875 TRACE("(%p,%d,%p,%p(%d),%d)\n",
876 hUSKey
, dwIndex
, pszName
, pcchValueNameLen
,
877 *pcchValueNameLen
, enumRegFlags
);
879 if (((enumRegFlags
== SHREGENUM_HKCU
) ||
880 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
881 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKCU
))) {
882 return RegEnumKeyExW(dokey
, dwIndex
, pszName
, pcchValueNameLen
,
886 if (((enumRegFlags
== SHREGENUM_HKLM
) ||
887 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
888 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKLM
))) {
889 return RegEnumKeyExW(dokey
, dwIndex
, pszName
, pcchValueNameLen
,
892 FIXME("no support for SHREGENUM_BOTH\n");
893 return ERROR_INVALID_FUNCTION
;
897 /*************************************************************************
898 * SHRegWriteUSValueA [SHLWAPI.@]
900 * Write a user-specific registry value.
903 * hUSKey [I] Key to write the value to
904 * pszValue [I] Name of value under hUSKey to write the value as
905 * dwType [I] Type of the value
906 * pvData [I] Data to set as the value
907 * cbData [I] length of pvData
908 * dwFlags [I] SHREGSET_ flags from "shlwapi.h"
911 * Success: ERROR_SUCCESS.
912 * Failure: ERROR_INVALID_PARAMETER, if any parameter is invalid, otherwise
913 * an error code from RegSetValueExA().
916 * dwFlags must have at least SHREGSET_FORCE_HKCU or SHREGSET_FORCE_HKLM set.
918 LONG WINAPI
SHRegWriteUSValueA(HUSKEY hUSKey
, LPCSTR pszValue
, DWORD dwType
,
919 LPVOID pvData
, DWORD cbData
, DWORD dwFlags
)
921 WCHAR szValue
[MAX_PATH
];
924 MultiByteToWideChar(CP_ACP
, 0, pszValue
, -1, szValue
, MAX_PATH
);
926 return SHRegWriteUSValueW(hUSKey
, pszValue
? szValue
: NULL
, dwType
,
927 pvData
, cbData
, dwFlags
);
930 /*************************************************************************
931 * SHRegWriteUSValueW [SHLWAPI.@]
933 * See SHRegWriteUSValueA.
935 LONG WINAPI
SHRegWriteUSValueW(HUSKEY hUSKey
, LPCWSTR pszValue
, DWORD dwType
,
936 LPVOID pvData
, DWORD cbData
, DWORD dwFlags
)
939 LPSHUSKEY hKey
= (LPSHUSKEY
)hUSKey
;
940 LONG ret
= ERROR_SUCCESS
;
942 TRACE("(%p,%s,%d,%p,%d,%d)\n", hUSKey
, debugstr_w(pszValue
),
943 dwType
, pvData
, cbData
, dwFlags
);
945 if (!hUSKey
|| IsBadWritePtr(hUSKey
, sizeof(SHUSKEY
)) ||
946 !(dwFlags
& (SHREGSET_FORCE_HKCU
|SHREGSET_FORCE_HKLM
)))
947 return ERROR_INVALID_PARAMETER
;
949 if (dwFlags
& (SHREGSET_FORCE_HKCU
|SHREGSET_HKCU
))
954 ret
= RegCreateKeyW(hKey
->HKCUstart
, hKey
->lpszPath
, &hKey
->HKCUkey
);
955 TRACE("Creating HKCU key, ret = %d\n", ret
);
956 if (ret
&& (dwFlags
& (SHREGSET_FORCE_HKCU
)))
965 if ((dwFlags
& SHREGSET_FORCE_HKCU
) ||
966 RegQueryValueExW(hKey
->HKCUkey
, pszValue
, NULL
, NULL
, NULL
, &dummy
))
968 /* Doesn't exist or we are forcing: Write value */
969 ret
= RegSetValueExW(hKey
->HKCUkey
, pszValue
, 0, dwType
, pvData
, cbData
);
970 TRACE("Writing HKCU value, ret = %d\n", ret
);
975 if (dwFlags
& (SHREGSET_FORCE_HKLM
|SHREGSET_HKLM
))
980 ret
= RegCreateKeyW(hKey
->HKLMstart
, hKey
->lpszPath
, &hKey
->HKLMkey
);
981 TRACE("Creating HKLM key, ret = %d\n", ret
);
982 if (ret
&& (dwFlags
& (SHREGSET_FORCE_HKLM
)))
991 if ((dwFlags
& SHREGSET_FORCE_HKLM
) ||
992 RegQueryValueExW(hKey
->HKLMkey
, pszValue
, NULL
, NULL
, NULL
, &dummy
))
994 /* Doesn't exist or we are forcing: Write value */
995 ret
= RegSetValueExW(hKey
->HKLMkey
, pszValue
, 0, dwType
, pvData
, cbData
);
996 TRACE("Writing HKLM value, ret = %d\n", ret
);
1004 /*************************************************************************
1005 * SHRegGetPathA [SHLWAPI.@]
1007 * Get a path from the registry.
1010 * hKey [I] Handle to registry key
1011 * lpszSubKey [I] Name of sub key containing path to get
1012 * lpszValue [I] Name of value containing path to get
1013 * lpszPath [O] Buffer for returned path
1014 * dwFlags [I] Reserved
1017 * Success: ERROR_SUCCESS. lpszPath contains the path.
1018 * Failure: An error code from RegOpenKeyExA() or SHQueryValueExA().
1020 DWORD WINAPI
SHRegGetPathA(HKEY hKey
, LPCSTR lpszSubKey
, LPCSTR lpszValue
,
1021 LPSTR lpszPath
, DWORD dwFlags
)
1023 DWORD dwSize
= MAX_PATH
;
1025 TRACE("(hkey=%p,%s,%s,%p,%d)\n", hKey
, debugstr_a(lpszSubKey
),
1026 debugstr_a(lpszValue
), lpszPath
, dwFlags
);
1028 return SHGetValueA(hKey
, lpszSubKey
, lpszValue
, 0, lpszPath
, &dwSize
);
1031 /*************************************************************************
1032 * SHRegGetPathW [SHLWAPI.@]
1034 * See SHRegGetPathA.
1036 DWORD WINAPI
SHRegGetPathW(HKEY hKey
, LPCWSTR lpszSubKey
, LPCWSTR lpszValue
,
1037 LPWSTR lpszPath
, DWORD dwFlags
)
1039 DWORD dwSize
= MAX_PATH
;
1041 TRACE("(hkey=%p,%s,%s,%p,%d)\n", hKey
, debugstr_w(lpszSubKey
),
1042 debugstr_w(lpszValue
), lpszPath
, dwFlags
);
1044 return SHGetValueW(hKey
, lpszSubKey
, lpszValue
, 0, lpszPath
, &dwSize
);
1048 /*************************************************************************
1049 * SHRegSetPathA [SHLWAPI.@]
1051 * Write a path to the registry.
1054 * hKey [I] Handle to registry key
1055 * lpszSubKey [I] Name of sub key containing path to set
1056 * lpszValue [I] Name of value containing path to set
1057 * lpszPath [O] Path to write
1058 * dwFlags [I] Reserved, must be 0.
1061 * Success: ERROR_SUCCESS.
1062 * Failure: An error code from SHSetValueA().
1064 DWORD WINAPI
SHRegSetPathA(HKEY hKey
, LPCSTR lpszSubKey
, LPCSTR lpszValue
,
1065 LPCSTR lpszPath
, DWORD dwFlags
)
1067 char szBuff
[MAX_PATH
];
1069 FIXME("(hkey=%p,%s,%s,%p,%d) - semi-stub\n",hKey
, debugstr_a(lpszSubKey
),
1070 debugstr_a(lpszValue
), lpszPath
, dwFlags
);
1072 lstrcpyA(szBuff
, lpszPath
);
1074 /* FIXME: PathUnExpandEnvStringsA(szBuff); */
1076 return SHSetValueA(hKey
,lpszSubKey
, lpszValue
, REG_SZ
, szBuff
,
1080 /*************************************************************************
1081 * SHRegSetPathW [SHLWAPI.@]
1083 * See SHRegSetPathA.
1085 DWORD WINAPI
SHRegSetPathW(HKEY hKey
, LPCWSTR lpszSubKey
, LPCWSTR lpszValue
,
1086 LPCWSTR lpszPath
, DWORD dwFlags
)
1088 WCHAR szBuff
[MAX_PATH
];
1090 FIXME("(hkey=%p,%s,%s,%p,%d) - semi-stub\n",hKey
, debugstr_w(lpszSubKey
),
1091 debugstr_w(lpszValue
), lpszPath
, dwFlags
);
1093 lstrcpyW(szBuff
, lpszPath
);
1095 /* FIXME: PathUnExpandEnvStringsW(szBuff); */
1097 return SHSetValueW(hKey
,lpszSubKey
, lpszValue
, REG_SZ
, szBuff
,
1101 /*************************************************************************
1102 * SHGetValueA [SHLWAPI.@]
1104 * Get a value from the registry.
1107 * hKey [I] Handle to registry key
1108 * lpszSubKey [I] Name of sub key containing value to get
1109 * lpszValue [I] Name of value to get
1110 * pwType [O] Pointer to the values type
1111 * pvData [O] Pointer to the values data
1112 * pcbData [O] Pointer to the values size
1115 * Success: ERROR_SUCCESS. Output parameters contain the details read.
1116 * Failure: An error code from RegOpenKeyExA() or SHQueryValueExA().
1118 DWORD WINAPI
SHGetValueA(HKEY hKey
, LPCSTR lpszSubKey
, LPCSTR lpszValue
,
1119 LPDWORD pwType
, LPVOID pvData
, LPDWORD pcbData
)
1124 TRACE("(hkey=%p,%s,%s,%p,%p,%p)\n", hKey
, debugstr_a(lpszSubKey
),
1125 debugstr_a(lpszValue
), pwType
, pvData
, pcbData
);
1127 /* lpszSubKey can be 0. In this case the value is taken from the
1131 dwRet
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_QUERY_VALUE
, &hSubKey
);
1135 /* SHQueryValueEx expands Environment strings */
1136 dwRet
= SHQueryValueExA(hSubKey
? hSubKey
: hKey
, lpszValue
, 0, pwType
, pvData
, pcbData
);
1137 if (hSubKey
) RegCloseKey(hSubKey
);
1142 /*************************************************************************
1143 * SHRegGetValueA [SHLWAPI.@]
1145 * Get a value from the registry.
1148 * hKey [I] Handle to registry key
1149 * lpszSubKey [I] Name of sub key containing value to get
1150 * lpszValue [I] Name of value to get
1151 * srrf [I] Flags for restricting returned data
1152 * pwType [O] Pointer to the values type
1153 * pvData [O] Pointer to the values data
1154 * pcbData [O] Pointer to the values size
1157 * Success: ERROR_SUCCESS. Output parameters contain the details read.
1158 * Failure: An error code from RegOpenKeyExA() or SHQueryValueExA().
1160 DWORD WINAPI
SHRegGetValueA(HKEY hKey
, LPCSTR lpszSubKey
, LPCSTR lpszValue
, DWORD srrfFlags
,
1161 LPDWORD pwType
, LPVOID pvData
, LPDWORD pcbData
)
1166 TRACE("(hkey=%p,%s,%s,%p,%p,%p)\n", hKey
, debugstr_a(lpszSubKey
),
1167 debugstr_a(lpszValue
), pwType
, pvData
, pcbData
);
1168 FIXME("Semi-Stub: Find meaning and implement handling of SRFF Flags 0x%08x\n", srrfFlags
);
1170 dwRet
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_QUERY_VALUE
, &hSubKey
);
1173 /* SHQueryValueEx expands Environment strings */
1174 dwRet
= SHQueryValueExA(hSubKey
, lpszValue
, 0, pwType
, pvData
, pcbData
);
1175 RegCloseKey(hSubKey
);
1180 /*************************************************************************
1181 * SHReg GetRegValueW [SHLWAPI.@]
1185 DWORD WINAPI
SHRegGetValueW(HKEY hKey
, LPCWSTR lpszSubKey
, LPCWSTR lpszValue
, DWORD srrfFlags
,
1186 LPDWORD pwType
, LPVOID pvData
, LPDWORD pcbData
)
1191 TRACE("(hkey=%p,%s,%s,0x%08x, %p,%p,%p)\n", hKey
, debugstr_w(lpszSubKey
),
1192 debugstr_w(lpszValue
), srrfFlags
,pwType
, pvData
, pcbData
);
1193 FIXME("Semi-Stub: Find meaning and implement handling of SRFF Flags 0x%08x\n", srrfFlags
);
1195 dwRet
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_QUERY_VALUE
, &hSubKey
);
1198 dwRet
= SHQueryValueExW(hSubKey
, lpszValue
, 0, pwType
, pvData
, pcbData
);
1199 RegCloseKey(hSubKey
);
1204 /*************************************************************************
1205 * SHGetValueW [SHLWAPI.@]
1209 DWORD WINAPI
SHGetValueW(HKEY hKey
, LPCWSTR lpszSubKey
, LPCWSTR lpszValue
,
1210 LPDWORD pwType
, LPVOID pvData
, LPDWORD pcbData
)
1215 TRACE("(hkey=%p,%s,%s,%p,%p,%p)\n", hKey
, debugstr_w(lpszSubKey
),
1216 debugstr_w(lpszValue
), pwType
, pvData
, pcbData
);
1219 dwRet
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_QUERY_VALUE
, &hSubKey
);
1223 dwRet
= SHQueryValueExW(hSubKey
? hSubKey
: hKey
, lpszValue
, 0, pwType
, pvData
, pcbData
);
1224 if (hSubKey
) RegCloseKey(hSubKey
);
1229 /*************************************************************************
1230 * SHSetValueA [SHLWAPI.@]
1232 * Set a value in the registry.
1235 * hKey [I] Handle to registry key
1236 * lpszSubKey [I] Name of sub key under hKey
1237 * lpszValue [I] Name of value to set
1238 * dwType [I] Type of the value
1239 * pvData [I] Data of the value
1240 * cbData [I] Size of the value
1243 * Success: ERROR_SUCCESS. The value is set with the data given.
1244 * Failure: An error code from RegCreateKeyExA() or RegSetValueExA()
1247 * If lpszSubKey does not exist, it is created before the value is set. If
1248 * lpszSubKey is NULL or an empty string, then the value is added directly
1251 DWORD WINAPI
SHSetValueA(HKEY hKey
, LPCSTR lpszSubKey
, LPCSTR lpszValue
,
1252 DWORD dwType
, LPCVOID pvData
, DWORD cbData
)
1254 DWORD dwRet
= ERROR_SUCCESS
, dwDummy
;
1257 TRACE("(hkey=%p,%s,%s,%d,%p,%d)\n", hKey
, debugstr_a(lpszSubKey
),
1258 debugstr_a(lpszValue
), dwType
, pvData
, cbData
);
1260 if (lpszSubKey
&& *lpszSubKey
)
1261 dwRet
= RegCreateKeyExA(hKey
, lpszSubKey
, 0, NULL
,
1262 0, KEY_SET_VALUE
, NULL
, &hSubKey
, &dwDummy
);
1267 dwRet
= RegSetValueExA(hSubKey
, lpszValue
, 0, dwType
, pvData
, cbData
);
1268 if (hSubKey
!= hKey
)
1269 RegCloseKey(hSubKey
);
1274 /*************************************************************************
1275 * SHSetValueW [SHLWAPI.@]
1279 DWORD WINAPI
SHSetValueW(HKEY hKey
, LPCWSTR lpszSubKey
, LPCWSTR lpszValue
,
1280 DWORD dwType
, LPCVOID pvData
, DWORD cbData
)
1282 DWORD dwRet
= ERROR_SUCCESS
, dwDummy
;
1285 TRACE("(hkey=%p,%s,%s,%d,%p,%d)\n", hKey
, debugstr_w(lpszSubKey
),
1286 debugstr_w(lpszValue
), dwType
, pvData
, cbData
);
1288 if (lpszSubKey
&& *lpszSubKey
)
1289 dwRet
= RegCreateKeyExW(hKey
, lpszSubKey
, 0, NULL
,
1290 0, KEY_SET_VALUE
, NULL
, &hSubKey
, &dwDummy
);
1295 dwRet
= RegSetValueExW(hSubKey
, lpszValue
, 0, dwType
, pvData
, cbData
);
1296 if (hSubKey
!= hKey
)
1297 RegCloseKey(hSubKey
);
1302 /*************************************************************************
1303 * SHQueryInfoKeyA [SHLWAPI.@]
1305 * Get information about a registry key. See RegQueryInfoKeyA().
1308 * The result of calling RegQueryInfoKeyA().
1310 LONG WINAPI
SHQueryInfoKeyA(HKEY hKey
, LPDWORD pwSubKeys
, LPDWORD pwSubKeyMax
,
1311 LPDWORD pwValues
, LPDWORD pwValueMax
)
1313 TRACE("(hkey=%p,%p,%p,%p,%p)\n", hKey
, pwSubKeys
, pwSubKeyMax
,
1314 pwValues
, pwValueMax
);
1315 return RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, pwSubKeys
, pwSubKeyMax
,
1316 NULL
, pwValues
, pwValueMax
, NULL
, NULL
, NULL
);
1319 /*************************************************************************
1320 * SHQueryInfoKeyW [SHLWAPI.@]
1322 * See SHQueryInfoKeyA.
1324 LONG WINAPI
SHQueryInfoKeyW(HKEY hKey
, LPDWORD pwSubKeys
, LPDWORD pwSubKeyMax
,
1325 LPDWORD pwValues
, LPDWORD pwValueMax
)
1327 TRACE("(hkey=%p,%p,%p,%p,%p)\n", hKey
, pwSubKeys
, pwSubKeyMax
,
1328 pwValues
, pwValueMax
);
1329 return RegQueryInfoKeyW(hKey
, NULL
, NULL
, NULL
, pwSubKeys
, pwSubKeyMax
,
1330 NULL
, pwValues
, pwValueMax
, NULL
, NULL
, NULL
);
1333 /*************************************************************************
1334 * SHQueryValueExA [SHLWAPI.@]
1336 * Get a value from the registry, expanding environment variable strings.
1339 * hKey [I] Handle to registry key
1340 * lpszValue [I] Name of value to query
1341 * lpReserved [O] Reserved for future use; must be NULL
1342 * pwType [O] Optional pointer updated with the values type
1343 * pvData [O] Optional pointer updated with the values data
1344 * pcbData [O] Optional pointer updated with the values size
1347 * Success: ERROR_SUCCESS. Any non NULL output parameters are updated with
1348 * information about the value.
1349 * Failure: ERROR_OUTOFMEMORY if memory allocation fails, or the type of the
1350 * data is REG_EXPAND_SZ and pcbData is NULL. Otherwise an error
1351 * code from RegQueryValueExA() or ExpandEnvironmentStringsA().
1354 * Either pwType, pvData or pcbData may be NULL if the caller doesn't want
1355 * the type, data or size information for the value.
1357 * If the type of the data is REG_EXPAND_SZ, it is expanded to REG_SZ. The
1358 * value returned will be truncated if it is of type REG_SZ and bigger than
1359 * the buffer given to store it.
1362 * case-1: the unexpanded string is smaller than the expanded one
1363 * subcase-1: the buffer is too small to hold the unexpanded string:
1364 * function fails and returns the size of the unexpanded string.
1366 * subcase-2: buffer is too small to hold the expanded string:
1367 * the function return success (!!) and the result is truncated
1368 * *** This is clearly an error in the native implementation. ***
1370 * case-2: the unexpanded string is bigger than the expanded one
1371 * The buffer must have enough space to hold the unexpanded
1372 * string even if the result is smaller.
1375 DWORD WINAPI
SHQueryValueExA( HKEY hKey
, LPCSTR lpszValue
,
1376 LPDWORD lpReserved
, LPDWORD pwType
,
1377 LPVOID pvData
, LPDWORD pcbData
)
1379 DWORD dwRet
, dwType
, dwUnExpDataLen
= 0, dwExpDataLen
;
1381 TRACE("(hkey=%p,%s,%p,%p,%p,%p=%d)\n", hKey
, debugstr_a(lpszValue
),
1382 lpReserved
, pwType
, pvData
, pcbData
, pcbData
? *pcbData
: 0);
1384 if (pcbData
) dwUnExpDataLen
= *pcbData
;
1386 dwRet
= RegQueryValueExA(hKey
, lpszValue
, lpReserved
, &dwType
, pvData
, &dwUnExpDataLen
);
1388 if (pcbData
&& (dwType
== REG_EXPAND_SZ
))
1390 DWORD nBytesToAlloc
;
1392 /* Expand type REG_EXPAND_SZ into REG_SZ */
1395 /* If the caller didn't supply a buffer or the buffer is too small we have
1396 * to allocate our own
1398 if ((!pvData
) || (dwRet
== ERROR_MORE_DATA
) )
1401 nBytesToAlloc
= (!pvData
|| (dwRet
== ERROR_MORE_DATA
)) ? dwUnExpDataLen
: *pcbData
;
1403 szData
= (LPSTR
) LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
1404 RegQueryValueExA (hKey
, lpszValue
, lpReserved
, NULL
, (LPBYTE
)szData
, &nBytesToAlloc
);
1405 dwExpDataLen
= ExpandEnvironmentStringsA(szData
, &cNull
, 1);
1406 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
1407 LocalFree((HLOCAL
) szData
);
1411 nBytesToAlloc
= (lstrlenA(pvData
)+1) * sizeof (CHAR
);
1412 szData
= (LPSTR
) LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
1413 lstrcpyA(szData
, pvData
);
1414 dwExpDataLen
= ExpandEnvironmentStringsA(szData
, pvData
, *pcbData
/ sizeof(CHAR
));
1415 if (dwExpDataLen
> *pcbData
) dwRet
= ERROR_MORE_DATA
;
1416 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
1417 LocalFree((HLOCAL
) szData
);
1421 /* Update the type and data size if the caller wanted them */
1422 if ( dwType
== REG_EXPAND_SZ
) dwType
= REG_SZ
;
1423 if ( pwType
) *pwType
= dwType
;
1424 if ( pcbData
) *pcbData
= dwUnExpDataLen
;
1429 /*************************************************************************
1430 * SHQueryValueExW [SHLWAPI.@]
1432 * See SHQueryValueExA.
1434 DWORD WINAPI
SHQueryValueExW(HKEY hKey
, LPCWSTR lpszValue
,
1435 LPDWORD lpReserved
, LPDWORD pwType
,
1436 LPVOID pvData
, LPDWORD pcbData
)
1438 DWORD dwRet
, dwType
, dwUnExpDataLen
= 0, dwExpDataLen
;
1440 TRACE("(hkey=%p,%s,%p,%p,%p,%p=%d)\n", hKey
, debugstr_w(lpszValue
),
1441 lpReserved
, pwType
, pvData
, pcbData
, pcbData
? *pcbData
: 0);
1443 if (pcbData
) dwUnExpDataLen
= *pcbData
;
1445 dwRet
= RegQueryValueExW(hKey
, lpszValue
, lpReserved
, &dwType
, pvData
, &dwUnExpDataLen
);
1446 if (dwRet
!=ERROR_SUCCESS
&& dwRet
!=ERROR_MORE_DATA
)
1449 if (pcbData
&& (dwType
== REG_EXPAND_SZ
))
1451 DWORD nBytesToAlloc
;
1453 /* Expand type REG_EXPAND_SZ into REG_SZ */
1456 /* If the caller didn't supply a buffer or the buffer is too small we have
1457 * to allocate our own
1459 if ((!pvData
) || (dwRet
== ERROR_MORE_DATA
) )
1462 nBytesToAlloc
= (!pvData
|| (dwRet
== ERROR_MORE_DATA
)) ? dwUnExpDataLen
: *pcbData
;
1464 szData
= (LPWSTR
) LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
1465 RegQueryValueExW (hKey
, lpszValue
, lpReserved
, NULL
, (LPBYTE
)szData
, &nBytesToAlloc
);
1466 dwExpDataLen
= ExpandEnvironmentStringsW(szData
, &cNull
, 1);
1467 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
1468 LocalFree((HLOCAL
) szData
);
1472 nBytesToAlloc
= (lstrlenW(pvData
) + 1) * sizeof(WCHAR
);
1473 szData
= (LPWSTR
) LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
1474 lstrcpyW(szData
, pvData
);
1475 dwExpDataLen
= ExpandEnvironmentStringsW(szData
, pvData
, *pcbData
/sizeof(WCHAR
) );
1476 if (dwExpDataLen
> *pcbData
) dwRet
= ERROR_MORE_DATA
;
1477 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
1478 LocalFree((HLOCAL
) szData
);
1482 /* Update the type and data size if the caller wanted them */
1483 if ( dwType
== REG_EXPAND_SZ
) dwType
= REG_SZ
;
1484 if ( pwType
) *pwType
= dwType
;
1485 if ( pcbData
) *pcbData
= dwUnExpDataLen
;
1489 /*************************************************************************
1490 * SHDeleteKeyA [SHLWAPI.@]
1492 * Delete a registry key and any sub keys/values present
1495 * hKey [I] Handle to registry key
1496 * lpszSubKey [I] Name of sub key to delete
1499 * Success: ERROR_SUCCESS. The key is deleted.
1500 * Failure: An error code from RegOpenKeyExA(), RegQueryInfoKeyA(),
1501 * RegEnumKeyExA() or RegDeleteKeyA().
1503 DWORD WINAPI
SHDeleteKeyA(HKEY hKey
, LPCSTR lpszSubKey
)
1505 DWORD dwRet
, dwMaxSubkeyLen
= 0, dwSize
;
1506 CHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
1509 TRACE("(hkey=%p,%s)\n", hKey
, debugstr_a(lpszSubKey
));
1511 dwRet
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
1514 /* Find the maximum subkey length so that we can allocate a buffer */
1515 dwRet
= RegQueryInfoKeyA(hSubKey
, NULL
, NULL
, NULL
, NULL
,
1516 &dwMaxSubkeyLen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1520 if (dwMaxSubkeyLen
> sizeof(szNameBuf
))
1521 /* Name too big: alloc a buffer for it */
1522 lpszName
= HeapAlloc(GetProcessHeap(), 0, dwMaxSubkeyLen
*sizeof(CHAR
));
1525 dwRet
= ERROR_NOT_ENOUGH_MEMORY
;
1528 while (dwRet
== ERROR_SUCCESS
)
1530 dwSize
= dwMaxSubkeyLen
;
1531 dwRet
= RegEnumKeyExA(hSubKey
, 0, lpszName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
1532 if (dwRet
== ERROR_SUCCESS
|| dwRet
== ERROR_MORE_DATA
)
1533 dwRet
= SHDeleteKeyA(hSubKey
, lpszName
);
1535 if (dwRet
== ERROR_NO_MORE_ITEMS
)
1536 dwRet
= ERROR_SUCCESS
;
1537 if (lpszName
!= szNameBuf
)
1538 HeapFree(GetProcessHeap(), 0, lpszName
); /* Free buffer if allocated */
1542 RegCloseKey(hSubKey
);
1544 dwRet
= RegDeleteKeyA(hKey
, lpszSubKey
);
1549 /*************************************************************************
1550 * SHDeleteKeyW [SHLWAPI.@]
1554 DWORD WINAPI
SHDeleteKeyW(HKEY hKey
, LPCWSTR lpszSubKey
)
1556 DWORD dwRet
, dwMaxSubkeyLen
= 0, dwSize
;
1557 WCHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
1560 TRACE("(hkey=%p,%s)\n", hKey
, debugstr_w(lpszSubKey
));
1562 dwRet
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
1565 /* Find the maximum subkey length so that we can allocate a buffer */
1566 dwRet
= RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, NULL
,
1567 &dwMaxSubkeyLen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1571 if (dwMaxSubkeyLen
> sizeof(szNameBuf
)/sizeof(WCHAR
))
1572 /* Name too big: alloc a buffer for it */
1573 lpszName
= HeapAlloc(GetProcessHeap(), 0, dwMaxSubkeyLen
*sizeof(WCHAR
));
1576 dwRet
= ERROR_NOT_ENOUGH_MEMORY
;
1579 while (dwRet
== ERROR_SUCCESS
)
1581 dwSize
= dwMaxSubkeyLen
;
1582 dwRet
= RegEnumKeyExW(hSubKey
, 0, lpszName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
1583 if (dwRet
== ERROR_SUCCESS
|| dwRet
== ERROR_MORE_DATA
)
1584 dwRet
= SHDeleteKeyW(hSubKey
, lpszName
);
1586 if (dwRet
== ERROR_NO_MORE_ITEMS
)
1587 dwRet
= ERROR_SUCCESS
;
1589 if (lpszName
!= szNameBuf
)
1590 HeapFree(GetProcessHeap(), 0, lpszName
); /* Free buffer if allocated */
1594 RegCloseKey(hSubKey
);
1596 dwRet
= RegDeleteKeyW(hKey
, lpszSubKey
);
1601 /*************************************************************************
1602 * SHDeleteEmptyKeyA [SHLWAPI.@]
1604 * Delete a registry key with no sub keys.
1607 * hKey [I] Handle to registry key
1608 * lpszSubKey [I] Name of sub key to delete
1611 * Success: ERROR_SUCCESS. The key is deleted.
1612 * Failure: If the key is not empty, returns ERROR_KEY_HAS_CHILDREN. Otherwise
1613 * returns an error code from RegOpenKeyExA(), RegQueryInfoKeyA() or
1616 DWORD WINAPI
SHDeleteEmptyKeyA(HKEY hKey
, LPCSTR lpszSubKey
)
1618 DWORD dwRet
, dwKeyCount
= 0;
1621 TRACE("(hkey=%p,%s)\n", hKey
, debugstr_a(lpszSubKey
));
1623 dwRet
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
1626 dwRet
= RegQueryInfoKeyA(hSubKey
, NULL
, NULL
, NULL
, &dwKeyCount
,
1627 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1628 RegCloseKey(hSubKey
);
1632 dwRet
= RegDeleteKeyA(hKey
, lpszSubKey
);
1634 dwRet
= ERROR_KEY_HAS_CHILDREN
;
1640 /*************************************************************************
1641 * SHDeleteEmptyKeyW [SHLWAPI.@]
1643 * See SHDeleteEmptyKeyA.
1645 DWORD WINAPI
SHDeleteEmptyKeyW(HKEY hKey
, LPCWSTR lpszSubKey
)
1647 DWORD dwRet
, dwKeyCount
= 0;
1650 TRACE("(hkey=%p, %s)\n", hKey
, debugstr_w(lpszSubKey
));
1652 dwRet
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
1655 dwRet
= RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, &dwKeyCount
,
1656 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1657 RegCloseKey(hSubKey
);
1661 dwRet
= RegDeleteKeyW(hKey
, lpszSubKey
);
1663 dwRet
= ERROR_KEY_HAS_CHILDREN
;
1669 /*************************************************************************
1670 * SHDeleteOrphanKeyA [SHLWAPI.@]
1672 * Delete a registry key with no sub keys or values.
1675 * hKey [I] Handle to registry key
1676 * lpszSubKey [I] Name of sub key to possibly delete
1679 * Success: ERROR_SUCCESS. The key has been deleted if it was an orphan.
1680 * Failure: An error from RegOpenKeyExA(), RegQueryValueExA(), or RegDeleteKeyA().
1682 DWORD WINAPI
SHDeleteOrphanKeyA(HKEY hKey
, LPCSTR lpszSubKey
)
1685 DWORD dwKeyCount
= 0, dwValueCount
= 0, dwRet
;
1687 TRACE("(hkey=%p,%s)\n", hKey
, debugstr_a(lpszSubKey
));
1689 dwRet
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
1693 /* Get subkey and value count */
1694 dwRet
= RegQueryInfoKeyA(hSubKey
, NULL
, NULL
, NULL
, &dwKeyCount
,
1695 NULL
, NULL
, &dwValueCount
, NULL
, NULL
, NULL
, NULL
);
1697 if(!dwRet
&& !dwKeyCount
&& !dwValueCount
)
1699 dwRet
= RegDeleteKeyA(hKey
, lpszSubKey
);
1701 RegCloseKey(hSubKey
);
1706 /*************************************************************************
1707 * SHDeleteOrphanKeyW [SHLWAPI.@]
1709 * See SHDeleteOrphanKeyA.
1711 DWORD WINAPI
SHDeleteOrphanKeyW(HKEY hKey
, LPCWSTR lpszSubKey
)
1714 DWORD dwKeyCount
= 0, dwValueCount
= 0, dwRet
;
1716 TRACE("(hkey=%p,%s)\n", hKey
, debugstr_w(lpszSubKey
));
1718 dwRet
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
1722 /* Get subkey and value count */
1723 dwRet
= RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, &dwKeyCount
,
1724 NULL
, NULL
, &dwValueCount
, NULL
, NULL
, NULL
, NULL
);
1726 if(!dwRet
&& !dwKeyCount
&& !dwValueCount
)
1728 dwRet
= RegDeleteKeyW(hKey
, lpszSubKey
);
1730 RegCloseKey(hSubKey
);
1735 /*************************************************************************
1736 * SHDeleteValueA [SHLWAPI.@]
1738 * Delete a value from the registry.
1741 * hKey [I] Handle to registry key
1742 * lpszSubKey [I] Name of sub key containing value to delete
1743 * lpszValue [I] Name of value to delete
1746 * Success: ERROR_SUCCESS. The value is deleted.
1747 * Failure: An error code from RegOpenKeyExA() or RegDeleteValueA().
1749 DWORD WINAPI
SHDeleteValueA(HKEY hKey
, LPCSTR lpszSubKey
, LPCSTR lpszValue
)
1754 TRACE("(hkey=%p,%s,%s)\n", hKey
, debugstr_a(lpszSubKey
), debugstr_a(lpszValue
));
1756 dwRet
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_SET_VALUE
, &hSubKey
);
1759 dwRet
= RegDeleteValueA(hSubKey
, lpszValue
);
1760 RegCloseKey(hSubKey
);
1765 /*************************************************************************
1766 * SHDeleteValueW [SHLWAPI.@]
1768 * See SHDeleteValueA.
1770 DWORD WINAPI
SHDeleteValueW(HKEY hKey
, LPCWSTR lpszSubKey
, LPCWSTR lpszValue
)
1775 TRACE("(hkey=%p,%s,%s)\n", hKey
, debugstr_w(lpszSubKey
), debugstr_w(lpszValue
));
1777 dwRet
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_SET_VALUE
, &hSubKey
);
1780 dwRet
= RegDeleteValueW(hSubKey
, lpszValue
);
1781 RegCloseKey(hSubKey
);
1786 /*************************************************************************
1787 * SHEnumKeyExA [SHLWAPI.@]
1789 * Enumerate sub keys in a registry key.
1792 * hKey [I] Handle to registry key
1793 * dwIndex [I] Index of key to enumerate
1794 * lpszSubKey [O] Pointer updated with the subkey name
1795 * pwLen [O] Pointer updated with the subkey length
1798 * Success: ERROR_SUCCESS. lpszSubKey and pwLen are updated.
1799 * Failure: An error code from RegEnumKeyExA().
1801 LONG WINAPI
SHEnumKeyExA(HKEY hKey
, DWORD dwIndex
, LPSTR lpszSubKey
,
1804 TRACE("(hkey=%p,%d,%s,%p)\n", hKey
, dwIndex
, debugstr_a(lpszSubKey
), pwLen
);
1806 return RegEnumKeyExA(hKey
, dwIndex
, lpszSubKey
, pwLen
, NULL
, NULL
, NULL
, NULL
);
1809 /*************************************************************************
1810 * SHEnumKeyExW [SHLWAPI.@]
1814 LONG WINAPI
SHEnumKeyExW(HKEY hKey
, DWORD dwIndex
, LPWSTR lpszSubKey
,
1817 TRACE("(hkey=%p,%d,%s,%p)\n", hKey
, dwIndex
, debugstr_w(lpszSubKey
), pwLen
);
1819 return RegEnumKeyExW(hKey
, dwIndex
, lpszSubKey
, pwLen
, NULL
, NULL
, NULL
, NULL
);
1822 /*************************************************************************
1823 * SHEnumValueA [SHLWAPI.@]
1825 * Enumerate values in a registry key.
1828 * hKey [I] Handle to registry key
1829 * dwIndex [I] Index of key to enumerate
1830 * lpszValue [O] Pointer updated with the values name
1831 * pwLen [O] Pointer updated with the values length
1832 * pwType [O] Pointer updated with the values type
1833 * pvData [O] Pointer updated with the values data
1834 * pcbData [O] Pointer updated with the values size
1837 * Success: ERROR_SUCCESS. Output parameters are updated.
1838 * Failure: An error code from RegEnumValueA().
1840 LONG WINAPI
SHEnumValueA(HKEY hKey
, DWORD dwIndex
, LPSTR lpszValue
,
1841 LPDWORD pwLen
, LPDWORD pwType
,
1842 LPVOID pvData
, LPDWORD pcbData
)
1844 TRACE("(hkey=%p,%d,%s,%p,%p,%p,%p)\n", hKey
, dwIndex
,
1845 debugstr_a(lpszValue
), pwLen
, pwType
, pvData
, pcbData
);
1847 return RegEnumValueA(hKey
, dwIndex
, lpszValue
, pwLen
, NULL
,
1848 pwType
, pvData
, pcbData
);
1851 /*************************************************************************
1852 * SHEnumValueW [SHLWAPI.@]
1856 LONG WINAPI
SHEnumValueW(HKEY hKey
, DWORD dwIndex
, LPWSTR lpszValue
,
1857 LPDWORD pwLen
, LPDWORD pwType
,
1858 LPVOID pvData
, LPDWORD pcbData
)
1860 TRACE("(hkey=%p,%d,%s,%p,%p,%p,%p)\n", hKey
, dwIndex
,
1861 debugstr_w(lpszValue
), pwLen
, pwType
, pvData
, pcbData
);
1863 return RegEnumValueW(hKey
, dwIndex
, lpszValue
, pwLen
, NULL
,
1864 pwType
, pvData
, pcbData
);
1867 /*************************************************************************
1870 * Get a value from the registry.
1873 * hKey [I] Handle to registry key
1874 * pSubKey [I] Name of sub key containing value to get
1875 * pValue [I] Name of value to get
1876 * pwType [O] Destination for the values type
1877 * pvData [O] Destination for the values data
1878 * pbData [O] Destination for the values size
1881 * Success: ERROR_SUCCESS. Output parameters contain the details read.
1882 * Failure: An error code from RegOpenKeyExA() or SHQueryValueExA(),
1883 * or ERROR_INVALID_FUNCTION in the machine is in safe mode.
1885 DWORD WINAPI
SHGetValueGoodBootA(HKEY hkey
, LPCSTR pSubKey
, LPCSTR pValue
,
1886 LPDWORD pwType
, LPVOID pvData
, LPDWORD pbData
)
1888 if (GetSystemMetrics(SM_CLEANBOOT
))
1889 return ERROR_INVALID_FUNCTION
;
1890 return SHGetValueA(hkey
, pSubKey
, pValue
, pwType
, pvData
, pbData
);
1893 /*************************************************************************
1896 * Unicode version of SHGetValueGoodBootW.
1898 DWORD WINAPI
SHGetValueGoodBootW(HKEY hkey
, LPCWSTR pSubKey
, LPCWSTR pValue
,
1899 LPDWORD pwType
, LPVOID pvData
, LPDWORD pbData
)
1901 if (GetSystemMetrics(SM_CLEANBOOT
))
1902 return ERROR_INVALID_FUNCTION
;
1903 return SHGetValueW(hkey
, pSubKey
, pValue
, pwType
, pvData
, pbData
);
1906 /*************************************************************************
1909 * Set a MIME content type in the registry.
1912 * lpszSubKey [I] Name of key under HKEY_CLASSES_ROOT.
1913 * lpszValue [I] Value to set
1919 BOOL WINAPI
RegisterMIMETypeForExtensionA(LPCSTR lpszSubKey
, LPCSTR lpszValue
)
1925 WARN("Invalid lpszValue would crash under Win32!\n");
1929 dwRet
= SHSetValueA(HKEY_CLASSES_ROOT
, lpszSubKey
, lpszContentTypeA
,
1930 REG_SZ
, lpszValue
, strlen(lpszValue
));
1931 return dwRet
? FALSE
: TRUE
;
1934 /*************************************************************************
1937 * Unicode version of RegisterMIMETypeForExtensionA.
1939 BOOL WINAPI
RegisterMIMETypeForExtensionW(LPCWSTR lpszSubKey
, LPCWSTR lpszValue
)
1945 WARN("Invalid lpszValue would crash under Win32!\n");
1949 dwRet
= SHSetValueW(HKEY_CLASSES_ROOT
, lpszSubKey
, lpszContentTypeW
,
1950 REG_SZ
, lpszValue
, strlenW(lpszValue
));
1951 return dwRet
? FALSE
: TRUE
;
1954 /*************************************************************************
1957 * Delete a MIME content type from the registry.
1960 * lpszSubKey [I] Name of sub key
1966 BOOL WINAPI
UnregisterMIMETypeForExtensionA(LPCSTR lpszSubKey
)
1968 HRESULT ret
= SHDeleteValueA(HKEY_CLASSES_ROOT
, lpszSubKey
, lpszContentTypeA
);
1969 return ret
? FALSE
: TRUE
;
1972 /*************************************************************************
1975 * Unicode version of UnregisterMIMETypeForExtensionA.
1977 BOOL WINAPI
UnregisterMIMETypeForExtensionW(LPCWSTR lpszSubKey
)
1979 HRESULT ret
= SHDeleteValueW(HKEY_CLASSES_ROOT
, lpszSubKey
, lpszContentTypeW
);
1980 return ret
? FALSE
: TRUE
;
1983 /*************************************************************************
1986 * Get the registry path to a MIME content key.
1989 * lpszType [I] Content type to get the path for
1990 * lpszBuffer [O] Destination for path
1991 * dwLen [I] Length of lpszBuffer
1994 * Success: TRUE. lpszBuffer contains the full path.
1998 * The base path for the key is "MIME\Database\Content Type\"
2000 BOOL WINAPI
GetMIMETypeSubKeyA(LPCSTR lpszType
, LPSTR lpszBuffer
, DWORD dwLen
)
2002 TRACE("(%s,%p,%d)\n", debugstr_a(lpszType
), lpszBuffer
, dwLen
);
2004 if (dwLen
> dwLenMimeDbContent
&& lpszType
&& lpszBuffer
)
2006 size_t dwStrLen
= strlen(lpszType
);
2008 if (dwStrLen
< dwLen
- dwLenMimeDbContent
)
2010 memcpy(lpszBuffer
, szMimeDbContentA
, dwLenMimeDbContent
);
2011 memcpy(lpszBuffer
+ dwLenMimeDbContent
, lpszType
, dwStrLen
+ 1);
2018 /*************************************************************************
2021 * Unicode version of GetMIMETypeSubKeyA.
2023 BOOL WINAPI
GetMIMETypeSubKeyW(LPCWSTR lpszType
, LPWSTR lpszBuffer
, DWORD dwLen
)
2025 TRACE("(%s,%p,%d)\n", debugstr_w(lpszType
), lpszBuffer
, dwLen
);
2027 if (dwLen
> dwLenMimeDbContent
&& lpszType
&& lpszBuffer
)
2029 DWORD dwStrLen
= strlenW(lpszType
);
2031 if (dwStrLen
< dwLen
- dwLenMimeDbContent
)
2033 memcpy(lpszBuffer
, szMimeDbContentW
, dwLenMimeDbContent
* sizeof(WCHAR
));
2034 memcpy(lpszBuffer
+ dwLenMimeDbContent
, lpszType
, (dwStrLen
+ 1) * sizeof(WCHAR
));
2041 /*************************************************************************
2044 * Get the file extension for a given Mime type.
2047 * lpszType [I] Mime type to get the file extension for
2048 * lpExt [O] Destination for the resulting extension
2049 * iLen [I] Length of lpExt in characters
2052 * Success: TRUE. lpExt contains the file extension.
2053 * Failure: FALSE, if any parameter is invalid or the extension cannot be
2054 * retrieved. If iLen > 0, lpExt is set to an empty string.
2057 * - The extension returned in lpExt always has a leading '.' character, even
2058 * if the registry Mime database entry does not.
2059 * - iLen must be long enough for the file extension for this function to succeed.
2061 BOOL WINAPI
MIME_GetExtensionA(LPCSTR lpszType
, LPSTR lpExt
, INT iLen
)
2063 char szSubKey
[MAX_PATH
];
2064 DWORD dwlen
= iLen
- 1, dwType
;
2067 if (iLen
> 0 && lpExt
)
2070 if (lpszType
&& lpExt
&& iLen
> 2 &&
2071 GetMIMETypeSubKeyA(lpszType
, szSubKey
, MAX_PATH
) &&
2072 !SHGetValueA(HKEY_CLASSES_ROOT
, szSubKey
, szExtensionA
, &dwType
, lpExt
+ 1, &dwlen
) &&
2075 if (lpExt
[1] == '.')
2076 memmove(lpExt
, lpExt
+ 1, strlen(lpExt
+ 1) + 1);
2078 *lpExt
= '.'; /* Supply a '.' */
2084 /*************************************************************************
2087 * Unicode version of MIME_GetExtensionA.
2089 BOOL WINAPI
MIME_GetExtensionW(LPCWSTR lpszType
, LPWSTR lpExt
, INT iLen
)
2091 WCHAR szSubKey
[MAX_PATH
];
2092 DWORD dwlen
= iLen
- 1, dwType
;
2095 if (iLen
> 0 && lpExt
)
2098 if (lpszType
&& lpExt
&& iLen
> 2 &&
2099 GetMIMETypeSubKeyW(lpszType
, szSubKey
, MAX_PATH
) &&
2100 !SHGetValueW(HKEY_CLASSES_ROOT
, szSubKey
, szExtensionW
, &dwType
, lpExt
+ 1, &dwlen
) &&
2103 if (lpExt
[1] == '.')
2104 memmove(lpExt
, lpExt
+ 1, (strlenW(lpExt
+ 1) + 1) * sizeof(WCHAR
));
2106 *lpExt
= '.'; /* Supply a '.' */
2112 /*************************************************************************
2115 * Set the file extension for a MIME content key.
2118 * lpszExt [I] File extension to set
2119 * lpszType [I] Content type to set the extension for
2122 * Success: TRUE. The file extension is set in the registry.
2125 BOOL WINAPI
RegisterExtensionForMIMETypeA(LPCSTR lpszExt
, LPCSTR lpszType
)
2128 char szKey
[MAX_PATH
];
2130 TRACE("(%s,%s)\n", debugstr_a(lpszExt
), debugstr_a(lpszType
));
2132 if (!GetMIMETypeSubKeyA(lpszType
, szKey
, MAX_PATH
)) /* Get full path to the key */
2135 dwLen
= strlen(lpszExt
) + 1;
2137 if (SHSetValueA(HKEY_CLASSES_ROOT
, szKey
, szExtensionA
, REG_SZ
, lpszExt
, dwLen
))
2142 /*************************************************************************
2145 * Unicode version of RegisterExtensionForMIMETypeA.
2147 BOOL WINAPI
RegisterExtensionForMIMETypeW(LPCWSTR lpszExt
, LPCWSTR lpszType
)
2150 WCHAR szKey
[MAX_PATH
];
2152 TRACE("(%s,%s)\n", debugstr_w(lpszExt
), debugstr_w(lpszType
));
2154 /* Get the full path to the key */
2155 if (!GetMIMETypeSubKeyW(lpszType
, szKey
, MAX_PATH
)) /* Get full path to the key */
2158 dwLen
= (lstrlenW(lpszExt
) + 1) * sizeof(WCHAR
);
2160 if (SHSetValueW(HKEY_CLASSES_ROOT
, szKey
, szExtensionW
, REG_SZ
, lpszExt
, dwLen
))
2165 /*************************************************************************
2168 * Delete a file extension from a MIME content type.
2171 * lpszType [I] Content type to delete the extension for
2174 * Success: TRUE. The file extension is deleted from the registry.
2175 * Failure: FALSE. The extension may have been removed but the key remains.
2178 * If deleting the extension leaves an orphan key, the key is removed also.
2180 BOOL WINAPI
UnregisterExtensionForMIMETypeA(LPCSTR lpszType
)
2182 char szKey
[MAX_PATH
];
2184 TRACE("(%s)\n", debugstr_a(lpszType
));
2186 if (!GetMIMETypeSubKeyA(lpszType
, szKey
, MAX_PATH
)) /* Get full path to the key */
2189 if (!SHDeleteValueA(HKEY_CLASSES_ROOT
, szKey
, szExtensionA
))
2192 if (!SHDeleteOrphanKeyA(HKEY_CLASSES_ROOT
, szKey
))
2197 /*************************************************************************
2200 * Unicode version of UnregisterExtensionForMIMETypeA.
2202 BOOL WINAPI
UnregisterExtensionForMIMETypeW(LPCWSTR lpszType
)
2204 WCHAR szKey
[MAX_PATH
];
2206 TRACE("(%s)\n", debugstr_w(lpszType
));
2208 if (!GetMIMETypeSubKeyW(lpszType
, szKey
, MAX_PATH
)) /* Get full path to the key */
2211 if (!SHDeleteValueW(HKEY_CLASSES_ROOT
, szKey
, szExtensionW
))
2214 if (!SHDeleteOrphanKeyW(HKEY_CLASSES_ROOT
, szKey
))
2219 /*************************************************************************
2220 * SHRegDuplicateHKey [SHLWAPI.@]
2222 * Create a duplicate of a registry handle.
2225 * hKey [I] key to duplicate.
2228 * A new handle pointing to the same key as hKey.
2230 HKEY WINAPI
SHRegDuplicateHKey(HKEY hKey
)
2234 RegOpenKeyExA(hKey
, 0, 0, MAXIMUM_ALLOWED
, &newKey
);
2235 TRACE("new key is %p\n", newKey
);
2240 /*************************************************************************
2241 * SHCopyKeyA [SHLWAPI.@]
2243 * Copy a key and its values/sub keys to another location.
2246 * hKeySrc [I] Source key to copy from
2247 * lpszSrcSubKey [I] Sub key under hKeySrc, or NULL to use hKeySrc directly
2248 * hKeyDst [I] Destination key
2249 * dwReserved [I] Reserved, must be 0
2252 * Success: ERROR_SUCCESS. The key is copied to the destination key.
2253 * Failure: A standard windows error code.
2256 * If hKeyDst is a key under hKeySrc, this function will misbehave
2257 * (It will loop until out of stack, or the registry is full). This
2258 * bug is present in Win32 also.
2260 DWORD WINAPI
SHCopyKeyA(HKEY hKeySrc
, LPCSTR lpszSrcSubKey
, HKEY hKeyDst
, DWORD dwReserved
)
2262 WCHAR szSubKeyW
[MAX_PATH
];
2264 TRACE("(hkey=%p,%s,%p08x,%d)\n", hKeySrc
, debugstr_a(lpszSrcSubKey
), hKeyDst
, dwReserved
);
2267 MultiByteToWideChar(0, 0, lpszSrcSubKey
, -1, szSubKeyW
, MAX_PATH
);
2269 return SHCopyKeyW(hKeySrc
, lpszSrcSubKey
? szSubKeyW
: NULL
, hKeyDst
, dwReserved
);
2272 /*************************************************************************
2273 * SHCopyKeyW [SHLWAPI.@]
2277 DWORD WINAPI
SHCopyKeyW(HKEY hKeySrc
, LPCWSTR lpszSrcSubKey
, HKEY hKeyDst
, DWORD dwReserved
)
2279 DWORD dwKeyCount
= 0, dwValueCount
= 0, dwMaxKeyLen
= 0;
2280 DWORD dwMaxValueLen
= 0, dwMaxDataLen
= 0, i
;
2282 LPVOID lpBuff
= (LPVOID
)buff
;
2283 WCHAR szName
[MAX_PATH
], *lpszName
= szName
;
2286 TRACE("hkey=%p,%s,%p08x,%d)\n", hKeySrc
, debugstr_w(lpszSrcSubKey
), hKeyDst
, dwReserved
);
2288 if(!hKeyDst
|| !hKeySrc
)
2289 dwRet
= ERROR_INVALID_PARAMETER
;
2292 /* Open source key */
2294 dwRet
= RegOpenKeyExW(hKeySrc
, lpszSrcSubKey
, 0, KEY_ALL_ACCESS
, &hKeySrc
);
2297 hKeyDst
= NULL
; /* Don't close this key since we didn't open it */
2300 /* Get details about sub keys and values */
2301 dwRet
= RegQueryInfoKeyW(hKeySrc
, NULL
, NULL
, NULL
, &dwKeyCount
, &dwMaxKeyLen
,
2302 NULL
, &dwValueCount
, &dwMaxValueLen
, &dwMaxDataLen
,
2306 if (dwMaxValueLen
> dwMaxKeyLen
)
2307 dwMaxKeyLen
= dwMaxValueLen
; /* Get max size for key/value names */
2309 if (dwMaxKeyLen
++ > MAX_PATH
- 1)
2310 lpszName
= HeapAlloc(GetProcessHeap(), 0, dwMaxKeyLen
* sizeof(WCHAR
));
2312 if (dwMaxDataLen
> sizeof(buff
))
2313 lpBuff
= HeapAlloc(GetProcessHeap(), 0, dwMaxDataLen
);
2315 if (!lpszName
|| !lpBuff
)
2316 dwRet
= ERROR_NOT_ENOUGH_MEMORY
;
2321 /* Copy all the sub keys */
2322 for(i
= 0; i
< dwKeyCount
&& !dwRet
; i
++)
2324 HKEY hSubKeySrc
, hSubKeyDst
;
2325 DWORD dwSize
= dwMaxKeyLen
;
2327 dwRet
= RegEnumKeyExW(hKeySrc
, i
, lpszName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
2331 /* Open source sub key */
2332 dwRet
= RegOpenKeyExW(hKeySrc
, lpszName
, 0, KEY_READ
, &hSubKeySrc
);
2336 /* Create destination sub key */
2337 dwRet
= RegCreateKeyW(hKeyDst
, lpszName
, &hSubKeyDst
);
2341 /* Recursively copy keys and values from the sub key */
2342 dwRet
= SHCopyKeyW(hSubKeySrc
, NULL
, hSubKeyDst
, 0);
2343 RegCloseKey(hSubKeyDst
);
2346 RegCloseKey(hSubKeySrc
);
2350 /* Copy all the values in this key */
2351 for (i
= 0; i
< dwValueCount
&& !dwRet
; i
++)
2353 DWORD dwNameSize
= dwMaxKeyLen
, dwType
, dwLen
= dwMaxDataLen
;
2355 dwRet
= RegEnumValueW(hKeySrc
, i
, lpszName
, &dwNameSize
, NULL
, &dwType
, lpBuff
, &dwLen
);
2358 dwRet
= SHSetValueW(hKeyDst
, NULL
, lpszName
, dwType
, lpBuff
, dwLen
);
2361 /* Free buffers if allocated */
2362 if (lpszName
!= szName
)
2363 HeapFree(GetProcessHeap(), 0, lpszName
);
2365 HeapFree(GetProcessHeap(), 0, lpBuff
);
2367 if (lpszSrcSubKey
&& hKeyDst
)
2368 RegCloseKey(hKeyDst
);
2373 * The following functions are ORDINAL ONLY:
2376 /*************************************************************************
2379 * Read an integer value from the registry, falling back to a default.
2382 * hKey [I] Registry key to read from
2383 * lpszValue [I] Value name to read
2384 * iDefault [I] Default value to return
2387 * The value contained in the given registry value if present, otherwise
2390 int WINAPI
SHRegGetIntW(HKEY hKey
, LPCWSTR lpszValue
, int iDefault
)
2392 TRACE("(%p,%s,%d)\n", hKey
, debugstr_w(lpszValue
), iDefault
);
2397 DWORD dwSize
= sizeof(szBuff
);
2399 SHQueryValueExW(hKey
, lpszValue
, 0, 0, szBuff
, &dwSize
);
2401 if(*szBuff
>= '0' && *szBuff
<= '9')
2402 return StrToIntW(szBuff
);
2407 /*************************************************************************
2410 * Create or open an explorer ClassId Key.
2413 * guid [I] Explorer ClassId key to open
2414 * lpszValue [I] Value name under the ClassId Key
2415 * bUseHKCU [I] TRUE=Use HKEY_CURRENT_USER, FALSE=Use HKEY_CLASSES_ROOT
2416 * bCreate [I] TRUE=Create the key if it doesn't exist, FALSE=Don't
2417 * phKey [O] Destination for the resulting key handle
2420 * Success: S_OK. phKey contains the resulting registry handle.
2421 * Failure: An HRESULT error code indicating the problem.
2423 HRESULT WINAPI
SHRegGetCLSIDKeyA(REFGUID guid
, LPCSTR lpszValue
, BOOL bUseHKCU
, BOOL bCreate
, PHKEY phKey
)
2425 WCHAR szValue
[MAX_PATH
];
2428 MultiByteToWideChar(CP_ACP
, 0, lpszValue
, -1, szValue
, sizeof(szValue
)/sizeof(WCHAR
));
2430 return SHRegGetCLSIDKeyW(guid
, lpszValue
? szValue
: NULL
, bUseHKCU
, bCreate
, phKey
);
2433 /*************************************************************************
2436 * Unicode version of SHRegGetCLSIDKeyA.
2438 HRESULT WINAPI
SHRegGetCLSIDKeyW(REFGUID guid
, LPCWSTR lpszValue
, BOOL bUseHKCU
,
2439 BOOL bCreate
, PHKEY phKey
)
2441 static const WCHAR szClassIdKey
[] = { 'S','o','f','t','w','a','r','e','\\',
2442 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
2443 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2444 'E','x','p','l','o','r','e','r','\\','C','L','S','I','D','\\' };
2445 #define szClassIdKeyLen (sizeof(szClassIdKey)/sizeof(WCHAR))
2446 WCHAR szKey
[MAX_PATH
];
2450 /* Create the key string */
2451 memcpy(szKey
, szClassIdKey
, sizeof(szClassIdKey
));
2452 SHStringFromGUIDW(guid
, szKey
+ szClassIdKeyLen
, 39); /* Append guid */
2456 szKey
[szClassIdKeyLen
+ 39] = '\\';
2457 strcpyW(szKey
+ szClassIdKeyLen
+ 40, lpszValue
); /* Append value name */
2460 hkey
= bUseHKCU
? HKEY_CURRENT_USER
: HKEY_CLASSES_ROOT
;
2463 dwRet
= RegCreateKeyW(hkey
, szKey
, phKey
);
2465 dwRet
= RegOpenKeyExW(hkey
, szKey
, 0, KEY_READ
, phKey
);
2467 return dwRet
? HRESULT_FROM_WIN32(dwRet
) : S_OK
;
2470 /*************************************************************************
2471 * SHRegisterValidateTemplate [SHLWAPI.@]
2473 * observed from the ie 5.5 installer:
2474 * - allocates a buffer with the size of the given file
2475 * - read the file content into the buffer
2476 * - creates the key szTemplateKey
2477 * - sets "205523652929647911071668590831910975402"=dword:00002e37 at
2481 * filename [I] An existing file its content is read into an allocated
2486 * Success: ERROR_SUCCESS.
2488 HRESULT WINAPI
SHRegisterValidateTemplate(LPCWSTR filename
, BOOL unknown
)
2490 /* static const WCHAR szTemplateKey[] = { 'S','o','f','t','w','a','r','e','\\',
2491 * 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
2492 * 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2493 * 'E','x','p','l','o','r','e','r','\\',
2494 * 'T','e','m','p','l','a','t','e','R','e','g','i','s','t','r','y',0 };
2496 FIXME("stub: %s, %08x\n", debugstr_w(filename
), unknown
);