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
24 /* Key/Value names for MIME content types */
25 static const char lpszContentTypeA
[] = "Content Type";
26 static const WCHAR lpszContentTypeW
[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
28 static const char szMimeDbContentA
[] = "MIME\\Database\\Content Type\\";
29 static const WCHAR szMimeDbContentW
[] = { 'M', 'I', 'M','E','\\',
30 'D','a','t','a','b','a','s','e','\\','C','o','n','t','e','n','t',
31 ' ','T','y','p','e','\\', 0 };
32 static const DWORD dwLenMimeDbContent
= 27; /* strlen of szMimeDbContentA/W */
34 static const char szExtensionA
[] = "Extension";
35 static const WCHAR szExtensionW
[] = { 'E', 'x', 't','e','n','s','i','o','n','\0' };
37 /* internal structure of what the HUSKEY points to */
39 HKEY HKCUstart
; /* Start key in CU hive */
40 HKEY HKCUkey
; /* Opened key in CU hive */
41 HKEY HKLMstart
; /* Start key in LM hive */
42 HKEY HKLMkey
; /* Opened key in LM hive */
43 WCHAR lpszPath
[MAX_PATH
];
44 } SHUSKEY
, *LPSHUSKEY
;
46 INT WINAPI
SHStringFromGUIDW(REFGUID
,LPWSTR
,INT
);
47 HRESULT WINAPI
SHRegGetCLSIDKeyW(REFGUID
,LPCWSTR
,BOOL
,BOOL
,PHKEY
);
51 #define REG_HKLM FALSE
52 /*************************************************************************
53 * REG_GetHKEYFromHUSKEY
55 * Function: Return the proper registry key from the HUSKEY structure
56 * also allow special predefined values.
58 static HKEY
REG_GetHKEYFromHUSKEY(HUSKEY hUSKey
, BOOL which
)
61 LPSHUSKEY mihk
= hUSKey
;
63 if ((test
== HKEY_CLASSES_ROOT
) ||
64 (test
== HKEY_CURRENT_CONFIG
) ||
65 (test
== HKEY_CURRENT_USER
) ||
66 (test
== HKEY_DYN_DATA
) ||
67 (test
== HKEY_LOCAL_MACHINE
) ||
68 (test
== HKEY_PERFORMANCE_DATA
) ||
69 /* FIXME: need to define for Win2k, ME, XP
70 * (test == HKEY_PERFORMANCE_TEXT) ||
71 * (test == HKEY_PERFORMANCE_NLSTEXT) ||
73 (test
== HKEY_USERS
)) return test
;
74 if (which
== REG_HKCU
) return mihk
->HKCUkey
;
79 /*************************************************************************
80 * SHRegOpenUSKeyA [SHLWAPI.@]
82 * Open a user-specific registry key.
85 * Path [I] Key name to open
86 * AccessType [I] Access type
87 * hRelativeUSKey [I] Relative user key
88 * phNewUSKey [O] Destination for created key
89 * fIgnoreHKCU [I] TRUE=Don't check HKEY_CURRENT_USER
92 * Success: ERROR_SUCCESS
93 * Failure: An error code from RegOpenKeyExA().
95 LONG WINAPI
SHRegOpenUSKeyA(LPCSTR Path
, REGSAM AccessType
, HUSKEY hRelativeUSKey
,
96 PHUSKEY phNewUSKey
, BOOL fIgnoreHKCU
)
98 WCHAR szPath
[MAX_PATH
];
101 MultiByteToWideChar(CP_ACP
, 0, Path
, -1, szPath
, MAX_PATH
);
103 return SHRegOpenUSKeyW(Path
? szPath
: NULL
, AccessType
, hRelativeUSKey
,
104 phNewUSKey
, fIgnoreHKCU
);
107 /*************************************************************************
108 * SHRegOpenUSKeyW [SHLWAPI.@]
110 * See SHRegOpenUSKeyA.
112 LONG WINAPI
SHRegOpenUSKeyW(LPCWSTR Path
, REGSAM AccessType
, HUSKEY hRelativeUSKey
,
113 PHUSKEY phNewUSKey
, BOOL fIgnoreHKCU
)
115 LONG ret2
, ret1
= ~ERROR_SUCCESS
;
118 TRACE("(%s,0x%x,%p,%p,%d)\n", debugstr_w(Path
),(LONG
)AccessType
,
119 hRelativeUSKey
, phNewUSKey
, fIgnoreHKCU
);
124 /* Create internal HUSKEY */
125 hKey
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*hKey
));
126 lstrcpynW(hKey
->lpszPath
, Path
, sizeof(hKey
->lpszPath
)/sizeof(WCHAR
));
130 hKey
->HKCUstart
= SHRegDuplicateHKey(REG_GetHKEYFromHUSKEY(hRelativeUSKey
, REG_HKCU
));
131 hKey
->HKLMstart
= SHRegDuplicateHKey(REG_GetHKEYFromHUSKEY(hRelativeUSKey
, REG_HKLM
));
133 /* FIXME: if either of these keys is NULL, create the start key from
134 * the relative keys start+path
139 hKey
->HKCUstart
= HKEY_CURRENT_USER
;
140 hKey
->HKLMstart
= HKEY_LOCAL_MACHINE
;
145 ret1
= RegOpenKeyExW(hKey
->HKCUstart
, hKey
->lpszPath
, 0, AccessType
, &hKey
->HKCUkey
);
150 ret2
= RegOpenKeyExW(hKey
->HKLMstart
, hKey
->lpszPath
, 0, AccessType
, &hKey
->HKLMkey
);
155 TRACE("one or more opens failed: HKCU=%d HKLM=%d\n", ret1
, ret2
);
159 /* Neither open succeeded: fail */
160 SHRegCloseUSKey(hKey
);
164 TRACE("HUSKEY=%p\n", hKey
);
167 return ERROR_SUCCESS
;
170 /*************************************************************************
171 * SHRegCloseUSKey [SHLWAPI.@]
173 * Close a user-specific registry key
176 * Success: ERROR_SUCCESS
177 * Failure: An error code from RegCloseKey().
179 LONG WINAPI
SHRegCloseUSKey(
180 HUSKEY hUSKey
) /* [I] Key to close */
182 LPSHUSKEY hKey
= hUSKey
;
183 LONG ret
= ERROR_SUCCESS
;
186 ret
= RegCloseKey(hKey
->HKCUkey
);
187 if (hKey
->HKCUstart
&& hKey
->HKCUstart
!= HKEY_CURRENT_USER
)
188 ret
= RegCloseKey(hKey
->HKCUstart
);
190 ret
= RegCloseKey(hKey
->HKLMkey
);
191 if (hKey
->HKLMstart
&& hKey
->HKLMstart
!= HKEY_LOCAL_MACHINE
)
192 ret
= RegCloseKey(hKey
->HKLMstart
);
194 HeapFree(GetProcessHeap(), 0, hKey
);
198 /*************************************************************************
199 * SHRegCreateUSKeyA [SHLWAPI.@]
201 * Create or open a user-specific registry key.
204 * pszPath [I] Key name to create or open.
205 * samDesired [I] Wanted security access.
206 * hRelativeUSKey [I] Base path if pszPath is relative. NULL otherwise.
207 * phNewUSKey [O] Receives a handle to the new or opened key.
208 * dwFlags [I] Base key under which the key should be opened.
211 * Success: ERROR_SUCCESS
212 * Failure: Nonzero error code from winerror.h
214 LONG WINAPI
SHRegCreateUSKeyA(LPCSTR pszPath
, REGSAM samDesired
, HUSKEY hRelativeUSKey
,
215 PHUSKEY phNewUSKey
, DWORD dwFlags
)
217 FIXME("(%s, 0x%08x, %p, %p, 0x%08x) stub\n", debugstr_a(pszPath
), samDesired
,
218 hRelativeUSKey
, phNewUSKey
, dwFlags
);
219 return ERROR_SUCCESS
;
222 /*************************************************************************
223 * SHRegCreateUSKeyW [SHLWAPI.@]
225 * See SHRegCreateUSKeyA.
227 LONG WINAPI
SHRegCreateUSKeyW(LPCWSTR path
, REGSAM samDesired
, HUSKEY relative_key
,
228 PHUSKEY new_uskey
, DWORD flags
)
230 LONG ret
= ERROR_CALL_NOT_IMPLEMENTED
;
233 TRACE("(%s, 0x%08x, %p, %p, 0x%08x)\n", debugstr_w(path
), samDesired
,
234 relative_key
, new_uskey
, flags
);
236 if (!new_uskey
) return ERROR_INVALID_PARAMETER
;
240 if (flags
& ~SHREGSET_FORCE_HKCU
)
242 FIXME("unsupported flags 0x%08x\n", flags
);
243 return ERROR_SUCCESS
;
246 ret_key
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ret_key
));
247 lstrcpynW(ret_key
->lpszPath
, path
, sizeof(ret_key
->lpszPath
)/sizeof(WCHAR
));
251 ret_key
->HKCUstart
= SHRegDuplicateHKey(REG_GetHKEYFromHUSKEY(relative_key
, REG_HKCU
));
252 ret_key
->HKLMstart
= SHRegDuplicateHKey(REG_GetHKEYFromHUSKEY(relative_key
, REG_HKLM
));
256 ret_key
->HKCUstart
= HKEY_CURRENT_USER
;
257 ret_key
->HKLMstart
= HKEY_LOCAL_MACHINE
;
260 if (flags
& SHREGSET_FORCE_HKCU
)
262 ret
= RegCreateKeyExW(ret_key
->HKCUstart
, path
, 0, NULL
, 0, samDesired
, NULL
, &ret_key
->HKCUkey
, NULL
);
263 if (ret
== ERROR_SUCCESS
)
264 *new_uskey
= ret_key
;
266 HeapFree(GetProcessHeap(), 0, ret_key
);
272 /*************************************************************************
273 * SHRegDeleteEmptyUSKeyA [SHLWAPI.@]
275 * Delete an empty user-specific registry key.
278 * hUSKey [I] Handle to an open registry key.
279 * pszValue [I] Empty key name.
280 * delRegFlags [I] Flag that specifies the base from which to delete
284 * Success: ERROR_SUCCESS
285 * Failure: Nonzero error code from winerror.h
287 LONG WINAPI
SHRegDeleteEmptyUSKeyA(HUSKEY hUSKey
, LPCSTR pszValue
, SHREGDEL_FLAGS delRegFlags
)
289 FIXME("(%p, %s, 0x%08x) stub\n", hUSKey
, debugstr_a(pszValue
), delRegFlags
);
290 return ERROR_SUCCESS
;
293 /*************************************************************************
294 * SHRegDeleteEmptyUSKeyW [SHLWAPI.@]
296 * See SHRegDeleteEmptyUSKeyA.
298 LONG WINAPI
SHRegDeleteEmptyUSKeyW(HUSKEY hUSKey
, LPCWSTR pszValue
, SHREGDEL_FLAGS delRegFlags
)
300 FIXME("(%p, %s, 0x%08x) stub\n", hUSKey
, debugstr_w(pszValue
), delRegFlags
);
301 return ERROR_SUCCESS
;
304 /*************************************************************************
305 * SHRegDeleteUSValueA [SHLWAPI.@]
307 * Delete a user-specific registry value.
310 * hUSKey [I] Handle to an open registry key.
311 * pszValue [I] Specifies the value to delete.
312 * delRegFlags [I] Flag that specifies the base of the key from which to
316 * Success: ERROR_SUCCESS
317 * Failure: Nonzero error code from winerror.h
319 LONG WINAPI
SHRegDeleteUSValueA(HUSKEY hUSKey
, LPCSTR pszValue
, SHREGDEL_FLAGS delRegFlags
)
321 FIXME("(%p, %s, 0x%08x) stub\n", hUSKey
, debugstr_a(pszValue
), delRegFlags
);
322 return ERROR_SUCCESS
;
325 /*************************************************************************
326 * SHRegDeleteUSValueW [SHLWAPI.@]
328 * See SHRegDeleteUSValueA.
330 LONG WINAPI
SHRegDeleteUSValueW(HUSKEY hUSKey
, LPCWSTR pszValue
, SHREGDEL_FLAGS delRegFlags
)
332 FIXME("(%p, %s, 0x%08x) stub\n", hUSKey
, debugstr_w(pszValue
), delRegFlags
);
333 return ERROR_SUCCESS
;
336 /*************************************************************************
337 * SHRegEnumUSValueA [SHLWAPI.@]
339 * Enumerate values of a specified registry key.
342 * hUSKey [I] Handle to an open registry key.
343 * dwIndex [I] Index of the value to be retrieved.
344 * pszValueName [O] Buffer to receive the value name.
345 * pcchValueNameLen [I] Size of pszValueName in characters.
346 * pdwType [O] Receives data type of the value.
347 * pvData [O] Receives value data. May be NULL.
348 * pcbData [I/O] Size of pvData in bytes.
349 * enumRegFlags [I] Flag that specifies the base key under which to
353 * Success: ERROR_SUCCESS
354 * Failure: Nonzero error code from winerror.h
356 LONG WINAPI
SHRegEnumUSValueA(HUSKEY hUSKey
, DWORD dwIndex
, LPSTR pszValueName
,
357 LPDWORD pcchValueNameLen
, LPDWORD pdwType
, LPVOID pvData
,
358 LPDWORD pcbData
, SHREGENUM_FLAGS enumRegFlags
)
362 TRACE("(%p, 0x%08x, %p, %p, %p, %p, %p, 0x%08x)\n", hUSKey
, dwIndex
,
363 pszValueName
, pcchValueNameLen
, pdwType
, pvData
, pcbData
, enumRegFlags
);
365 if (((enumRegFlags
== SHREGENUM_HKCU
) ||
366 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
367 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKCU
))) {
368 return RegEnumValueA(dokey
, dwIndex
, pszValueName
, pcchValueNameLen
,
369 NULL
, pdwType
, pvData
, pcbData
);
372 if (((enumRegFlags
== SHREGENUM_HKLM
) ||
373 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
374 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKLM
))) {
375 return RegEnumValueA(dokey
, dwIndex
, pszValueName
, pcchValueNameLen
,
376 NULL
, pdwType
, pvData
, pcbData
);
378 FIXME("no support for SHREGENUM_BOTH\n");
379 return ERROR_INVALID_FUNCTION
;
382 /*************************************************************************
383 * SHRegEnumUSValueW [SHLWAPI.@]
385 * See SHRegEnumUSValueA.
387 LONG WINAPI
SHRegEnumUSValueW(HUSKEY hUSKey
, DWORD dwIndex
, LPWSTR pszValueName
,
388 LPDWORD pcchValueNameLen
, LPDWORD pdwType
, LPVOID pvData
,
389 LPDWORD pcbData
, SHREGENUM_FLAGS enumRegFlags
)
393 TRACE("(%p, 0x%08x, %p, %p, %p, %p, %p, 0x%08x)\n", hUSKey
, dwIndex
,
394 pszValueName
, pcchValueNameLen
, pdwType
, pvData
, pcbData
, enumRegFlags
);
396 if (((enumRegFlags
== SHREGENUM_HKCU
) ||
397 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
398 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKCU
))) {
399 return RegEnumValueW(dokey
, dwIndex
, pszValueName
, pcchValueNameLen
,
400 NULL
, pdwType
, pvData
, pcbData
);
403 if (((enumRegFlags
== SHREGENUM_HKLM
) ||
404 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
405 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKLM
))) {
406 return RegEnumValueW(dokey
, dwIndex
, pszValueName
, pcchValueNameLen
,
407 NULL
, pdwType
, pvData
, pcbData
);
409 FIXME("no support for SHREGENUM_BOTH\n");
410 return ERROR_INVALID_FUNCTION
;
413 /*************************************************************************
414 * SHRegQueryUSValueA [SHLWAPI.@]
416 * Query a user-specific registry value.
419 * Success: ERROR_SUCCESS
420 * Failure: An error code from RegQueryValueExA().
422 LONG WINAPI
SHRegQueryUSValueA(
423 HUSKEY hUSKey
, /* [I] Key to query */
424 LPCSTR pszValue
, /* [I] Value name under hUSKey */
425 LPDWORD pdwType
, /* [O] Destination for value type */
426 LPVOID pvData
, /* [O] Destination for value data */
427 LPDWORD pcbData
, /* [O] Destination for value length */
428 BOOL fIgnoreHKCU
, /* [I] TRUE=Don't check HKEY_CURRENT_USER */
429 LPVOID pvDefaultData
, /* [I] Default data if pszValue does not exist */
430 DWORD dwDefaultDataSize
) /* [I] Length of pvDefaultData */
432 LONG ret
= ~ERROR_SUCCESS
;
437 /* if user wants HKCU, and it exists, then try it */
438 if (!fIgnoreHKCU
&& (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKCU
))) {
439 ret
= RegQueryValueExA(dokey
,
440 pszValue
, 0, pdwType
, pvData
, pcbData
);
441 TRACE("HKCU RegQueryValue returned %08x\n", ret
);
444 /* if HKCU did not work and HKLM exists, then try it */
445 if ((ret
!= ERROR_SUCCESS
) &&
446 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKLM
))) {
447 ret
= RegQueryValueExA(dokey
,
448 pszValue
, 0, pdwType
, pvData
, pcbData
);
449 TRACE("HKLM RegQueryValue returned %08x\n", ret
);
452 /* if neither worked, and default data exists, then use it */
453 if (ret
!= ERROR_SUCCESS
) {
454 if (pvDefaultData
&& (dwDefaultDataSize
!= 0)) {
455 maxmove
= (dwDefaultDataSize
>= *pcbData
) ? *pcbData
: dwDefaultDataSize
;
458 for(i
=0; i
<maxmove
; i
++) *dst
++ = *src
++;
460 TRACE("setting default data\n");
468 /*************************************************************************
469 * SHRegQueryUSValueW [SHLWAPI.@]
471 * See SHRegQueryUSValueA.
473 LONG WINAPI
SHRegQueryUSValueW(
480 LPVOID pvDefaultData
,
481 DWORD dwDefaultDataSize
)
483 LONG ret
= ~ERROR_SUCCESS
;
488 /* if user wants HKCU, and it exists, then try it */
489 if (!fIgnoreHKCU
&& (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKCU
))) {
490 ret
= RegQueryValueExW(dokey
,
491 pszValue
, 0, pdwType
, pvData
, pcbData
);
492 TRACE("HKCU RegQueryValue returned %08x\n", ret
);
495 /* if HKCU did not work and HKLM exists, then try it */
496 if ((ret
!= ERROR_SUCCESS
) &&
497 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKLM
))) {
498 ret
= RegQueryValueExW(dokey
,
499 pszValue
, 0, pdwType
, pvData
, pcbData
);
500 TRACE("HKLM RegQueryValue returned %08x\n", ret
);
503 /* if neither worked, and default data exists, then use it */
504 if (ret
!= ERROR_SUCCESS
) {
505 if (pvDefaultData
&& (dwDefaultDataSize
!= 0)) {
506 maxmove
= (dwDefaultDataSize
>= *pcbData
) ? *pcbData
: dwDefaultDataSize
;
509 for(i
=0; i
<maxmove
; i
++) *dst
++ = *src
++;
511 TRACE("setting default data\n");
518 /*************************************************************************
519 * SHRegGetUSValueA [SHLWAPI.@]
521 * Get a user-specific registry value.
524 * Success: ERROR_SUCCESS
525 * Failure: An error code from SHRegOpenUSKeyA() or SHRegQueryUSValueA().
528 * This function opens pSubKey, queries the value, and then closes the key.
530 LONG WINAPI
SHRegGetUSValueA(
531 LPCSTR pSubKey
, /* [I] Key name to open */
532 LPCSTR pValue
, /* [I] Value name to open */
533 LPDWORD pwType
, /* [O] Destination for the type of the value */
534 LPVOID pvData
, /* [O] Destination for the value */
535 LPDWORD pcbData
, /* [I] Destination for the length of the value **/
536 BOOL flagIgnoreHKCU
, /* [I] TRUE=Don't check HKEY_CURRENT_USER */
537 LPVOID pDefaultData
, /* [I] Default value if it doesn't exist */
538 DWORD wDefaultDataSize
) /* [I] Length of pDefaultData */
543 if (!pvData
|| !pcbData
) return ERROR_INVALID_FUNCTION
; /* FIXME:wrong*/
544 TRACE("key '%s', value '%s', datalen %d, %s\n",
545 debugstr_a(pSubKey
), debugstr_a(pValue
), *pcbData
,
546 (flagIgnoreHKCU
) ? "Ignoring HKCU" : "Tries HKCU then HKLM");
548 ret
= SHRegOpenUSKeyA(pSubKey
, 0x1, 0, &myhuskey
, flagIgnoreHKCU
);
549 if (ret
== ERROR_SUCCESS
) {
550 ret
= SHRegQueryUSValueA(myhuskey
, pValue
, pwType
, pvData
,
551 pcbData
, flagIgnoreHKCU
, pDefaultData
,
553 SHRegCloseUSKey(myhuskey
);
558 /*************************************************************************
559 * SHRegGetUSValueW [SHLWAPI.@]
561 * See SHRegGetUSValueA.
563 LONG WINAPI
SHRegGetUSValueW(
571 DWORD wDefaultDataSize
)
576 if (!pvData
|| !pcbData
) return ERROR_INVALID_FUNCTION
; /* FIXME:wrong*/
577 TRACE("key '%s', value '%s', datalen %d, %s\n",
578 debugstr_w(pSubKey
), debugstr_w(pValue
), *pcbData
,
579 (flagIgnoreHKCU
) ? "Ignoring HKCU" : "Tries HKCU then HKLM");
581 ret
= SHRegOpenUSKeyW(pSubKey
, 0x1, 0, &myhuskey
, flagIgnoreHKCU
);
582 if (ret
== ERROR_SUCCESS
) {
583 ret
= SHRegQueryUSValueW(myhuskey
, pValue
, pwType
, pvData
,
584 pcbData
, flagIgnoreHKCU
, pDefaultData
,
586 SHRegCloseUSKey(myhuskey
);
591 /*************************************************************************
592 * SHRegSetUSValueA [SHLWAPI.@]
594 * Set a user-specific registry value.
597 * pszSubKey [I] Name of key to set the value in
598 * pszValue [I] Name of value under pszSubKey to set the value in
599 * dwType [I] Type of the value
600 * pvData [I] Data to set as the value
601 * cbData [I] length of pvData
602 * dwFlags [I] SHREGSET_ flags from "shlwapi.h"
605 * Success: ERROR_SUCCESS
606 * Failure: An error code from SHRegOpenUSKeyA() or SHRegWriteUSValueA(), or
607 * ERROR_INVALID_FUNCTION if pvData is NULL.
610 * This function opens pszSubKey, sets the value, and then closes the key.
612 LONG WINAPI
SHRegSetUSValueA(LPCSTR pszSubKey
, LPCSTR pszValue
, DWORD dwType
,
613 LPVOID pvData
, DWORD cbData
, DWORD dwFlags
)
615 BOOL ignoreHKCU
= TRUE
;
619 TRACE("(%s,%s,%d,%p,%d,0x%08x\n", debugstr_a(pszSubKey
), debugstr_a(pszValue
),
620 dwType
, pvData
, cbData
, dwFlags
);
623 return ERROR_INVALID_FUNCTION
;
625 if (dwFlags
& SHREGSET_HKCU
|| dwFlags
& SHREGSET_FORCE_HKCU
)
628 ret
= SHRegOpenUSKeyA(pszSubKey
, KEY_ALL_ACCESS
, 0, &hkey
, ignoreHKCU
);
629 if (ret
== ERROR_SUCCESS
)
631 ret
= SHRegWriteUSValueA(hkey
, pszValue
, dwType
, pvData
, cbData
, dwFlags
);
632 SHRegCloseUSKey(hkey
);
637 /*************************************************************************
638 * SHRegSetUSValueW [SHLWAPI.@]
640 * See SHRegSetUSValueA.
642 LONG WINAPI
SHRegSetUSValueW(LPCWSTR pszSubKey
, LPCWSTR pszValue
, DWORD dwType
,
643 LPVOID pvData
, DWORD cbData
, DWORD dwFlags
)
645 BOOL ignoreHKCU
= TRUE
;
649 TRACE("(%s,%s,%d,%p,%d,0x%08x\n", debugstr_w(pszSubKey
), debugstr_w(pszValue
),
650 dwType
, pvData
, cbData
, dwFlags
);
653 return ERROR_INVALID_FUNCTION
;
655 if (dwFlags
& SHREGSET_HKCU
|| dwFlags
& SHREGSET_FORCE_HKCU
)
658 ret
= SHRegOpenUSKeyW(pszSubKey
, KEY_ALL_ACCESS
, 0, &hkey
, ignoreHKCU
);
659 if (ret
== ERROR_SUCCESS
)
661 ret
= SHRegWriteUSValueW(hkey
, pszValue
, dwType
, pvData
, cbData
, dwFlags
);
662 SHRegCloseUSKey(hkey
);
667 /*************************************************************************
668 * SHRegGetBoolUSValueA [SHLWAPI.@]
670 * Get a user-specific registry boolean value.
673 * Success: ERROR_SUCCESS
674 * Failure: An error code from SHRegOpenUSKeyA() or SHRegQueryUSValueA().
677 * This function opens pszSubKey, queries the value, and then closes the key.
679 * Boolean values are one of the following:
680 * True: YES,TRUE,non-zero
683 BOOL WINAPI
SHRegGetBoolUSValueA(
684 LPCSTR pszSubKey
, /* [I] Key name to open */
685 LPCSTR pszValue
, /* [I] Value name to open */
686 BOOL fIgnoreHKCU
, /* [I] TRUE=Don't check HKEY_CURRENT_USER */
687 BOOL fDefault
) /* [I] Default value to use if pszValue is not present */
689 DWORD type
, datalen
, work
;
693 TRACE("key '%s', value '%s', %s\n",
694 debugstr_a(pszSubKey
), debugstr_a(pszValue
),
695 (fIgnoreHKCU
) ? "Ignoring HKCU" : "Tries HKCU then HKLM");
697 datalen
= sizeof(data
)-1;
698 if (!SHRegGetUSValueA( pszSubKey
, pszValue
, &type
,
700 fIgnoreHKCU
, 0, 0)) {
701 /* process returned data via type into bool */
704 data
[9] = '\0'; /* set end of string */
705 if (lstrcmpiA(data
, "YES") == 0) ret
= TRUE
;
706 if (lstrcmpiA(data
, "TRUE") == 0) ret
= TRUE
;
707 if (lstrcmpiA(data
, "NO") == 0) ret
= FALSE
;
708 if (lstrcmpiA(data
, "FALSE") == 0) ret
= FALSE
;
711 work
= *(LPDWORD
)data
;
716 ret
= (data
[0] != '\0');
720 FIXME("Unsupported registry data type %d\n", type
);
723 TRACE("got value (type=%d), returning <%s>\n", type
,
724 (ret
) ? "TRUE" : "FALSE");
728 TRACE("returning default data <%s>\n",
729 (ret
) ? "TRUE" : "FALSE");
734 /*************************************************************************
735 * SHRegGetBoolUSValueW [SHLWAPI.@]
737 * See SHRegGetBoolUSValueA.
739 BOOL WINAPI
SHRegGetBoolUSValueW(
745 static const WCHAR wYES
[]= {'Y','E','S','\0'};
746 static const WCHAR wTRUE
[]= {'T','R','U','E','\0'};
747 static const WCHAR wNO
[]= {'N','O','\0'};
748 static const WCHAR wFALSE
[]={'F','A','L','S','E','\0'};
749 DWORD type
, datalen
, work
;
753 TRACE("key '%s', value '%s', %s\n",
754 debugstr_w(pszSubKey
), debugstr_w(pszValue
),
755 (fIgnoreHKCU
) ? "Ignoring HKCU" : "Tries HKCU then HKLM");
757 datalen
= (sizeof(data
)-1) * sizeof(WCHAR
);
758 if (!SHRegGetUSValueW( pszSubKey
, pszValue
, &type
,
760 fIgnoreHKCU
, 0, 0)) {
761 /* process returned data via type into bool */
764 data
[9] = '\0'; /* set end of string */
765 if (lstrcmpiW(data
, wYES
)==0 || lstrcmpiW(data
, wTRUE
)==0)
767 else if (lstrcmpiW(data
, wNO
)==0 || lstrcmpiW(data
, wFALSE
)==0)
771 work
= *(LPDWORD
)data
;
776 ret
= (data
[0] != '\0');
780 FIXME("Unsupported registry data type %d\n", type
);
783 TRACE("got value (type=%d), returning <%s>\n", type
,
784 (ret
) ? "TRUE" : "FALSE");
788 TRACE("returning default data <%s>\n",
789 (ret
) ? "TRUE" : "FALSE");
794 /*************************************************************************
795 * SHRegQueryInfoUSKeyA [SHLWAPI.@]
797 * Get information about a user-specific registry key.
800 * Success: ERROR_SUCCESS
801 * Failure: An error code from RegQueryInfoKeyA().
803 LONG WINAPI
SHRegQueryInfoUSKeyA(
804 HUSKEY hUSKey
, /* [I] Key to query */
805 LPDWORD pcSubKeys
, /* [O] Destination for number of sub keys */
806 LPDWORD pcchMaxSubKeyLen
, /* [O] Destination for the length of the biggest sub key name */
807 LPDWORD pcValues
, /* [O] Destination for number of values */
808 LPDWORD pcchMaxValueNameLen
,/* [O] Destination for the length of the biggest value */
809 SHREGENUM_FLAGS enumRegFlags
) /* [in] SHREGENUM_ flags from "shlwapi.h" */
814 TRACE("(%p,%p,%p,%p,%p,%d)\n",
815 hUSKey
,pcSubKeys
,pcchMaxSubKeyLen
,pcValues
,
816 pcchMaxValueNameLen
,enumRegFlags
);
818 /* if user wants HKCU, and it exists, then try it */
819 if (((enumRegFlags
== SHREGENUM_HKCU
) ||
820 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
821 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKCU
))) {
822 ret
= RegQueryInfoKeyA(dokey
, 0, 0, 0,
823 pcSubKeys
, pcchMaxSubKeyLen
, 0,
824 pcValues
, pcchMaxValueNameLen
, 0, 0, 0);
825 if ((ret
== ERROR_SUCCESS
) ||
826 (enumRegFlags
== SHREGENUM_HKCU
))
829 if (((enumRegFlags
== SHREGENUM_HKLM
) ||
830 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
831 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKLM
))) {
832 return RegQueryInfoKeyA(dokey
, 0, 0, 0,
833 pcSubKeys
, pcchMaxSubKeyLen
, 0,
834 pcValues
, pcchMaxValueNameLen
, 0, 0, 0);
836 return ERROR_INVALID_FUNCTION
;
839 /*************************************************************************
840 * SHRegQueryInfoUSKeyW [SHLWAPI.@]
842 * See SHRegQueryInfoUSKeyA.
844 LONG WINAPI
SHRegQueryInfoUSKeyW(
847 LPDWORD pcchMaxSubKeyLen
,
849 LPDWORD pcchMaxValueNameLen
,
850 SHREGENUM_FLAGS enumRegFlags
)
855 TRACE("(%p,%p,%p,%p,%p,%d)\n",
856 hUSKey
,pcSubKeys
,pcchMaxSubKeyLen
,pcValues
,
857 pcchMaxValueNameLen
,enumRegFlags
);
859 /* if user wants HKCU, and it exists, then try it */
860 if (((enumRegFlags
== SHREGENUM_HKCU
) ||
861 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
862 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKCU
))) {
863 ret
= RegQueryInfoKeyW(dokey
, 0, 0, 0,
864 pcSubKeys
, pcchMaxSubKeyLen
, 0,
865 pcValues
, pcchMaxValueNameLen
, 0, 0, 0);
866 if ((ret
== ERROR_SUCCESS
) ||
867 (enumRegFlags
== SHREGENUM_HKCU
))
870 if (((enumRegFlags
== SHREGENUM_HKLM
) ||
871 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
872 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKLM
))) {
873 return RegQueryInfoKeyW(dokey
, 0, 0, 0,
874 pcSubKeys
, pcchMaxSubKeyLen
, 0,
875 pcValues
, pcchMaxValueNameLen
, 0, 0, 0);
877 return ERROR_INVALID_FUNCTION
;
880 /*************************************************************************
881 * SHRegEnumUSKeyA [SHLWAPI.@]
883 * Enumerate a user-specific registry key.
886 * Success: ERROR_SUCCESS
887 * Failure: An error code from RegEnumKeyExA().
889 LONG WINAPI
SHRegEnumUSKeyA(
890 HUSKEY hUSKey
, /* [in] Key to enumerate */
891 DWORD dwIndex
, /* [in] Index within hUSKey */
892 LPSTR pszName
, /* [out] Name of the enumerated value */
893 LPDWORD pcchValueNameLen
, /* [in/out] Length of pszName */
894 SHREGENUM_FLAGS enumRegFlags
) /* [in] SHREGENUM_ flags from "shlwapi.h" */
898 TRACE("(%p,%d,%p,%p(%d),%d)\n",
899 hUSKey
, dwIndex
, pszName
, pcchValueNameLen
,
900 *pcchValueNameLen
, enumRegFlags
);
902 if (((enumRegFlags
== SHREGENUM_HKCU
) ||
903 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
904 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKCU
))) {
905 return RegEnumKeyExA(dokey
, dwIndex
, pszName
, pcchValueNameLen
,
909 if (((enumRegFlags
== SHREGENUM_HKLM
) ||
910 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
911 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKLM
))) {
912 return RegEnumKeyExA(dokey
, dwIndex
, pszName
, pcchValueNameLen
,
915 FIXME("no support for SHREGENUM_BOTH\n");
916 return ERROR_INVALID_FUNCTION
;
919 /*************************************************************************
920 * SHRegEnumUSKeyW [SHLWAPI.@]
922 * See SHRegEnumUSKeyA.
924 LONG WINAPI
SHRegEnumUSKeyW(
928 LPDWORD pcchValueNameLen
,
929 SHREGENUM_FLAGS enumRegFlags
)
933 TRACE("(%p,%d,%p,%p(%d),%d)\n",
934 hUSKey
, dwIndex
, pszName
, pcchValueNameLen
,
935 *pcchValueNameLen
, enumRegFlags
);
937 if (((enumRegFlags
== SHREGENUM_HKCU
) ||
938 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
939 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKCU
))) {
940 return RegEnumKeyExW(dokey
, dwIndex
, pszName
, pcchValueNameLen
,
944 if (((enumRegFlags
== SHREGENUM_HKLM
) ||
945 (enumRegFlags
== SHREGENUM_DEFAULT
)) &&
946 (dokey
= REG_GetHKEYFromHUSKEY(hUSKey
,REG_HKLM
))) {
947 return RegEnumKeyExW(dokey
, dwIndex
, pszName
, pcchValueNameLen
,
950 FIXME("no support for SHREGENUM_BOTH\n");
951 return ERROR_INVALID_FUNCTION
;
955 /*************************************************************************
956 * SHRegWriteUSValueA [SHLWAPI.@]
958 * Write a user-specific registry value.
961 * hUSKey [I] Key to write the value to
962 * pszValue [I] Name of value under hUSKey to write the value as
963 * dwType [I] Type of the value
964 * pvData [I] Data to set as the value
965 * cbData [I] length of pvData
966 * dwFlags [I] SHREGSET_ flags from "shlwapi.h"
969 * Success: ERROR_SUCCESS.
970 * Failure: ERROR_INVALID_PARAMETER, if any parameter is invalid, otherwise
971 * an error code from RegSetValueExA().
974 * dwFlags must have at least SHREGSET_FORCE_HKCU or SHREGSET_FORCE_HKLM set.
976 LONG WINAPI
SHRegWriteUSValueA(HUSKEY hUSKey
, LPCSTR pszValue
, DWORD dwType
,
977 LPVOID pvData
, DWORD cbData
, DWORD dwFlags
)
979 WCHAR szValue
[MAX_PATH
];
982 MultiByteToWideChar(CP_ACP
, 0, pszValue
, -1, szValue
, MAX_PATH
);
984 return SHRegWriteUSValueW(hUSKey
, pszValue
? szValue
: NULL
, dwType
,
985 pvData
, cbData
, dwFlags
);
988 /*************************************************************************
989 * SHRegWriteUSValueW [SHLWAPI.@]
991 * See SHRegWriteUSValueA.
993 LONG WINAPI
SHRegWriteUSValueW(HUSKEY hUSKey
, LPCWSTR pszValue
, DWORD dwType
,
994 LPVOID pvData
, DWORD cbData
, DWORD dwFlags
)
997 LPSHUSKEY hKey
= hUSKey
;
998 LONG ret
= ERROR_SUCCESS
;
1000 TRACE("(%p,%s,%d,%p,%d,%d)\n", hUSKey
, debugstr_w(pszValue
),
1001 dwType
, pvData
, cbData
, dwFlags
);
1003 if (!hUSKey
|| IsBadWritePtr(hUSKey
, sizeof(SHUSKEY
)) ||
1004 !(dwFlags
& (SHREGSET_FORCE_HKCU
|SHREGSET_FORCE_HKLM
)))
1005 return ERROR_INVALID_PARAMETER
;
1007 if (dwFlags
& (SHREGSET_FORCE_HKCU
|SHREGSET_HKCU
))
1011 /* Create the key */
1012 ret
= RegCreateKeyW(hKey
->HKCUstart
, hKey
->lpszPath
, &hKey
->HKCUkey
);
1013 TRACE("Creating HKCU key, ret = %d\n", ret
);
1014 if (ret
&& (dwFlags
& (SHREGSET_FORCE_HKCU
)))
1023 if ((dwFlags
& SHREGSET_FORCE_HKCU
) ||
1024 RegQueryValueExW(hKey
->HKCUkey
, pszValue
, NULL
, NULL
, NULL
, &dummy
))
1026 /* Doesn't exist or we are forcing: Write value */
1027 ret
= RegSetValueExW(hKey
->HKCUkey
, pszValue
, 0, dwType
, pvData
, cbData
);
1028 TRACE("Writing HKCU value, ret = %d\n", ret
);
1033 if (dwFlags
& (SHREGSET_FORCE_HKLM
|SHREGSET_HKLM
))
1037 /* Create the key */
1038 ret
= RegCreateKeyW(hKey
->HKLMstart
, hKey
->lpszPath
, &hKey
->HKLMkey
);
1039 TRACE("Creating HKLM key, ret = %d\n", ret
);
1040 if (ret
&& (dwFlags
& (SHREGSET_FORCE_HKLM
)))
1049 if ((dwFlags
& SHREGSET_FORCE_HKLM
) ||
1050 RegQueryValueExW(hKey
->HKLMkey
, pszValue
, NULL
, NULL
, NULL
, &dummy
))
1052 /* Doesn't exist or we are forcing: Write value */
1053 ret
= RegSetValueExW(hKey
->HKLMkey
, pszValue
, 0, dwType
, pvData
, cbData
);
1054 TRACE("Writing HKLM value, ret = %d\n", ret
);
1062 /*************************************************************************
1063 * SHRegGetPathA [SHLWAPI.@]
1065 * Get a path from the registry.
1068 * hKey [I] Handle to registry key
1069 * lpszSubKey [I] Name of sub key containing path to get
1070 * lpszValue [I] Name of value containing path to get
1071 * lpszPath [O] Buffer for returned path
1072 * dwFlags [I] Reserved
1075 * Success: ERROR_SUCCESS. lpszPath contains the path.
1076 * Failure: An error code from RegOpenKeyExA() or SHQueryValueExA().
1078 DWORD WINAPI
SHRegGetPathA(HKEY hKey
, LPCSTR lpszSubKey
, LPCSTR lpszValue
,
1079 LPSTR lpszPath
, DWORD dwFlags
)
1081 DWORD dwSize
= MAX_PATH
;
1083 TRACE("(hkey=%p,%s,%s,%p,%d)\n", hKey
, debugstr_a(lpszSubKey
),
1084 debugstr_a(lpszValue
), lpszPath
, dwFlags
);
1086 return SHGetValueA(hKey
, lpszSubKey
, lpszValue
, 0, lpszPath
, &dwSize
);
1089 /*************************************************************************
1090 * SHRegGetPathW [SHLWAPI.@]
1092 * See SHRegGetPathA.
1094 DWORD WINAPI
SHRegGetPathW(HKEY hKey
, LPCWSTR lpszSubKey
, LPCWSTR lpszValue
,
1095 LPWSTR lpszPath
, DWORD dwFlags
)
1097 DWORD dwSize
= MAX_PATH
;
1099 TRACE("(hkey=%p,%s,%s,%p,%d)\n", hKey
, debugstr_w(lpszSubKey
),
1100 debugstr_w(lpszValue
), lpszPath
, dwFlags
);
1102 return SHGetValueW(hKey
, lpszSubKey
, lpszValue
, 0, lpszPath
, &dwSize
);
1106 /*************************************************************************
1107 * SHRegSetPathA [SHLWAPI.@]
1109 * Write a path to the registry.
1112 * hKey [I] Handle to registry key
1113 * lpszSubKey [I] Name of sub key containing path to set
1114 * lpszValue [I] Name of value containing path to set
1115 * lpszPath [O] Path to write
1116 * dwFlags [I] Reserved, must be 0.
1119 * Success: ERROR_SUCCESS.
1120 * Failure: An error code from SHSetValueA().
1122 DWORD WINAPI
SHRegSetPathA(HKEY hKey
, LPCSTR lpszSubKey
, LPCSTR lpszValue
,
1123 LPCSTR lpszPath
, DWORD dwFlags
)
1125 char szBuff
[MAX_PATH
];
1127 FIXME("(hkey=%p,%s,%s,%p,%d) - semi-stub\n",hKey
, debugstr_a(lpszSubKey
),
1128 debugstr_a(lpszValue
), lpszPath
, dwFlags
);
1130 lstrcpyA(szBuff
, lpszPath
);
1132 /* FIXME: PathUnExpandEnvStringsA(szBuff); */
1134 return SHSetValueA(hKey
,lpszSubKey
, lpszValue
, REG_SZ
, szBuff
,
1138 /*************************************************************************
1139 * SHRegSetPathW [SHLWAPI.@]
1141 * See SHRegSetPathA.
1143 DWORD WINAPI
SHRegSetPathW(HKEY hKey
, LPCWSTR lpszSubKey
, LPCWSTR lpszValue
,
1144 LPCWSTR lpszPath
, DWORD dwFlags
)
1146 WCHAR szBuff
[MAX_PATH
];
1148 FIXME("(hkey=%p,%s,%s,%p,%d) - semi-stub\n",hKey
, debugstr_w(lpszSubKey
),
1149 debugstr_w(lpszValue
), lpszPath
, dwFlags
);
1151 lstrcpyW(szBuff
, lpszPath
);
1153 /* FIXME: PathUnExpandEnvStringsW(szBuff); */
1155 return SHSetValueW(hKey
,lpszSubKey
, lpszValue
, REG_SZ
, szBuff
,
1159 /*************************************************************************
1160 * SHGetValueA [SHLWAPI.@]
1162 * Get a value from the registry.
1165 * hKey [I] Handle to registry key
1166 * lpszSubKey [I] Name of sub key containing value to get
1167 * lpszValue [I] Name of value to get
1168 * pwType [O] Pointer to the values type
1169 * pvData [O] Pointer to the values data
1170 * pcbData [O] Pointer to the values size
1173 * Success: ERROR_SUCCESS. Output parameters contain the details read.
1174 * Failure: An error code from RegOpenKeyExA() or SHQueryValueExA().
1176 DWORD WINAPI
SHGetValueA(HKEY hKey
, LPCSTR lpszSubKey
, LPCSTR lpszValue
,
1177 LPDWORD pwType
, LPVOID pvData
, LPDWORD pcbData
)
1182 TRACE("(hkey=%p,%s,%s,%p,%p,%p)\n", hKey
, debugstr_a(lpszSubKey
),
1183 debugstr_a(lpszValue
), pwType
, pvData
, pcbData
);
1185 /* lpszSubKey can be 0. In this case the value is taken from the
1189 dwRet
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_QUERY_VALUE
, &hSubKey
);
1193 /* SHQueryValueEx expands Environment strings */
1194 dwRet
= SHQueryValueExA(hSubKey
? hSubKey
: hKey
, lpszValue
, 0, pwType
, pvData
, pcbData
);
1195 if (hSubKey
) RegCloseKey(hSubKey
);
1200 /*************************************************************************
1201 * SHGetValueW [SHLWAPI.@]
1205 DWORD WINAPI
SHGetValueW(HKEY hKey
, LPCWSTR lpszSubKey
, LPCWSTR lpszValue
,
1206 LPDWORD pwType
, LPVOID pvData
, LPDWORD pcbData
)
1211 TRACE("(hkey=%p,%s,%s,%p,%p,%p)\n", hKey
, debugstr_w(lpszSubKey
),
1212 debugstr_w(lpszValue
), pwType
, pvData
, pcbData
);
1215 dwRet
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_QUERY_VALUE
, &hSubKey
);
1219 dwRet
= SHQueryValueExW(hSubKey
? hSubKey
: hKey
, lpszValue
, 0, pwType
, pvData
, pcbData
);
1220 if (hSubKey
) RegCloseKey(hSubKey
);
1225 /*************************************************************************
1226 * SHSetValueA [SHLWAPI.@]
1228 * Set a value in the registry.
1231 * hKey [I] Handle to registry key
1232 * lpszSubKey [I] Name of sub key under hKey
1233 * lpszValue [I] Name of value to set
1234 * dwType [I] Type of the value
1235 * pvData [I] Data of the value
1236 * cbData [I] Size of the value
1239 * Success: ERROR_SUCCESS. The value is set with the data given.
1240 * Failure: An error code from RegCreateKeyExA() or RegSetValueExA()
1243 * If lpszSubKey does not exist, it is created before the value is set. If
1244 * lpszSubKey is NULL or an empty string, then the value is added directly
1247 DWORD WINAPI
SHSetValueA(HKEY hKey
, LPCSTR lpszSubKey
, LPCSTR lpszValue
,
1248 DWORD dwType
, LPCVOID pvData
, DWORD cbData
)
1250 DWORD dwRet
= ERROR_SUCCESS
, dwDummy
;
1253 TRACE("(hkey=%p,%s,%s,%d,%p,%d)\n", hKey
, debugstr_a(lpszSubKey
),
1254 debugstr_a(lpszValue
), dwType
, pvData
, cbData
);
1256 if (lpszSubKey
&& *lpszSubKey
)
1257 dwRet
= RegCreateKeyExA(hKey
, lpszSubKey
, 0, NULL
,
1258 0, KEY_SET_VALUE
, NULL
, &hSubKey
, &dwDummy
);
1263 dwRet
= RegSetValueExA(hSubKey
, lpszValue
, 0, dwType
, pvData
, cbData
);
1264 if (hSubKey
!= hKey
)
1265 RegCloseKey(hSubKey
);
1270 /*************************************************************************
1271 * SHSetValueW [SHLWAPI.@]
1275 DWORD WINAPI
SHSetValueW(HKEY hKey
, LPCWSTR lpszSubKey
, LPCWSTR lpszValue
,
1276 DWORD dwType
, LPCVOID pvData
, DWORD cbData
)
1278 DWORD dwRet
= ERROR_SUCCESS
, dwDummy
;
1281 TRACE("(hkey=%p,%s,%s,%d,%p,%d)\n", hKey
, debugstr_w(lpszSubKey
),
1282 debugstr_w(lpszValue
), dwType
, pvData
, cbData
);
1284 if (lpszSubKey
&& *lpszSubKey
)
1285 dwRet
= RegCreateKeyExW(hKey
, lpszSubKey
, 0, NULL
,
1286 0, KEY_SET_VALUE
, NULL
, &hSubKey
, &dwDummy
);
1291 dwRet
= RegSetValueExW(hSubKey
, lpszValue
, 0, dwType
, pvData
, cbData
);
1292 if (hSubKey
!= hKey
)
1293 RegCloseKey(hSubKey
);
1298 /*************************************************************************
1299 * SHQueryInfoKeyA [SHLWAPI.@]
1301 * Get information about a registry key. See RegQueryInfoKeyA().
1304 * The result of calling RegQueryInfoKeyA().
1306 LONG WINAPI
SHQueryInfoKeyA(HKEY hKey
, LPDWORD pwSubKeys
, LPDWORD pwSubKeyMax
,
1307 LPDWORD pwValues
, LPDWORD pwValueMax
)
1309 TRACE("(hkey=%p,%p,%p,%p,%p)\n", hKey
, pwSubKeys
, pwSubKeyMax
,
1310 pwValues
, pwValueMax
);
1311 return RegQueryInfoKeyA(hKey
, NULL
, NULL
, NULL
, pwSubKeys
, pwSubKeyMax
,
1312 NULL
, pwValues
, pwValueMax
, NULL
, NULL
, NULL
);
1315 /*************************************************************************
1316 * SHQueryInfoKeyW [SHLWAPI.@]
1318 * See SHQueryInfoKeyA.
1320 LONG WINAPI
SHQueryInfoKeyW(HKEY hKey
, LPDWORD pwSubKeys
, LPDWORD pwSubKeyMax
,
1321 LPDWORD pwValues
, LPDWORD pwValueMax
)
1323 TRACE("(hkey=%p,%p,%p,%p,%p)\n", hKey
, pwSubKeys
, pwSubKeyMax
,
1324 pwValues
, pwValueMax
);
1325 return RegQueryInfoKeyW(hKey
, NULL
, NULL
, NULL
, pwSubKeys
, pwSubKeyMax
,
1326 NULL
, pwValues
, pwValueMax
, NULL
, NULL
, NULL
);
1329 /*************************************************************************
1330 * SHQueryValueExA [SHLWAPI.@]
1332 * Get a value from the registry, expanding environment variable strings.
1335 * hKey [I] Handle to registry key
1336 * lpszValue [I] Name of value to query
1337 * lpReserved [O] Reserved for future use; must be NULL
1338 * pwType [O] Optional pointer updated with the values type
1339 * pvData [O] Optional pointer updated with the values data
1340 * pcbData [O] Optional pointer updated with the values size
1343 * Success: ERROR_SUCCESS. Any non NULL output parameters are updated with
1344 * information about the value.
1345 * Failure: ERROR_OUTOFMEMORY if memory allocation fails, or the type of the
1346 * data is REG_EXPAND_SZ and pcbData is NULL. Otherwise an error
1347 * code from RegQueryValueExA() or ExpandEnvironmentStringsA().
1350 * Either pwType, pvData or pcbData may be NULL if the caller doesn't want
1351 * the type, data or size information for the value.
1353 * If the type of the data is REG_EXPAND_SZ, it is expanded to REG_SZ. The
1354 * value returned will be truncated if it is of type REG_SZ and bigger than
1355 * the buffer given to store it.
1358 * case-1: the unexpanded string is smaller than the expanded one
1359 * subcase-1: the buffer is too small to hold the unexpanded string:
1360 * function fails and returns the size of the unexpanded string.
1362 * subcase-2: buffer is too small to hold the expanded string:
1363 * the function return success (!!) and the result is truncated
1364 * *** This is clearly an error in the native implementation. ***
1366 * case-2: the unexpanded string is bigger than the expanded one
1367 * The buffer must have enough space to hold the unexpanded
1368 * string even if the result is smaller.
1371 DWORD WINAPI
SHQueryValueExA( HKEY hKey
, LPCSTR lpszValue
,
1372 LPDWORD lpReserved
, LPDWORD pwType
,
1373 LPVOID pvData
, LPDWORD pcbData
)
1375 DWORD dwRet
, dwType
, dwUnExpDataLen
= 0, dwExpDataLen
;
1377 TRACE("(hkey=%p,%s,%p,%p,%p,%p=%d)\n", hKey
, debugstr_a(lpszValue
),
1378 lpReserved
, pwType
, pvData
, pcbData
, pcbData
? *pcbData
: 0);
1380 if (pcbData
) dwUnExpDataLen
= *pcbData
;
1382 dwRet
= RegQueryValueExA(hKey
, lpszValue
, lpReserved
, &dwType
, pvData
, &dwUnExpDataLen
);
1384 if (pcbData
&& (dwType
== REG_EXPAND_SZ
))
1386 DWORD nBytesToAlloc
;
1388 /* Expand type REG_EXPAND_SZ into REG_SZ */
1391 /* If the caller didn't supply a buffer or the buffer is too small we have
1392 * to allocate our own
1394 if ((!pvData
) || (dwRet
== ERROR_MORE_DATA
) )
1397 nBytesToAlloc
= dwUnExpDataLen
;
1399 szData
= LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
1400 RegQueryValueExA (hKey
, lpszValue
, lpReserved
, NULL
, (LPBYTE
)szData
, &nBytesToAlloc
);
1401 dwExpDataLen
= ExpandEnvironmentStringsA(szData
, &cNull
, 1);
1402 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
1407 nBytesToAlloc
= (lstrlenA(pvData
)+1) * sizeof (CHAR
);
1408 szData
= LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
1409 lstrcpyA(szData
, pvData
);
1410 dwExpDataLen
= ExpandEnvironmentStringsA(szData
, pvData
, *pcbData
/ sizeof(CHAR
));
1411 if (dwExpDataLen
> *pcbData
) dwRet
= ERROR_MORE_DATA
;
1412 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
1417 /* Update the type and data size if the caller wanted them */
1418 if ( dwType
== REG_EXPAND_SZ
) dwType
= REG_SZ
;
1419 if ( pwType
) *pwType
= dwType
;
1420 if ( pcbData
) *pcbData
= dwUnExpDataLen
;
1425 /*************************************************************************
1426 * SHQueryValueExW [SHLWAPI.@]
1428 * See SHQueryValueExA.
1430 DWORD WINAPI
SHQueryValueExW(HKEY hKey
, LPCWSTR lpszValue
,
1431 LPDWORD lpReserved
, LPDWORD pwType
,
1432 LPVOID pvData
, LPDWORD pcbData
)
1434 DWORD dwRet
, dwType
, dwUnExpDataLen
= 0, dwExpDataLen
;
1436 TRACE("(hkey=%p,%s,%p,%p,%p,%p=%d)\n", hKey
, debugstr_w(lpszValue
),
1437 lpReserved
, pwType
, pvData
, pcbData
, pcbData
? *pcbData
: 0);
1439 if (pcbData
) dwUnExpDataLen
= *pcbData
;
1441 dwRet
= RegQueryValueExW(hKey
, lpszValue
, lpReserved
, &dwType
, pvData
, &dwUnExpDataLen
);
1442 if (dwRet
!=ERROR_SUCCESS
&& dwRet
!=ERROR_MORE_DATA
)
1445 if (pcbData
&& (dwType
== REG_EXPAND_SZ
))
1447 DWORD nBytesToAlloc
;
1449 /* Expand type REG_EXPAND_SZ into REG_SZ */
1452 /* If the caller didn't supply a buffer or the buffer is too small we have
1453 * to allocate our own
1455 if ((!pvData
) || (dwRet
== ERROR_MORE_DATA
) )
1458 nBytesToAlloc
= dwUnExpDataLen
;
1460 szData
= LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
1461 RegQueryValueExW (hKey
, lpszValue
, lpReserved
, NULL
, (LPBYTE
)szData
, &nBytesToAlloc
);
1462 dwExpDataLen
= ExpandEnvironmentStringsW(szData
, &cNull
, 1);
1463 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
1468 nBytesToAlloc
= (lstrlenW(pvData
) + 1) * sizeof(WCHAR
);
1469 szData
= LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
1470 lstrcpyW(szData
, pvData
);
1471 dwExpDataLen
= ExpandEnvironmentStringsW(szData
, pvData
, *pcbData
/sizeof(WCHAR
) );
1472 if (dwExpDataLen
> *pcbData
) dwRet
= ERROR_MORE_DATA
;
1473 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
1478 /* Update the type and data size if the caller wanted them */
1479 if ( dwType
== REG_EXPAND_SZ
) dwType
= REG_SZ
;
1480 if ( pwType
) *pwType
= dwType
;
1481 if ( pcbData
) *pcbData
= dwUnExpDataLen
;
1485 /*************************************************************************
1486 * SHDeleteKeyA [SHLWAPI.@]
1488 * Delete a registry key and any sub keys/values present
1490 * This function forwards to the unicode version directly, to avoid
1491 * handling subkeys that are not representable in ASCII.
1494 * hKey [I] Handle to registry key
1495 * lpszSubKey [I] Name of sub key to delete
1498 * Success: ERROR_SUCCESS. The key is deleted.
1499 * Failure: An error code from RegOpenKeyExA(), RegQueryInfoKeyA(),
1500 * RegEnumKeyExA() or RegDeleteKeyA().
1502 DWORD WINAPI
SHDeleteKeyA(HKEY hKey
, LPCSTR lpszSubKey
)
1504 WCHAR subkeyW
[MAX_PATH
];
1506 MultiByteToWideChar (CP_ACP
, 0, lpszSubKey
, -1, subkeyW
, sizeof(subkeyW
)/sizeof(WCHAR
));
1507 return SHDeleteKeyW(hKey
, subkeyW
);
1510 /*************************************************************************
1511 * SHDeleteKeyW [SHLWAPI.@]
1515 DWORD WINAPI
SHDeleteKeyW(HKEY hKey
, LPCWSTR lpszSubKey
)
1517 DWORD dwRet
, dwMaxSubkeyLen
= 0, dwSize
;
1518 WCHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
1521 TRACE("(hkey=%p,%s)\n", hKey
, debugstr_w(lpszSubKey
));
1523 dwRet
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
1526 /* Find the maximum subkey length so that we can allocate a buffer */
1527 dwRet
= RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, NULL
,
1528 &dwMaxSubkeyLen
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1532 if (dwMaxSubkeyLen
> sizeof(szNameBuf
)/sizeof(WCHAR
))
1533 /* Name too big: alloc a buffer for it */
1534 lpszName
= HeapAlloc(GetProcessHeap(), 0, dwMaxSubkeyLen
*sizeof(WCHAR
));
1537 dwRet
= ERROR_NOT_ENOUGH_MEMORY
;
1540 while (dwRet
== ERROR_SUCCESS
)
1542 dwSize
= dwMaxSubkeyLen
;
1543 dwRet
= RegEnumKeyExW(hSubKey
, 0, lpszName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
1544 if (dwRet
== ERROR_SUCCESS
|| dwRet
== ERROR_MORE_DATA
)
1545 dwRet
= SHDeleteKeyW(hSubKey
, lpszName
);
1547 if (dwRet
== ERROR_NO_MORE_ITEMS
)
1548 dwRet
= ERROR_SUCCESS
;
1550 if (lpszName
!= szNameBuf
)
1551 HeapFree(GetProcessHeap(), 0, lpszName
); /* Free buffer if allocated */
1555 RegCloseKey(hSubKey
);
1557 dwRet
= RegDeleteKeyW(hKey
, lpszSubKey
);
1562 /*************************************************************************
1563 * SHDeleteEmptyKeyA [SHLWAPI.@]
1565 * Delete a registry key with no sub keys.
1568 * hKey [I] Handle to registry key
1569 * lpszSubKey [I] Name of sub key to delete
1572 * Success: ERROR_SUCCESS. The key is deleted.
1573 * Failure: If the key is not empty, returns ERROR_KEY_HAS_CHILDREN. Otherwise
1574 * returns an error code from RegOpenKeyExA(), RegQueryInfoKeyA() or
1577 DWORD WINAPI
SHDeleteEmptyKeyA(HKEY hKey
, LPCSTR lpszSubKey
)
1579 DWORD dwRet
, dwKeyCount
= 0;
1582 TRACE("(hkey=%p,%s)\n", hKey
, debugstr_a(lpszSubKey
));
1584 dwRet
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
1587 dwRet
= RegQueryInfoKeyA(hSubKey
, NULL
, NULL
, NULL
, &dwKeyCount
,
1588 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1589 RegCloseKey(hSubKey
);
1593 dwRet
= RegDeleteKeyA(hKey
, lpszSubKey
);
1595 dwRet
= ERROR_KEY_HAS_CHILDREN
;
1601 /*************************************************************************
1602 * SHDeleteEmptyKeyW [SHLWAPI.@]
1604 * See SHDeleteEmptyKeyA.
1606 DWORD WINAPI
SHDeleteEmptyKeyW(HKEY hKey
, LPCWSTR lpszSubKey
)
1608 DWORD dwRet
, dwKeyCount
= 0;
1611 TRACE("(hkey=%p, %s)\n", hKey
, debugstr_w(lpszSubKey
));
1613 dwRet
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
1616 dwRet
= RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, &dwKeyCount
,
1617 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1618 RegCloseKey(hSubKey
);
1622 dwRet
= RegDeleteKeyW(hKey
, lpszSubKey
);
1624 dwRet
= ERROR_KEY_HAS_CHILDREN
;
1630 /*************************************************************************
1631 * SHDeleteOrphanKeyA [SHLWAPI.@]
1633 * Delete a registry key with no sub keys or values.
1636 * hKey [I] Handle to registry key
1637 * lpszSubKey [I] Name of sub key to possibly delete
1640 * Success: ERROR_SUCCESS. The key has been deleted if it was an orphan.
1641 * Failure: An error from RegOpenKeyExA(), RegQueryValueExA(), or RegDeleteKeyA().
1643 DWORD WINAPI
SHDeleteOrphanKeyA(HKEY hKey
, LPCSTR lpszSubKey
)
1646 DWORD dwKeyCount
= 0, dwValueCount
= 0, dwRet
;
1648 TRACE("(hkey=%p,%s)\n", hKey
, debugstr_a(lpszSubKey
));
1650 dwRet
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
1654 /* Get subkey and value count */
1655 dwRet
= RegQueryInfoKeyA(hSubKey
, NULL
, NULL
, NULL
, &dwKeyCount
,
1656 NULL
, NULL
, &dwValueCount
, NULL
, NULL
, NULL
, NULL
);
1658 if(!dwRet
&& !dwKeyCount
&& !dwValueCount
)
1660 dwRet
= RegDeleteKeyA(hKey
, lpszSubKey
);
1662 RegCloseKey(hSubKey
);
1667 /*************************************************************************
1668 * SHDeleteOrphanKeyW [SHLWAPI.@]
1670 * See SHDeleteOrphanKeyA.
1672 DWORD WINAPI
SHDeleteOrphanKeyW(HKEY hKey
, LPCWSTR lpszSubKey
)
1675 DWORD dwKeyCount
= 0, dwValueCount
= 0, dwRet
;
1677 TRACE("(hkey=%p,%s)\n", hKey
, debugstr_w(lpszSubKey
));
1679 dwRet
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
1683 /* Get subkey and value count */
1684 dwRet
= RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, &dwKeyCount
,
1685 NULL
, NULL
, &dwValueCount
, NULL
, NULL
, NULL
, NULL
);
1687 if(!dwRet
&& !dwKeyCount
&& !dwValueCount
)
1689 dwRet
= RegDeleteKeyW(hKey
, lpszSubKey
);
1691 RegCloseKey(hSubKey
);
1696 /*************************************************************************
1697 * SHDeleteValueA [SHLWAPI.@]
1699 * Delete a value from the registry.
1702 * hKey [I] Handle to registry key
1703 * lpszSubKey [I] Name of sub key containing value to delete
1704 * lpszValue [I] Name of value to delete
1707 * Success: ERROR_SUCCESS. The value is deleted.
1708 * Failure: An error code from RegOpenKeyExA() or RegDeleteValueA().
1710 DWORD WINAPI
SHDeleteValueA(HKEY hKey
, LPCSTR lpszSubKey
, LPCSTR lpszValue
)
1715 TRACE("(hkey=%p,%s,%s)\n", hKey
, debugstr_a(lpszSubKey
), debugstr_a(lpszValue
));
1717 dwRet
= RegOpenKeyExA(hKey
, lpszSubKey
, 0, KEY_SET_VALUE
, &hSubKey
);
1720 dwRet
= RegDeleteValueA(hSubKey
, lpszValue
);
1721 RegCloseKey(hSubKey
);
1726 /*************************************************************************
1727 * SHDeleteValueW [SHLWAPI.@]
1729 * See SHDeleteValueA.
1731 DWORD WINAPI
SHDeleteValueW(HKEY hKey
, LPCWSTR lpszSubKey
, LPCWSTR lpszValue
)
1736 TRACE("(hkey=%p,%s,%s)\n", hKey
, debugstr_w(lpszSubKey
), debugstr_w(lpszValue
));
1738 dwRet
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_SET_VALUE
, &hSubKey
);
1741 dwRet
= RegDeleteValueW(hSubKey
, lpszValue
);
1742 RegCloseKey(hSubKey
);
1747 /*************************************************************************
1748 * SHEnumKeyExA [SHLWAPI.@]
1750 * Enumerate sub keys in a registry key.
1753 * hKey [I] Handle to registry key
1754 * dwIndex [I] Index of key to enumerate
1755 * lpszSubKey [O] Pointer updated with the subkey name
1756 * pwLen [O] Pointer updated with the subkey length
1759 * Success: ERROR_SUCCESS. lpszSubKey and pwLen are updated.
1760 * Failure: An error code from RegEnumKeyExA().
1762 LONG WINAPI
SHEnumKeyExA(HKEY hKey
, DWORD dwIndex
, LPSTR lpszSubKey
,
1765 TRACE("(hkey=%p,%d,%s,%p)\n", hKey
, dwIndex
, debugstr_a(lpszSubKey
), pwLen
);
1767 return RegEnumKeyExA(hKey
, dwIndex
, lpszSubKey
, pwLen
, NULL
, NULL
, NULL
, NULL
);
1770 /*************************************************************************
1771 * SHEnumKeyExW [SHLWAPI.@]
1775 LONG WINAPI
SHEnumKeyExW(HKEY hKey
, DWORD dwIndex
, LPWSTR lpszSubKey
,
1778 TRACE("(hkey=%p,%d,%s,%p)\n", hKey
, dwIndex
, debugstr_w(lpszSubKey
), pwLen
);
1780 return RegEnumKeyExW(hKey
, dwIndex
, lpszSubKey
, pwLen
, NULL
, NULL
, NULL
, NULL
);
1783 /*************************************************************************
1784 * SHEnumValueA [SHLWAPI.@]
1786 * Enumerate values in a registry key.
1789 * hKey [I] Handle to registry key
1790 * dwIndex [I] Index of key to enumerate
1791 * lpszValue [O] Pointer updated with the values name
1792 * pwLen [O] Pointer updated with the values length
1793 * pwType [O] Pointer updated with the values type
1794 * pvData [O] Pointer updated with the values data
1795 * pcbData [O] Pointer updated with the values size
1798 * Success: ERROR_SUCCESS. Output parameters are updated.
1799 * Failure: An error code from RegEnumValueA().
1801 LONG WINAPI
SHEnumValueA(HKEY hKey
, DWORD dwIndex
, LPSTR lpszValue
,
1802 LPDWORD pwLen
, LPDWORD pwType
,
1803 LPVOID pvData
, LPDWORD pcbData
)
1805 TRACE("(hkey=%p,%d,%s,%p,%p,%p,%p)\n", hKey
, dwIndex
,
1806 debugstr_a(lpszValue
), pwLen
, pwType
, pvData
, pcbData
);
1808 return RegEnumValueA(hKey
, dwIndex
, lpszValue
, pwLen
, NULL
,
1809 pwType
, pvData
, pcbData
);
1812 /*************************************************************************
1813 * SHEnumValueW [SHLWAPI.@]
1817 LONG WINAPI
SHEnumValueW(HKEY hKey
, DWORD dwIndex
, LPWSTR lpszValue
,
1818 LPDWORD pwLen
, LPDWORD pwType
,
1819 LPVOID pvData
, LPDWORD pcbData
)
1821 TRACE("(hkey=%p,%d,%s,%p,%p,%p,%p)\n", hKey
, dwIndex
,
1822 debugstr_w(lpszValue
), pwLen
, pwType
, pvData
, pcbData
);
1824 return RegEnumValueW(hKey
, dwIndex
, lpszValue
, pwLen
, NULL
,
1825 pwType
, pvData
, pcbData
);
1828 /*************************************************************************
1831 * Get a value from the registry.
1834 * hKey [I] Handle to registry key
1835 * pSubKey [I] Name of sub key containing value to get
1836 * pValue [I] Name of value to get
1837 * pwType [O] Destination for the values type
1838 * pvData [O] Destination for the values data
1839 * pbData [O] Destination for the values size
1842 * Success: ERROR_SUCCESS. Output parameters contain the details read.
1843 * Failure: An error code from RegOpenKeyExA() or SHQueryValueExA(),
1844 * or ERROR_INVALID_FUNCTION in the machine is in safe mode.
1846 DWORD WINAPI
SHGetValueGoodBootA(HKEY hkey
, LPCSTR pSubKey
, LPCSTR pValue
,
1847 LPDWORD pwType
, LPVOID pvData
, LPDWORD pbData
)
1849 if (GetSystemMetrics(SM_CLEANBOOT
))
1850 return ERROR_INVALID_FUNCTION
;
1851 return SHGetValueA(hkey
, pSubKey
, pValue
, pwType
, pvData
, pbData
);
1854 /*************************************************************************
1857 * Unicode version of SHGetValueGoodBootW.
1859 DWORD WINAPI
SHGetValueGoodBootW(HKEY hkey
, LPCWSTR pSubKey
, LPCWSTR pValue
,
1860 LPDWORD pwType
, LPVOID pvData
, LPDWORD pbData
)
1862 if (GetSystemMetrics(SM_CLEANBOOT
))
1863 return ERROR_INVALID_FUNCTION
;
1864 return SHGetValueW(hkey
, pSubKey
, pValue
, pwType
, pvData
, pbData
);
1867 /*************************************************************************
1870 * Set a MIME content type in the registry.
1873 * lpszSubKey [I] Name of key under HKEY_CLASSES_ROOT.
1874 * lpszValue [I] Value to set
1880 BOOL WINAPI
RegisterMIMETypeForExtensionA(LPCSTR lpszSubKey
, LPCSTR lpszValue
)
1884 WARN("Invalid lpszValue would crash under Win32!\n");
1888 return !SHSetValueA(HKEY_CLASSES_ROOT
, lpszSubKey
, lpszContentTypeA
,
1889 REG_SZ
, lpszValue
, strlen(lpszValue
));
1892 /*************************************************************************
1895 * Unicode version of RegisterMIMETypeForExtensionA.
1897 BOOL WINAPI
RegisterMIMETypeForExtensionW(LPCWSTR lpszSubKey
, LPCWSTR lpszValue
)
1901 WARN("Invalid lpszValue would crash under Win32!\n");
1905 return !SHSetValueW(HKEY_CLASSES_ROOT
, lpszSubKey
, lpszContentTypeW
,
1906 REG_SZ
, lpszValue
, strlenW(lpszValue
));
1909 /*************************************************************************
1912 * Delete a MIME content type from the registry.
1915 * lpszSubKey [I] Name of sub key
1921 BOOL WINAPI
UnregisterMIMETypeForExtensionA(LPCSTR lpszSubKey
)
1923 return !SHDeleteValueA(HKEY_CLASSES_ROOT
, lpszSubKey
, lpszContentTypeA
);
1926 /*************************************************************************
1929 * Unicode version of UnregisterMIMETypeForExtensionA.
1931 BOOL WINAPI
UnregisterMIMETypeForExtensionW(LPCWSTR lpszSubKey
)
1933 return !SHDeleteValueW(HKEY_CLASSES_ROOT
, lpszSubKey
, lpszContentTypeW
);
1936 /*************************************************************************
1939 * Get the registry path to a MIME content key.
1942 * lpszType [I] Content type to get the path for
1943 * lpszBuffer [O] Destination for path
1944 * dwLen [I] Length of lpszBuffer
1947 * Success: TRUE. lpszBuffer contains the full path.
1951 * The base path for the key is "MIME\Database\Content Type\"
1953 BOOL WINAPI
GetMIMETypeSubKeyA(LPCSTR lpszType
, LPSTR lpszBuffer
, DWORD dwLen
)
1955 TRACE("(%s,%p,%d)\n", debugstr_a(lpszType
), lpszBuffer
, dwLen
);
1957 if (dwLen
> dwLenMimeDbContent
&& lpszType
&& lpszBuffer
)
1959 size_t dwStrLen
= strlen(lpszType
);
1961 if (dwStrLen
< dwLen
- dwLenMimeDbContent
)
1963 memcpy(lpszBuffer
, szMimeDbContentA
, dwLenMimeDbContent
);
1964 memcpy(lpszBuffer
+ dwLenMimeDbContent
, lpszType
, dwStrLen
+ 1);
1971 /*************************************************************************
1974 * Unicode version of GetMIMETypeSubKeyA.
1976 BOOL WINAPI
GetMIMETypeSubKeyW(LPCWSTR lpszType
, LPWSTR lpszBuffer
, DWORD dwLen
)
1978 TRACE("(%s,%p,%d)\n", debugstr_w(lpszType
), lpszBuffer
, dwLen
);
1980 if (dwLen
> dwLenMimeDbContent
&& lpszType
&& lpszBuffer
)
1982 DWORD dwStrLen
= strlenW(lpszType
);
1984 if (dwStrLen
< dwLen
- dwLenMimeDbContent
)
1986 memcpy(lpszBuffer
, szMimeDbContentW
, dwLenMimeDbContent
* sizeof(WCHAR
));
1987 memcpy(lpszBuffer
+ dwLenMimeDbContent
, lpszType
, (dwStrLen
+ 1) * sizeof(WCHAR
));
1994 /*************************************************************************
1997 * Get the file extension for a given Mime type.
2000 * lpszType [I] Mime type to get the file extension for
2001 * lpExt [O] Destination for the resulting extension
2002 * iLen [I] Length of lpExt in characters
2005 * Success: TRUE. lpExt contains the file extension.
2006 * Failure: FALSE, if any parameter is invalid or the extension cannot be
2007 * retrieved. If iLen > 0, lpExt is set to an empty string.
2010 * - The extension returned in lpExt always has a leading '.' character, even
2011 * if the registry Mime database entry does not.
2012 * - iLen must be long enough for the file extension for this function to succeed.
2014 BOOL WINAPI
MIME_GetExtensionA(LPCSTR lpszType
, LPSTR lpExt
, INT iLen
)
2016 char szSubKey
[MAX_PATH
];
2017 DWORD dwlen
= iLen
- 1, dwType
;
2020 if (iLen
> 0 && lpExt
)
2023 if (lpszType
&& lpExt
&& iLen
> 2 &&
2024 GetMIMETypeSubKeyA(lpszType
, szSubKey
, MAX_PATH
) &&
2025 !SHGetValueA(HKEY_CLASSES_ROOT
, szSubKey
, szExtensionA
, &dwType
, lpExt
+ 1, &dwlen
) &&
2028 if (lpExt
[1] == '.')
2029 memmove(lpExt
, lpExt
+ 1, strlen(lpExt
+ 1) + 1);
2031 *lpExt
= '.'; /* Supply a '.' */
2037 /*************************************************************************
2040 * Unicode version of MIME_GetExtensionA.
2042 BOOL WINAPI
MIME_GetExtensionW(LPCWSTR lpszType
, LPWSTR lpExt
, INT iLen
)
2044 WCHAR szSubKey
[MAX_PATH
];
2045 DWORD dwlen
= iLen
- 1, dwType
;
2048 if (iLen
> 0 && lpExt
)
2051 if (lpszType
&& lpExt
&& iLen
> 2 &&
2052 GetMIMETypeSubKeyW(lpszType
, szSubKey
, MAX_PATH
) &&
2053 !SHGetValueW(HKEY_CLASSES_ROOT
, szSubKey
, szExtensionW
, &dwType
, lpExt
+ 1, &dwlen
) &&
2056 if (lpExt
[1] == '.')
2057 memmove(lpExt
, lpExt
+ 1, (strlenW(lpExt
+ 1) + 1) * sizeof(WCHAR
));
2059 *lpExt
= '.'; /* Supply a '.' */
2065 /*************************************************************************
2068 * Set the file extension for a MIME content key.
2071 * lpszExt [I] File extension to set
2072 * lpszType [I] Content type to set the extension for
2075 * Success: TRUE. The file extension is set in the registry.
2078 BOOL WINAPI
RegisterExtensionForMIMETypeA(LPCSTR lpszExt
, LPCSTR lpszType
)
2081 char szKey
[MAX_PATH
];
2083 TRACE("(%s,%s)\n", debugstr_a(lpszExt
), debugstr_a(lpszType
));
2085 if (!GetMIMETypeSubKeyA(lpszType
, szKey
, MAX_PATH
)) /* Get full path to the key */
2088 dwLen
= strlen(lpszExt
) + 1;
2090 if (SHSetValueA(HKEY_CLASSES_ROOT
, szKey
, szExtensionA
, REG_SZ
, lpszExt
, dwLen
))
2095 /*************************************************************************
2098 * Unicode version of RegisterExtensionForMIMETypeA.
2100 BOOL WINAPI
RegisterExtensionForMIMETypeW(LPCWSTR lpszExt
, LPCWSTR lpszType
)
2103 WCHAR szKey
[MAX_PATH
];
2105 TRACE("(%s,%s)\n", debugstr_w(lpszExt
), debugstr_w(lpszType
));
2107 /* Get the full path to the key */
2108 if (!GetMIMETypeSubKeyW(lpszType
, szKey
, MAX_PATH
)) /* Get full path to the key */
2111 dwLen
= (lstrlenW(lpszExt
) + 1) * sizeof(WCHAR
);
2113 if (SHSetValueW(HKEY_CLASSES_ROOT
, szKey
, szExtensionW
, REG_SZ
, lpszExt
, dwLen
))
2118 /*************************************************************************
2121 * Delete a file extension from a MIME content type.
2124 * lpszType [I] Content type to delete the extension for
2127 * Success: TRUE. The file extension is deleted from the registry.
2128 * Failure: FALSE. The extension may have been removed but the key remains.
2131 * If deleting the extension leaves an orphan key, the key is removed also.
2133 BOOL WINAPI
UnregisterExtensionForMIMETypeA(LPCSTR lpszType
)
2135 char szKey
[MAX_PATH
];
2137 TRACE("(%s)\n", debugstr_a(lpszType
));
2139 if (!GetMIMETypeSubKeyA(lpszType
, szKey
, MAX_PATH
)) /* Get full path to the key */
2142 if (!SHDeleteValueA(HKEY_CLASSES_ROOT
, szKey
, szExtensionA
))
2145 if (!SHDeleteOrphanKeyA(HKEY_CLASSES_ROOT
, szKey
))
2150 /*************************************************************************
2153 * Unicode version of UnregisterExtensionForMIMETypeA.
2155 BOOL WINAPI
UnregisterExtensionForMIMETypeW(LPCWSTR lpszType
)
2157 WCHAR szKey
[MAX_PATH
];
2159 TRACE("(%s)\n", debugstr_w(lpszType
));
2161 if (!GetMIMETypeSubKeyW(lpszType
, szKey
, MAX_PATH
)) /* Get full path to the key */
2164 if (!SHDeleteValueW(HKEY_CLASSES_ROOT
, szKey
, szExtensionW
))
2167 if (!SHDeleteOrphanKeyW(HKEY_CLASSES_ROOT
, szKey
))
2172 /*************************************************************************
2173 * SHRegDuplicateHKey [SHLWAPI.@]
2175 * Create a duplicate of a registry handle.
2178 * hKey [I] key to duplicate.
2181 * A new handle pointing to the same key as hKey.
2183 HKEY WINAPI
SHRegDuplicateHKey(HKEY hKey
)
2187 RegOpenKeyExA(hKey
, 0, 0, MAXIMUM_ALLOWED
, &newKey
);
2188 TRACE("new key is %p\n", newKey
);
2193 /*************************************************************************
2194 * SHCopyKeyA [SHLWAPI.@]
2196 * Copy a key and its values/sub keys to another location.
2199 * hKeySrc [I] Source key to copy from
2200 * lpszSrcSubKey [I] Sub key under hKeySrc, or NULL to use hKeySrc directly
2201 * hKeyDst [I] Destination key
2202 * dwReserved [I] Reserved, must be 0
2205 * Success: ERROR_SUCCESS. The key is copied to the destination key.
2206 * Failure: A standard windows error code.
2209 * If hKeyDst is a key under hKeySrc, this function will misbehave
2210 * (It will loop until out of stack, or the registry is full). This
2211 * bug is present in Win32 also.
2213 DWORD WINAPI
SHCopyKeyA(HKEY hKeySrc
, LPCSTR lpszSrcSubKey
, HKEY hKeyDst
, DWORD dwReserved
)
2215 WCHAR szSubKeyW
[MAX_PATH
];
2217 TRACE("(hkey=%p,%s,%p08x,%d)\n", hKeySrc
, debugstr_a(lpszSrcSubKey
), hKeyDst
, dwReserved
);
2220 MultiByteToWideChar(CP_ACP
, 0, lpszSrcSubKey
, -1, szSubKeyW
, MAX_PATH
);
2222 return SHCopyKeyW(hKeySrc
, lpszSrcSubKey
? szSubKeyW
: NULL
, hKeyDst
, dwReserved
);
2225 /*************************************************************************
2226 * SHCopyKeyW [SHLWAPI.@]
2230 DWORD WINAPI
SHCopyKeyW(HKEY hKeySrc
, LPCWSTR lpszSrcSubKey
, HKEY hKeyDst
, DWORD dwReserved
)
2232 DWORD dwKeyCount
= 0, dwValueCount
= 0, dwMaxKeyLen
= 0;
2233 DWORD dwMaxValueLen
= 0, dwMaxDataLen
= 0, i
;
2235 LPVOID lpBuff
= buff
;
2236 WCHAR szName
[MAX_PATH
], *lpszName
= szName
;
2239 TRACE("hkey=%p,%s,%p08x,%d)\n", hKeySrc
, debugstr_w(lpszSrcSubKey
), hKeyDst
, dwReserved
);
2241 if(!hKeyDst
|| !hKeySrc
)
2242 dwRet
= ERROR_INVALID_PARAMETER
;
2245 /* Open source key */
2247 dwRet
= RegOpenKeyExW(hKeySrc
, lpszSrcSubKey
, 0, KEY_ALL_ACCESS
, &hKeySrc
);
2250 hKeyDst
= NULL
; /* Don't close this key since we didn't open it */
2253 /* Get details about sub keys and values */
2254 dwRet
= RegQueryInfoKeyW(hKeySrc
, NULL
, NULL
, NULL
, &dwKeyCount
, &dwMaxKeyLen
,
2255 NULL
, &dwValueCount
, &dwMaxValueLen
, &dwMaxDataLen
,
2259 if (dwMaxValueLen
> dwMaxKeyLen
)
2260 dwMaxKeyLen
= dwMaxValueLen
; /* Get max size for key/value names */
2262 if (dwMaxKeyLen
++ > MAX_PATH
- 1)
2263 lpszName
= HeapAlloc(GetProcessHeap(), 0, dwMaxKeyLen
* sizeof(WCHAR
));
2265 if (dwMaxDataLen
> sizeof(buff
))
2266 lpBuff
= HeapAlloc(GetProcessHeap(), 0, dwMaxDataLen
);
2268 if (!lpszName
|| !lpBuff
)
2269 dwRet
= ERROR_NOT_ENOUGH_MEMORY
;
2274 /* Copy all the sub keys */
2275 for(i
= 0; i
< dwKeyCount
&& !dwRet
; i
++)
2277 HKEY hSubKeySrc
, hSubKeyDst
;
2278 DWORD dwSize
= dwMaxKeyLen
;
2280 dwRet
= RegEnumKeyExW(hKeySrc
, i
, lpszName
, &dwSize
, NULL
, NULL
, NULL
, NULL
);
2284 /* Open source sub key */
2285 dwRet
= RegOpenKeyExW(hKeySrc
, lpszName
, 0, KEY_READ
, &hSubKeySrc
);
2289 /* Create destination sub key */
2290 dwRet
= RegCreateKeyW(hKeyDst
, lpszName
, &hSubKeyDst
);
2294 /* Recursively copy keys and values from the sub key */
2295 dwRet
= SHCopyKeyW(hSubKeySrc
, NULL
, hSubKeyDst
, 0);
2296 RegCloseKey(hSubKeyDst
);
2299 RegCloseKey(hSubKeySrc
);
2303 /* Copy all the values in this key */
2304 for (i
= 0; i
< dwValueCount
&& !dwRet
; i
++)
2306 DWORD dwNameSize
= dwMaxKeyLen
, dwType
, dwLen
= dwMaxDataLen
;
2308 dwRet
= RegEnumValueW(hKeySrc
, i
, lpszName
, &dwNameSize
, NULL
, &dwType
, lpBuff
, &dwLen
);
2311 dwRet
= SHSetValueW(hKeyDst
, NULL
, lpszName
, dwType
, lpBuff
, dwLen
);
2314 /* Free buffers if allocated */
2315 if (lpszName
!= szName
)
2316 HeapFree(GetProcessHeap(), 0, lpszName
);
2318 HeapFree(GetProcessHeap(), 0, lpBuff
);
2320 if (lpszSrcSubKey
&& hKeyDst
)
2321 RegCloseKey(hKeyDst
);
2326 * The following functions are ORDINAL ONLY:
2329 /*************************************************************************
2332 * Read an integer value from the registry, falling back to a default.
2335 * hKey [I] Registry key to read from
2336 * lpszValue [I] Value name to read
2337 * iDefault [I] Default value to return
2340 * The value contained in the given registry value if present, otherwise
2343 int WINAPI
SHRegGetIntW(HKEY hKey
, LPCWSTR lpszValue
, int iDefault
)
2345 TRACE("(%p,%s,%d)\n", hKey
, debugstr_w(lpszValue
), iDefault
);
2350 DWORD dwSize
= sizeof(szBuff
);
2352 SHQueryValueExW(hKey
, lpszValue
, 0, 0, szBuff
, &dwSize
);
2354 if(*szBuff
>= '0' && *szBuff
<= '9')
2355 return StrToIntW(szBuff
);
2360 /*************************************************************************
2363 * Create or open an explorer ClassId Key.
2366 * guid [I] Explorer ClassId key to open
2367 * lpszValue [I] Value name under the ClassId Key
2368 * bUseHKCU [I] TRUE=Use HKEY_CURRENT_USER, FALSE=Use HKEY_CLASSES_ROOT
2369 * bCreate [I] TRUE=Create the key if it doesn't exist, FALSE=Don't
2370 * phKey [O] Destination for the resulting key handle
2373 * Success: S_OK. phKey contains the resulting registry handle.
2374 * Failure: An HRESULT error code indicating the problem.
2376 HRESULT WINAPI
SHRegGetCLSIDKeyA(REFGUID guid
, LPCSTR lpszValue
, BOOL bUseHKCU
, BOOL bCreate
, PHKEY phKey
)
2378 WCHAR szValue
[MAX_PATH
];
2381 MultiByteToWideChar(CP_ACP
, 0, lpszValue
, -1, szValue
, sizeof(szValue
)/sizeof(WCHAR
));
2383 return SHRegGetCLSIDKeyW(guid
, lpszValue
? szValue
: NULL
, bUseHKCU
, bCreate
, phKey
);
2386 /*************************************************************************
2389 * Unicode version of SHRegGetCLSIDKeyA.
2391 HRESULT WINAPI
SHRegGetCLSIDKeyW(REFGUID guid
, LPCWSTR lpszValue
, BOOL bUseHKCU
,
2392 BOOL bCreate
, PHKEY phKey
)
2394 static const WCHAR szClassIdKey
[] = { 'S','o','f','t','w','a','r','e','\\',
2395 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
2396 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2397 'E','x','p','l','o','r','e','r','\\','C','L','S','I','D','\\' };
2398 #define szClassIdKeyLen (sizeof(szClassIdKey)/sizeof(WCHAR))
2399 WCHAR szKey
[MAX_PATH
];
2403 /* Create the key string */
2404 memcpy(szKey
, szClassIdKey
, sizeof(szClassIdKey
));
2405 SHStringFromGUIDW(guid
, szKey
+ szClassIdKeyLen
, 39); /* Append guid */
2409 szKey
[szClassIdKeyLen
+ 39] = '\\';
2410 strcpyW(szKey
+ szClassIdKeyLen
+ 40, lpszValue
); /* Append value name */
2413 hkey
= bUseHKCU
? HKEY_CURRENT_USER
: HKEY_CLASSES_ROOT
;
2416 dwRet
= RegCreateKeyW(hkey
, szKey
, phKey
);
2418 dwRet
= RegOpenKeyExW(hkey
, szKey
, 0, KEY_READ
, phKey
);
2420 return dwRet
? HRESULT_FROM_WIN32(dwRet
) : S_OK
;
2423 /*************************************************************************
2424 * SHRegisterValidateTemplate [SHLWAPI.@]
2426 * observed from the ie 5.5 installer:
2427 * - allocates a buffer with the size of the given file
2428 * - read the file content into the buffer
2429 * - creates the key szTemplateKey
2430 * - sets "205523652929647911071668590831910975402"=dword:00002e37 at
2434 * filename [I] An existing file its content is read into an allocated
2439 * Success: ERROR_SUCCESS.
2441 HRESULT WINAPI
SHRegisterValidateTemplate(LPCWSTR filename
, BOOL unknown
)
2443 /* static const WCHAR szTemplateKey[] = { 'S','o','f','t','w','a','r','e','\\',
2444 * 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
2445 * 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2446 * 'E','x','p','l','o','r','e','r','\\',
2447 * 'T','e','m','p','l','a','t','e','R','e','g','i','s','t','r','y',0 };
2449 FIXME("stub: %s, %08x\n", debugstr_w(filename
), unknown
);