-/*\r
- * SHLWAPI registry functions\r
- *\r
- * Copyright 1998 Juergen Schmied\r
- * Copyright 2001 Guy Albertelli\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Lesser General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2.1 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Lesser General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- */\r
-\r
-#include <stdarg.h>\r
-#include <string.h>\r
-#include "windef.h"\r
-#include "winbase.h"\r
-#include "winuser.h"\r
-#include "winreg.h"\r
-#include "wine/debug.h"\r
-#define NO_SHLWAPI_STREAM\r
-#include "shlwapi.h"\r
-#include "wine/unicode.h"\r
-\r
-WINE_DEFAULT_DEBUG_CHANNEL(shell);\r
-\r
-/* Key/Value names for MIME content types */\r
-static const char *lpszContentTypeA = "Content Type";\r
-static const WCHAR lpszContentTypeW[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};\r
-\r
-static const char *szMimeDbContentA = "MIME\\Database\\Content Type\\";\r
-static const WCHAR szMimeDbContentW[] = { 'M', 'I', 'M','E','\\',\r
- 'D','a','t','a','b','a','s','e','\\','C','o','n','t','e','n','t',\r
- ' ','T','y','p','e','\\', 0 };\r
-static const DWORD dwLenMimeDbContent = 27; /* strlen of szMimeDbContentA/W */\r
-\r
-static const char *szExtensionA = "Extension";\r
-static const WCHAR szExtensionW[] = { 'E', 'x', 't','e','n','s','i','o','n','\0' };\r
-\r
-/* internal structure of what the HUSKEY points to */\r
-typedef struct {\r
- HKEY HKCUstart; /* Start key in CU hive */\r
- HKEY HKCUkey; /* Opened key in CU hive */\r
- HKEY HKLMstart; /* Start key in LM hive */\r
- HKEY HKLMkey; /* Opened key in LM hive */\r
- WCHAR lpszPath[MAX_PATH];\r
-} SHUSKEY, *LPSHUSKEY;\r
-\r
-DWORD WINAPI SHStringFromGUIDW(REFGUID,LPWSTR,INT);\r
-HRESULT WINAPI SHRegGetCLSIDKeyW(REFGUID,LPCWSTR,BOOL,BOOL,PHKEY);\r
-\r
-\r
-#define REG_HKCU TRUE\r
-#define REG_HKLM FALSE\r
-/*************************************************************************\r
- * REG_GetHKEYFromHUSKEY\r
- *\r
- * Function: Return the proper registry key from the HUSKEY structure\r
- * also allow special predefined values.\r
- */\r
-static HKEY WINAPI REG_GetHKEYFromHUSKEY(HUSKEY hUSKey, BOOL which)\r
-{\r
- HKEY test = (HKEY) hUSKey;\r
- LPSHUSKEY mihk = (LPSHUSKEY) hUSKey;\r
-\r
- if ((test == HKEY_CLASSES_ROOT) ||\r
- (test == HKEY_CURRENT_CONFIG) ||\r
- (test == HKEY_CURRENT_USER) ||\r
- (test == HKEY_DYN_DATA) ||\r
- (test == HKEY_LOCAL_MACHINE) ||\r
- (test == HKEY_PERFORMANCE_DATA) ||\r
-/* FIXME: need to define for Win2k, ME, XP\r
- * (test == HKEY_PERFORMANCE_TEXT) ||\r
- * (test == HKEY_PERFORMANCE_NLSTEXT) ||\r
- */\r
- (test == HKEY_USERS)) return test;\r
- if (which == REG_HKCU) return mihk->HKCUkey;\r
- return mihk->HKLMkey;\r
-}\r
-\r
-\r
-/*************************************************************************\r
- * SHRegOpenUSKeyA [SHLWAPI.@]\r
- *\r
- * Open a user-specific registry key.\r
- *\r
- * PARAMS\r
- * Path [I] Key name to open\r
- * AccessType [I] Access type\r
- * hRelativeUSKey [I] Relative user key\r
- * phNewUSKey [O] Destination for created key\r
- * fIgnoreHKCU [I] TRUE=Don't check HKEY_CURRENT_USER\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS\r
- * Failure: An error code from RegOpenKeyExA().\r
- */\r
-LONG WINAPI SHRegOpenUSKeyA(LPCSTR Path, REGSAM AccessType, HUSKEY hRelativeUSKey,\r
- PHUSKEY phNewUSKey, BOOL fIgnoreHKCU)\r
-{\r
- WCHAR szPath[MAX_PATH];\r
-\r
- if (Path)\r
- MultiByteToWideChar(CP_ACP, 0, Path, -1, szPath, MAX_PATH);\r
-\r
- return SHRegOpenUSKeyW(Path ? szPath : NULL, AccessType, hRelativeUSKey,\r
- phNewUSKey, fIgnoreHKCU);\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegOpenUSKeyW [SHLWAPI.@]\r
- *\r
- * See SHRegOpenUSKeyA.\r
- */\r
-LONG WINAPI SHRegOpenUSKeyW(LPCWSTR Path, REGSAM AccessType, HUSKEY hRelativeUSKey,\r
- PHUSKEY phNewUSKey, BOOL fIgnoreHKCU)\r
-{\r
- LONG ret2, ret1 = ~ERROR_SUCCESS;\r
- LPSHUSKEY hKey;\r
-\r
- TRACE("(%s,0x%lx,%p,%p,%d)\n", debugstr_w(Path),(LONG)AccessType,\r
- hRelativeUSKey, phNewUSKey, fIgnoreHKCU);\r
-\r
- if (phNewUSKey)\r
- *phNewUSKey = NULL;\r
-\r
- /* Create internal HUSKEY */\r
- hKey = (LPSHUSKEY)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*hKey));\r
- lstrcpynW(hKey->lpszPath, Path, sizeof(hKey->lpszPath));\r
-\r
- if (hRelativeUSKey)\r
- {\r
- hKey->HKCUstart = SHRegDuplicateHKey(REG_GetHKEYFromHUSKEY(hRelativeUSKey, REG_HKCU));\r
- hKey->HKLMstart = SHRegDuplicateHKey(REG_GetHKEYFromHUSKEY(hRelativeUSKey, REG_HKLM));\r
-\r
- /* FIXME: if either of these keys is NULL, create the start key from\r
- * the relative keys start+path\r
- */\r
- }\r
- else\r
- {\r
- hKey->HKCUstart = HKEY_CURRENT_USER;\r
- hKey->HKLMstart = HKEY_LOCAL_MACHINE;\r
- }\r
-\r
- if (!fIgnoreHKCU)\r
- {\r
- ret1 = RegOpenKeyExW(hKey->HKCUstart, hKey->lpszPath, 0, AccessType, &hKey->HKCUkey);\r
- if (ret1)\r
- hKey->HKCUkey = 0;\r
- }\r
-\r
- ret2 = RegOpenKeyExW(hKey->HKLMstart, hKey->lpszPath, 0, AccessType, &hKey->HKLMkey);\r
- if (ret2)\r
- hKey->HKLMkey = 0;\r
-\r
- if (ret1 || ret2)\r
- TRACE("one or more opens failed: HKCU=%ld HKLM=%ld\n", ret1, ret2);\r
-\r
- if (ret1 && ret2)\r
- {\r
- /* Neither open succeeded: fail */\r
- SHRegCloseUSKey(hKey);\r
- return ret2;\r
- }\r
-\r
- TRACE("HUSKEY=%p\n", hKey);\r
- if (phNewUSKey)\r
- *phNewUSKey = (HUSKEY)hKey;\r
- return ERROR_SUCCESS;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegCloseUSKey [SHLWAPI.@]\r
- *\r
- * Close a user-specific registry key\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS\r
- * Failure: An error code from RegCloseKey().\r
- */\r
-LONG WINAPI SHRegCloseUSKey(\r
- HUSKEY hUSKey) /* [I] Key to close */\r
-{\r
- LPSHUSKEY hKey = (LPSHUSKEY)hUSKey;\r
- LONG ret = ERROR_SUCCESS;\r
-\r
- if (hKey->HKCUkey)\r
- ret = RegCloseKey(hKey->HKCUkey);\r
- if (hKey->HKCUstart && hKey->HKCUstart != HKEY_CURRENT_USER)\r
- ret = RegCloseKey(hKey->HKCUstart);\r
- if (hKey->HKLMkey)\r
- ret = RegCloseKey(hKey->HKLMkey);\r
- if (hKey->HKLMstart && hKey->HKLMstart != HKEY_LOCAL_MACHINE)\r
- ret = RegCloseKey(hKey->HKCUstart);\r
-\r
- HeapFree(GetProcessHeap(), 0, hKey);\r
- return ret;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegCreateUSKeyA [SHLWAPI.@]\r
- *\r
- * Create or open a user-specific registry key.\r
- * \r
- * PARAMS\r
- * pszPath [I] Key name to create or open.\r
- * samDesired [I] Wanted security access.\r
- * hRelativeUSKey [I] Base path if pszPath is relative. NULL otherwise.\r
- * phNewUSKey [O] Receives a handle to the new or openened key.\r
- * dwFlags [I] Base key under which the key should be opened.\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS\r
- * Failure: Nonzero error code from winerror.h\r
- */\r
-LONG WINAPI SHRegCreateUSKeyA(LPCSTR pszPath, REGSAM samDesired, HUSKEY hRelativeUSKey,\r
- PHUSKEY phNewUSKey, DWORD dwFlags)\r
-{\r
- FIXME("(%s, 0x%08lx, %p, %p, 0x%08lx) stub\n", debugstr_a(pszPath), samDesired,\r
- hRelativeUSKey, phNewUSKey, dwFlags);\r
- return ERROR_SUCCESS;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegCreateUSKeyW [SHLWAPI.@]\r
- *\r
- * See SHRegCreateUSKeyA.\r
- */\r
-LONG WINAPI SHRegCreateUSKeyW(LPCWSTR pszPath, REGSAM samDesired, HUSKEY hRelativeUSKey,\r
- PHUSKEY phNewUSKey, DWORD dwFlags)\r
-{\r
- FIXME("(%s, 0x%08lx, %p, %p, 0x%08lx) stub\n", debugstr_w(pszPath), samDesired,\r
- hRelativeUSKey, phNewUSKey, dwFlags);\r
- return ERROR_SUCCESS;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegDeleteEmptyUSKeyA [SHLWAPI.@]\r
- *\r
- * Delete an empty user-specific registry key.\r
- *\r
- * PARAMS\r
- * hUSKey [I] Handle to an open registry key.\r
- * pszValue [I] Empty key name.\r
- * delRegFlags [I] Flag that specifies the base from which to delete \r
- * the key.\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS\r
- * Failure: Nonzero error code from winerror.h\r
- */\r
-LONG WINAPI SHRegDeleteEmptyUSKeyA(HUSKEY hUSKey, LPCSTR pszValue, SHREGDEL_FLAGS delRegFlags)\r
-{\r
- FIXME("(%p, %s, 0x%08x) stub\n", hUSKey, debugstr_a(pszValue), delRegFlags);\r
- return ERROR_SUCCESS;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegDeleteEmptyUSKeyW [SHLWAPI.@]\r
- *\r
- * See SHRegDeleteEmptyUSKeyA.\r
- */\r
-LONG WINAPI SHRegDeleteEmptyUSKeyW(HUSKEY hUSKey, LPCWSTR pszValue, SHREGDEL_FLAGS delRegFlags)\r
-{\r
- FIXME("(%p, %s, 0x%08x) stub\n", hUSKey, debugstr_w(pszValue), delRegFlags);\r
- return ERROR_SUCCESS;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegDeleteUSValueA [SHLWAPI.@]\r
- *\r
- * Delete a user-specific registry value.\r
- *\r
- * PARAMS\r
- * hUSKey [I] Handle to an open registry key.\r
- * pszValue [I] Specifies the value to delete.\r
- * delRegFlags [I] Flag that specifies the base of the key from which to\r
- * delete the value.\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS\r
- * Failure: Nonzero error code from winerror.h\r
- */\r
-LONG WINAPI SHRegDeleteUSValueA(HUSKEY hUSKey, LPCSTR pszValue, SHREGDEL_FLAGS delRegFlags)\r
-{\r
- FIXME("(%p, %s, 0x%08x) stub\n", hUSKey, debugstr_a(pszValue), delRegFlags);\r
- return ERROR_SUCCESS;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegDeleteUSValueW [SHLWAPI.@]\r
- *\r
- * See SHRegDeleteUSValueA.\r
- */\r
-LONG WINAPI SHRegDeleteUSValueW(HUSKEY hUSKey, LPCWSTR pszValue, SHREGDEL_FLAGS delRegFlags)\r
-{\r
- FIXME("(%p, %s, 0x%08x) stub\n", hUSKey, debugstr_w(pszValue), delRegFlags);\r
- return ERROR_SUCCESS;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegEnumUSValueA [SHLWAPI.@]\r
- *\r
- * Enumerate values of a specified registry key.\r
- *\r
- * PARAMS\r
- * hUSKey [I] Handle to an open registry key.\r
- * dwIndex [I] Index of the value to be retrieved.\r
- * pszValueName [O] Buffer to receive the value name.\r
- * pcchValueNameLen [I] Size of pszValueName in characters.\r
- * pdwType [O] Receives data type of the value.\r
- * pvData [O] Receives value data. May be NULL.\r
- * pcbData [I/O] Size of pvData in bytes.\r
- * enumRegFlags [I] Flag that specifies the base key under which to\r
- * enumerate values.\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS\r
- * Failure: Nonzero error code from winerror.h\r
- */\r
-LONG WINAPI SHRegEnumUSValueA(HUSKEY hUSKey, DWORD dwIndex, LPSTR pszValueName,\r
- LPDWORD pcchValueNameLen, LPDWORD pdwType, LPVOID pvData,\r
- LPDWORD pcbData, SHREGENUM_FLAGS enumRegFlags)\r
-{\r
- FIXME("(%p, 0x%08lx, %s, %p, %p, %p, %p, 0x%08x) stub\n", hUSKey, dwIndex,\r
- debugstr_a(pszValueName), pcchValueNameLen, pdwType, pvData, pcbData, enumRegFlags);\r
- return ERROR_INVALID_FUNCTION;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegEnumUSValueW [SHLWAPI.@]\r
- *\r
- * See SHRegEnumUSValueA.\r
- */\r
-LONG WINAPI SHRegEnumUSValueW(HUSKEY hUSKey, DWORD dwIndex, LPWSTR pszValueName,\r
- LPDWORD pcchValueNameLen, LPDWORD pdwType, LPVOID pvData,\r
- LPDWORD pcbData, SHREGENUM_FLAGS enumRegFlags)\r
-{\r
- FIXME("(%p, 0x%08lx, %s, %p, %p, %p, %p, 0x%08x) stub\n", hUSKey, dwIndex,\r
- debugstr_w(pszValueName), pcchValueNameLen, pdwType, pvData, pcbData, enumRegFlags);\r
- return ERROR_INVALID_FUNCTION;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegQueryUSValueA [SHLWAPI.@]\r
- *\r
- * Query a user-specific registry value.\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS\r
- * Failure: An error code from RegQueryValueExA().\r
- */\r
-LONG WINAPI SHRegQueryUSValueA(\r
- HUSKEY hUSKey, /* [I] Key to query */\r
- LPCSTR pszValue, /* [I] Value name under hUSKey */\r
- LPDWORD pdwType, /* [O] Destination for value type */\r
- LPVOID pvData, /* [O] Destination for value data */\r
- LPDWORD pcbData, /* [O] Destination for value length */\r
- BOOL fIgnoreHKCU, /* [I] TRUE=Don't check HKEY_CURRENT_USER */\r
- LPVOID pvDefaultData, /* [I] Default data if pszValue does not exist */\r
- DWORD dwDefaultDataSize) /* [I] Length of pvDefaultData */\r
-{\r
- LONG ret = ~ERROR_SUCCESS;\r
- LONG i, maxmove;\r
- HKEY dokey;\r
- CHAR *src, *dst;\r
-\r
- /* if user wants HKCU, and it exists, then try it */\r
- if (!fIgnoreHKCU && (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKCU))) {\r
- ret = RegQueryValueExA(dokey,\r
- pszValue, 0, pdwType, pvData, pcbData);\r
- TRACE("HKCU RegQueryValue returned %08lx\n", ret);\r
- }\r
-\r
- /* if HKCU did not work and HKLM exists, then try it */\r
- if ((ret != ERROR_SUCCESS) &&\r
- (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKLM))) {\r
- ret = RegQueryValueExA(dokey,\r
- pszValue, 0, pdwType, pvData, pcbData);\r
- TRACE("HKLM RegQueryValue returned %08lx\n", ret);\r
- }\r
-\r
- /* if neither worked, and default data exists, then use it */\r
- if (ret != ERROR_SUCCESS) {\r
- if (pvDefaultData && (dwDefaultDataSize != 0)) {\r
- maxmove = (dwDefaultDataSize >= *pcbData) ? *pcbData : dwDefaultDataSize;\r
- src = (CHAR*)pvDefaultData;\r
- dst = (CHAR*)pvData;\r
- for(i=0; i<maxmove; i++) *dst++ = *src++;\r
- *pcbData = maxmove;\r
- TRACE("setting default data\n");\r
- ret = ERROR_SUCCESS;\r
- }\r
- }\r
- return ret;\r
-}\r
-\r
-\r
-/*************************************************************************\r
- * SHRegQueryUSValueW [SHLWAPI.@]\r
- *\r
- * See SHRegQueryUSValueA.\r
- */\r
-LONG WINAPI SHRegQueryUSValueW(\r
- HUSKEY hUSKey,\r
- LPCWSTR pszValue,\r
- LPDWORD pdwType,\r
- LPVOID pvData,\r
- LPDWORD pcbData,\r
- BOOL fIgnoreHKCU,\r
- LPVOID pvDefaultData,\r
- DWORD dwDefaultDataSize)\r
-{\r
- LONG ret = ~ERROR_SUCCESS;\r
- LONG i, maxmove;\r
- HKEY dokey;\r
- CHAR *src, *dst;\r
-\r
- /* if user wants HKCU, and it exists, then try it */\r
- if (!fIgnoreHKCU && (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKCU))) {\r
- ret = RegQueryValueExW(dokey,\r
- pszValue, 0, pdwType, pvData, pcbData);\r
- TRACE("HKCU RegQueryValue returned %08lx\n", ret);\r
- }\r
-\r
- /* if HKCU did not work and HKLM exists, then try it */\r
- if ((ret != ERROR_SUCCESS) &&\r
- (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKLM))) {\r
- ret = RegQueryValueExW(dokey,\r
- pszValue, 0, pdwType, pvData, pcbData);\r
- TRACE("HKLM RegQueryValue returned %08lx\n", ret);\r
- }\r
-\r
- /* if neither worked, and default data exists, then use it */\r
- if (ret != ERROR_SUCCESS) {\r
- if (pvDefaultData && (dwDefaultDataSize != 0)) {\r
- maxmove = (dwDefaultDataSize >= *pcbData) ? *pcbData : dwDefaultDataSize;\r
- src = (CHAR*)pvDefaultData;\r
- dst = (CHAR*)pvData;\r
- for(i=0; i<maxmove; i++) *dst++ = *src++;\r
- *pcbData = maxmove;\r
- TRACE("setting default data\n");\r
- ret = ERROR_SUCCESS;\r
- }\r
- }\r
- return ret;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegGetUSValueA [SHLWAPI.@]\r
- *\r
- * Get a user-specific registry value.\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS\r
- * Failure: An error code from SHRegOpenUSKeyA() or SHRegQueryUSValueA().\r
- *\r
- * NOTES\r
- * This function opens pSubKey, queries the value, and then closes the key.\r
- */\r
-LONG WINAPI SHRegGetUSValueA(\r
- LPCSTR pSubKey, /* [I] Key name to open */\r
- LPCSTR pValue, /* [I] Value name to open */\r
- LPDWORD pwType, /* [O] Destination for the type of the value */\r
- LPVOID pvData, /* [O] Destination for the value */\r
- LPDWORD pcbData, /* [I] Destination for the length of the value **/\r
- BOOL flagIgnoreHKCU, /* [I] TRUE=Don't check HKEY_CURRENT_USER */\r
- LPVOID pDefaultData, /* [I] Default value if it doesn't exist */\r
- DWORD wDefaultDataSize) /* [I] Length of pDefaultData */\r
-{\r
- HUSKEY myhuskey;\r
- LONG ret;\r
-\r
- if (!pvData || !pcbData) return ERROR_INVALID_FUNCTION; /* FIXME:wrong*/\r
- TRACE("key '%s', value '%s', datalen %ld, %s\n",\r
- debugstr_a(pSubKey), debugstr_a(pValue), *pcbData,\r
- (flagIgnoreHKCU) ? "Ignoring HKCU" : "Tries HKCU then HKLM");\r
-\r
- ret = SHRegOpenUSKeyA(pSubKey, 0x1, 0, &myhuskey, flagIgnoreHKCU);\r
- if (ret == ERROR_SUCCESS) {\r
- ret = SHRegQueryUSValueA(myhuskey, pValue, pwType, pvData,\r
- pcbData, flagIgnoreHKCU, pDefaultData,\r
- wDefaultDataSize);\r
- SHRegCloseUSKey(myhuskey);\r
- }\r
- return ret;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegGetUSValueW [SHLWAPI.@]\r
- *\r
- * See SHRegGetUSValueA.\r
- */\r
-LONG WINAPI SHRegGetUSValueW(\r
- LPCWSTR pSubKey,\r
- LPCWSTR pValue,\r
- LPDWORD pwType,\r
- LPVOID pvData,\r
- LPDWORD pcbData,\r
- BOOL flagIgnoreHKCU,\r
- LPVOID pDefaultData,\r
- DWORD wDefaultDataSize)\r
-{\r
- HUSKEY myhuskey;\r
- LONG ret;\r
-\r
- if (!pvData || !pcbData) return ERROR_INVALID_FUNCTION; /* FIXME:wrong*/\r
- TRACE("key '%s', value '%s', datalen %ld, %s\n",\r
- debugstr_w(pSubKey), debugstr_w(pValue), *pcbData,\r
- (flagIgnoreHKCU) ? "Ignoring HKCU" : "Tries HKCU then HKLM");\r
-\r
- ret = SHRegOpenUSKeyW(pSubKey, 0x1, 0, &myhuskey, flagIgnoreHKCU);\r
- if (ret == ERROR_SUCCESS) {\r
- ret = SHRegQueryUSValueW(myhuskey, pValue, pwType, pvData,\r
- pcbData, flagIgnoreHKCU, pDefaultData,\r
- wDefaultDataSize);\r
- SHRegCloseUSKey(myhuskey);\r
- }\r
- return ret;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegSetUSValueA [SHLWAPI.@]\r
- *\r
- * Set a user-specific registry value.\r
- *\r
- * PARAMS\r
- * pszSubKey [I] Name of key to set the value in\r
- * pszValue [I] Name of value under pszSubKey to set the value in\r
- * dwType [I] Type of the value\r
- * pvData [I] Data to set as the value\r
- * cbData [I] length of pvData\r
- * dwFlags [I] SHREGSET_ flags from "shlwapi.h"\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS\r
- * Failure: An error code from SHRegOpenUSKeyA() or SHRegWriteUSValueA(), or\r
- * ERROR_INVALID_FUNCTION if pvData is NULL.\r
- *\r
- * NOTES\r
- * This function opens pszSubKey, sets the value, and then closes the key.\r
- */\r
-LONG WINAPI SHRegSetUSValueA(LPCSTR pszSubKey, LPCSTR pszValue, DWORD dwType,\r
- LPVOID pvData, DWORD cbData, DWORD dwFlags)\r
-{\r
- BOOL ignoreHKCU = TRUE;\r
- HUSKEY hkey;\r
- LONG ret;\r
-\r
- TRACE("(%s,%s,%ld,%p,%ld,0x%08lx\n", debugstr_a(pszSubKey), debugstr_a(pszValue),\r
- dwType, pvData, cbData, dwFlags);\r
-\r
- if (!pvData)\r
- return ERROR_INVALID_FUNCTION;\r
-\r
- if (dwFlags & SHREGSET_HKCU || dwFlags & SHREGSET_FORCE_HKCU)\r
- ignoreHKCU = FALSE;\r
-\r
- ret = SHRegOpenUSKeyA(pszSubKey, KEY_ALL_ACCESS, 0, &hkey, ignoreHKCU);\r
- if (ret == ERROR_SUCCESS)\r
- {\r
- ret = SHRegWriteUSValueA(hkey, pszValue, dwType, pvData, cbData, dwFlags);\r
- SHRegCloseUSKey(hkey);\r
- }\r
- return ret;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegSetUSValueW [SHLWAPI.@]\r
- *\r
- * See SHRegSetUSValueA.\r
- */\r
-LONG WINAPI SHRegSetUSValueW(LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwType,\r
- LPVOID pvData, DWORD cbData, DWORD dwFlags)\r
-{\r
- BOOL ignoreHKCU = TRUE;\r
- HUSKEY hkey;\r
- LONG ret;\r
-\r
- TRACE("(%s,%s,%ld,%p,%ld,0x%08lx\n", debugstr_w(pszSubKey), debugstr_w(pszValue),\r
- dwType, pvData, cbData, dwFlags);\r
-\r
- if (!pvData)\r
- return ERROR_INVALID_FUNCTION;\r
-\r
- if (dwFlags & SHREGSET_HKCU || dwFlags & SHREGSET_FORCE_HKCU)\r
- ignoreHKCU = FALSE;\r
-\r
- ret = SHRegOpenUSKeyW(pszSubKey, KEY_ALL_ACCESS, 0, &hkey, ignoreHKCU);\r
- if (ret == ERROR_SUCCESS)\r
- {\r
- ret = SHRegWriteUSValueW(hkey, pszValue, dwType, pvData, cbData, dwFlags);\r
- SHRegCloseUSKey(hkey);\r
- }\r
- return ret;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegGetBoolUSValueA [SHLWAPI.@]\r
- *\r
- * Get a user-specific registry boolean value.\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS\r
- * Failure: An error code from SHRegOpenUSKeyA() or SHRegQueryUSValueA().\r
- *\r
- * NOTES\r
- * This function opens pszSubKey, queries the value, and then closes the key.\r
- *\r
- * Boolean values are one of the following:\r
- * True: YES,TRUE,non-zero\r
- * False: NO,FALSE,0\r
- */\r
-BOOL WINAPI SHRegGetBoolUSValueA(\r
- LPCSTR pszSubKey, /* [I] Key name to open */\r
- LPCSTR pszValue, /* [I] Value name to open */\r
- BOOL fIgnoreHKCU, /* [I] TRUE=Don't check HKEY_CURRENT_USER */\r
- BOOL fDefault) /* [I] Default value to use if pszValue is not present */\r
-{\r
- LONG retvalue;\r
- DWORD type, datalen, work;\r
- BOOL ret = fDefault;\r
- CHAR data[10];\r
-\r
- TRACE("key '%s', value '%s', %s\n",\r
- debugstr_a(pszSubKey), debugstr_a(pszValue),\r
- (fIgnoreHKCU) ? "Ignoring HKCU" : "Tries HKCU then HKLM");\r
-\r
- datalen = sizeof(data)-1;\r
- if (!(retvalue = SHRegGetUSValueA( pszSubKey, pszValue, &type,\r
- data, &datalen,\r
- fIgnoreHKCU, 0, 0))) {\r
- /* process returned data via type into bool */\r
- switch (type) {\r
- case REG_SZ:\r
- data[9] = '\0'; /* set end of string */\r
- if (lstrcmpiA(data, "YES") == 0) ret = TRUE;\r
- if (lstrcmpiA(data, "TRUE") == 0) ret = TRUE;\r
- if (lstrcmpiA(data, "NO") == 0) ret = FALSE;\r
- if (lstrcmpiA(data, "FALSE") == 0) ret = FALSE;\r
- break;\r
- case REG_DWORD:\r
- work = *(LPDWORD)data;\r
- ret = (work != 0);\r
- break;\r
- case REG_BINARY:\r
- if (datalen == 1) {\r
- ret = (data[0] != '\0');\r
- break;\r
- }\r
- default:\r
- FIXME("Unsupported registry data type %ld\n", type);\r
- ret = FALSE;\r
- }\r
- TRACE("got value (type=%ld), returing <%s>\n", type,\r
- (ret) ? "TRUE" : "FALSE");\r
- }\r
- else {\r
- ret = fDefault;\r
- TRACE("returning default data <%s>\n",\r
- (ret) ? "TRUE" : "FALSE");\r
- }\r
- return ret;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegGetBoolUSValueW [SHLWAPI.@]\r
- *\r
- * See SHRegGetBoolUSValueA.\r
- */\r
-BOOL WINAPI SHRegGetBoolUSValueW(\r
- LPCWSTR pszSubKey,\r
- LPCWSTR pszValue,\r
- BOOL fIgnoreHKCU,\r
- BOOL fDefault)\r
-{\r
- static const WCHAR wYES[]= {'Y','E','S','\0'};\r
- static const WCHAR wTRUE[]= {'T','R','U','E','\0'};\r
- static const WCHAR wNO[]= {'N','O','\0'};\r
- static const WCHAR wFALSE[]={'F','A','L','S','E','\0'};\r
- LONG retvalue;\r
- DWORD type, datalen, work;\r
- BOOL ret = fDefault;\r
- WCHAR data[10];\r
-\r
- TRACE("key '%s', value '%s', %s\n",\r
- debugstr_w(pszSubKey), debugstr_w(pszValue),\r
- (fIgnoreHKCU) ? "Ignoring HKCU" : "Tries HKCU then HKLM");\r
-\r
- datalen = (sizeof(data)-1) * sizeof(WCHAR);\r
- if (!(retvalue = SHRegGetUSValueW( pszSubKey, pszValue, &type,\r
- data, &datalen,\r
- fIgnoreHKCU, 0, 0))) {\r
- /* process returned data via type into bool */\r
- switch (type) {\r
- case REG_SZ:\r
- data[9] = L'\0'; /* set end of string */\r
- if (lstrcmpiW(data, wYES)==0 || lstrcmpiW(data, wTRUE)==0)\r
- ret = TRUE;\r
- else if (lstrcmpiW(data, wNO)==0 || lstrcmpiW(data, wFALSE)==0)\r
- ret = FALSE;\r
- break;\r
- case REG_DWORD:\r
- work = *(LPDWORD)data;\r
- ret = (work != 0);\r
- break;\r
- case REG_BINARY:\r
- if (datalen == 1) {\r
- ret = (data[0] != L'\0');\r
- break;\r
- }\r
- default:\r
- FIXME("Unsupported registry data type %ld\n", type);\r
- ret = FALSE;\r
- }\r
- TRACE("got value (type=%ld), returing <%s>\n", type,\r
- (ret) ? "TRUE" : "FALSE");\r
- }\r
- else {\r
- ret = fDefault;\r
- TRACE("returning default data <%s>\n",\r
- (ret) ? "TRUE" : "FALSE");\r
- }\r
- return ret;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegQueryInfoUSKeyA [SHLWAPI.@]\r
- *\r
- * Get information about a user-specific registry key.\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS\r
- * Failure: An error code from RegQueryInfoKeyA().\r
- */\r
-LONG WINAPI SHRegQueryInfoUSKeyA(\r
- HUSKEY hUSKey, /* [I] Key to query */\r
- LPDWORD pcSubKeys, /* [O] Destination for number of sub keys */\r
- LPDWORD pcchMaxSubKeyLen, /* [O] Destination for the length of the biggest sub key name */\r
- LPDWORD pcValues, /* [O] Destination for number of values */\r
- LPDWORD pcchMaxValueNameLen,/* [O] Destination for the length of the biggest value */\r
- SHREGENUM_FLAGS enumRegFlags) /* [in] SHREGENUM_ flags from "shlwapi.h" */\r
-{\r
- HKEY dokey;\r
- LONG ret;\r
-\r
- TRACE("(%p,%p,%p,%p,%p,%d)\n",\r
- hUSKey,pcSubKeys,pcchMaxSubKeyLen,pcValues,\r
- pcchMaxValueNameLen,enumRegFlags);\r
-\r
- /* if user wants HKCU, and it exists, then try it */\r
- if (((enumRegFlags == SHREGENUM_HKCU) ||\r
- (enumRegFlags == SHREGENUM_DEFAULT)) &&\r
- (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKCU))) {\r
- ret = RegQueryInfoKeyA(dokey, 0, 0, 0,\r
- pcSubKeys, pcchMaxSubKeyLen, 0,\r
- pcValues, pcchMaxValueNameLen, 0, 0, 0);\r
- if ((ret == ERROR_SUCCESS) ||\r
- (enumRegFlags == SHREGENUM_HKCU))\r
- return ret;\r
- }\r
- if (((enumRegFlags == SHREGENUM_HKLM) ||\r
- (enumRegFlags == SHREGENUM_DEFAULT)) &&\r
- (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKLM))) {\r
- return RegQueryInfoKeyA(dokey, 0, 0, 0,\r
- pcSubKeys, pcchMaxSubKeyLen, 0,\r
- pcValues, pcchMaxValueNameLen, 0, 0, 0);\r
- }\r
- return ERROR_INVALID_FUNCTION;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegQueryInfoUSKeyW [SHLWAPI.@]\r
- *\r
- * See SHRegQueryInfoUSKeyA.\r
- */\r
-LONG WINAPI SHRegQueryInfoUSKeyW(\r
- HUSKEY hUSKey,\r
- LPDWORD pcSubKeys,\r
- LPDWORD pcchMaxSubKeyLen,\r
- LPDWORD pcValues,\r
- LPDWORD pcchMaxValueNameLen,\r
- SHREGENUM_FLAGS enumRegFlags)\r
-{\r
- HKEY dokey;\r
- LONG ret;\r
-\r
- TRACE("(%p,%p,%p,%p,%p,%d)\n",\r
- hUSKey,pcSubKeys,pcchMaxSubKeyLen,pcValues,\r
- pcchMaxValueNameLen,enumRegFlags);\r
-\r
- /* if user wants HKCU, and it exists, then try it */\r
- if (((enumRegFlags == SHREGENUM_HKCU) ||\r
- (enumRegFlags == SHREGENUM_DEFAULT)) &&\r
- (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKCU))) {\r
- ret = RegQueryInfoKeyW(dokey, 0, 0, 0,\r
- pcSubKeys, pcchMaxSubKeyLen, 0,\r
- pcValues, pcchMaxValueNameLen, 0, 0, 0);\r
- if ((ret == ERROR_SUCCESS) ||\r
- (enumRegFlags == SHREGENUM_HKCU))\r
- return ret;\r
- }\r
- if (((enumRegFlags == SHREGENUM_HKLM) ||\r
- (enumRegFlags == SHREGENUM_DEFAULT)) &&\r
- (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKLM))) {\r
- return RegQueryInfoKeyW(dokey, 0, 0, 0,\r
- pcSubKeys, pcchMaxSubKeyLen, 0,\r
- pcValues, pcchMaxValueNameLen, 0, 0, 0);\r
- }\r
- return ERROR_INVALID_FUNCTION;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegEnumUSKeyA [SHLWAPI.@]\r
- *\r
- * Enumerate a user-specific registry key.\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS\r
- * Failure: An error code from RegEnumKeyExA().\r
- */\r
-LONG WINAPI SHRegEnumUSKeyA(\r
- HUSKEY hUSKey, /* [in] Key to enumerate */\r
- DWORD dwIndex, /* [in] Index within hUSKey */\r
- LPSTR pszName, /* [out] Name of the enumerated value */\r
- LPDWORD pcchValueNameLen, /* [in/out] Length of pszName */\r
- SHREGENUM_FLAGS enumRegFlags) /* [in] SHREGENUM_ flags from "shlwapi.h" */\r
-{\r
- HKEY dokey;\r
-\r
- TRACE("(%p,%ld,%p,%p(%ld),%d)\n",\r
- hUSKey, dwIndex, pszName, pcchValueNameLen,\r
- *pcchValueNameLen, enumRegFlags);\r
-\r
- if (((enumRegFlags == SHREGENUM_HKCU) ||\r
- (enumRegFlags == SHREGENUM_DEFAULT)) &&\r
- (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKCU))) {\r
- return RegEnumKeyExA(dokey, dwIndex, pszName, pcchValueNameLen,\r
- 0, 0, 0, 0);\r
- }\r
-\r
- if (((enumRegFlags == SHREGENUM_HKLM) ||\r
- (enumRegFlags == SHREGENUM_DEFAULT)) &&\r
- (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKLM))) {\r
- return RegEnumKeyExA(dokey, dwIndex, pszName, pcchValueNameLen,\r
- 0, 0, 0, 0);\r
- }\r
- FIXME("no support for SHREGENUM_BOTH\n");\r
- return ERROR_INVALID_FUNCTION;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegEnumUSKeyW [SHLWAPI.@]\r
- *\r
- * See SHRegEnumUSKeyA.\r
- */\r
-LONG WINAPI SHRegEnumUSKeyW(\r
- HUSKEY hUSKey,\r
- DWORD dwIndex,\r
- LPWSTR pszName,\r
- LPDWORD pcchValueNameLen,\r
- SHREGENUM_FLAGS enumRegFlags)\r
-{\r
- HKEY dokey;\r
-\r
- TRACE("(%p,%ld,%p,%p(%ld),%d)\n",\r
- hUSKey, dwIndex, pszName, pcchValueNameLen,\r
- *pcchValueNameLen, enumRegFlags);\r
-\r
- if (((enumRegFlags == SHREGENUM_HKCU) ||\r
- (enumRegFlags == SHREGENUM_DEFAULT)) &&\r
- (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKCU))) {\r
- return RegEnumKeyExW(dokey, dwIndex, pszName, pcchValueNameLen,\r
- 0, 0, 0, 0);\r
- }\r
-\r
- if (((enumRegFlags == SHREGENUM_HKLM) ||\r
- (enumRegFlags == SHREGENUM_DEFAULT)) &&\r
- (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKLM))) {\r
- return RegEnumKeyExW(dokey, dwIndex, pszName, pcchValueNameLen,\r
- 0, 0, 0, 0);\r
- }\r
- FIXME("no support for SHREGENUM_BOTH\n");\r
- return ERROR_INVALID_FUNCTION;\r
-}\r
-\r
-\r
-/*************************************************************************\r
- * SHRegWriteUSValueA [SHLWAPI.@]\r
- *\r
- * Write a user-specific registry value.\r
- *\r
- * PARAMS\r
- * hUSKey [I] Key to write the value to\r
- * pszValue [I] Name of value under hUSKey to write the value as\r
- * dwType [I] Type of the value\r
- * pvData [I] Data to set as the value\r
- * cbData [I] length of pvData\r
- * dwFlags [I] SHREGSET_ flags from "shlwapi.h"\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS.\r
- * Failure: ERROR_INVALID_PARAMETER, if any parameter is invalid, otherwise\r
- * an error code from RegSetValueExA().\r
- *\r
- * NOTES\r
- * dwFlags must have at least SHREGSET_FORCE_HKCU or SHREGSET_FORCE_HKLM set.\r
- */\r
-LONG WINAPI SHRegWriteUSValueA(HUSKEY hUSKey, LPCSTR pszValue, DWORD dwType,\r
- LPVOID pvData, DWORD cbData, DWORD dwFlags)\r
-{\r
- WCHAR szValue[MAX_PATH];\r
-\r
- if (pszValue)\r
- MultiByteToWideChar(CP_ACP, 0, pszValue, -1, szValue, MAX_PATH);\r
-\r
- return SHRegWriteUSValueW(hUSKey, pszValue ? szValue : NULL, dwType,\r
- pvData, cbData, dwFlags);\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegWriteUSValueW [SHLWAPI.@]\r
- *\r
- * See SHRegWriteUSValueA.\r
- */\r
-LONG WINAPI SHRegWriteUSValueW(HUSKEY hUSKey, LPCWSTR pszValue, DWORD dwType,\r
- LPVOID pvData, DWORD cbData, DWORD dwFlags)\r
-{\r
- LONG dummy;\r
- LPSHUSKEY hKey = (LPSHUSKEY)hUSKey;\r
- LONG ret = ERROR_SUCCESS;\r
-\r
- TRACE("(%p,%s,%ld,%p,%ld,%ld)\n", hUSKey, debugstr_w(pszValue),\r
- dwType, pvData, cbData, dwFlags);\r
-\r
- if (!hUSKey || IsBadWritePtr(hUSKey, sizeof(SHUSKEY)) ||\r
- !(dwFlags & (SHREGSET_FORCE_HKCU|SHREGSET_FORCE_HKLM)))\r
- return ERROR_INVALID_PARAMETER;\r
-\r
- if (dwFlags & (SHREGSET_FORCE_HKCU|SHREGSET_HKCU))\r
- {\r
- if (!hKey->HKCUkey)\r
- {\r
- /* Create the key */\r
- ret = RegCreateKeyW(hKey->HKCUstart, hKey->lpszPath, &hKey->HKCUkey);\r
- TRACE("Creating HKCU key, ret = %ld\n", ret);\r
- if (ret && (dwFlags & (SHREGSET_FORCE_HKCU)))\r
- {\r
- hKey->HKCUkey = 0;\r
- return ret;\r
- }\r
- }\r
-\r
- if (!ret)\r
- {\r
- if ((dwFlags & SHREGSET_FORCE_HKCU) ||\r
- RegQueryValueExW(hKey->HKCUkey, pszValue, NULL, NULL, NULL, &dummy))\r
- {\r
- /* Doesn't exist or we are forcing: Write value */\r
- ret = RegSetValueExW(hKey->HKCUkey, pszValue, 0, dwType, pvData, cbData);\r
- TRACE("Writing HKCU value, ret = %ld\n", ret);\r
- }\r
- }\r
- }\r
-\r
- if (dwFlags & (SHREGSET_FORCE_HKLM|SHREGSET_HKLM))\r
- {\r
- if (!hKey->HKLMkey)\r
- {\r
- /* Create the key */\r
- ret = RegCreateKeyW(hKey->HKLMstart, hKey->lpszPath, &hKey->HKLMkey);\r
- TRACE("Creating HKLM key, ret = %ld\n", ret);\r
- if (ret && (dwFlags & (SHREGSET_FORCE_HKLM)))\r
- {\r
- hKey->HKLMkey = 0;\r
- return ret;\r
- }\r
- }\r
-\r
- if (!ret)\r
- {\r
- if ((dwFlags & SHREGSET_FORCE_HKLM) ||\r
- RegQueryValueExW(hKey->HKLMkey, pszValue, NULL, NULL, NULL, &dummy))\r
- {\r
- /* Doesn't exist or we are forcing: Write value */\r
- ret = RegSetValueExW(hKey->HKLMkey, pszValue, 0, dwType, pvData, cbData);\r
- TRACE("Writing HKLM value, ret = %ld\n", ret);\r
- }\r
- }\r
- }\r
-\r
- return ret;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegGetPathA [SHLWAPI.@]\r
- *\r
- * Get a path from the registry.\r
- *\r
- * PARAMS\r
- * hKey [I] Handle to registry key\r
- * lpszSubKey [I] Name of sub key containing path to get\r
- * lpszValue [I] Name of value containing path to get\r
- * lpszPath [O] Buffer for returned path\r
- * dwFlags [I] Reserved\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS. lpszPath contains the path.\r
- * Failure: An error code from RegOpenKeyExA() or SHQueryValueExA().\r
- */\r
-DWORD WINAPI SHRegGetPathA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue,\r
- LPSTR lpszPath, DWORD dwFlags)\r
-{\r
- DWORD dwSize = MAX_PATH;\r
-\r
- TRACE("(hkey=%p,%s,%s,%p,%ld)\n", hKey, debugstr_a(lpszSubKey),\r
- debugstr_a(lpszValue), lpszPath, dwFlags);\r
-\r
- return SHGetValueA(hKey, lpszSubKey, lpszValue, 0, lpszPath, &dwSize);\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegGetPathW [SHLWAPI.@]\r
- *\r
- * See SHRegGetPathA.\r
- */\r
-DWORD WINAPI SHRegGetPathW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue,\r
- LPWSTR lpszPath, DWORD dwFlags)\r
-{\r
- DWORD dwSize = MAX_PATH;\r
-\r
- TRACE("(hkey=%p,%s,%s,%p,%ld)\n", hKey, debugstr_w(lpszSubKey),\r
- debugstr_w(lpszValue), lpszPath, dwFlags);\r
-\r
- return SHGetValueW(hKey, lpszSubKey, lpszValue, 0, lpszPath, &dwSize);\r
-}\r
-\r
-\r
-/*************************************************************************\r
- * SHRegSetPathA [SHLWAPI.@]\r
- *\r
- * Write a path to the registry.\r
- *\r
- * PARAMS\r
- * hKey [I] Handle to registry key\r
- * lpszSubKey [I] Name of sub key containing path to set\r
- * lpszValue [I] Name of value containing path to set\r
- * lpszPath [O] Path to write\r
- * dwFlags [I] Reserved, must be 0.\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS.\r
- * Failure: An error code from SHSetValueA().\r
- */\r
-DWORD WINAPI SHRegSetPathA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue,\r
- LPCSTR lpszPath, DWORD dwFlags)\r
-{\r
- char szBuff[MAX_PATH];\r
-\r
- FIXME("(hkey=%p,%s,%s,%p,%ld) - semi-stub\n",hKey, debugstr_a(lpszSubKey),\r
- debugstr_a(lpszValue), lpszPath, dwFlags);\r
-\r
- lstrcpyA(szBuff, lpszPath);\r
-\r
- /* FIXME: PathUnExpandEnvStringsA(szBuff); */\r
-\r
- return SHSetValueA(hKey,lpszSubKey, lpszValue, REG_SZ, szBuff,\r
- lstrlenA(szBuff));\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegSetPathW [SHLWAPI.@]\r
- *\r
- * See SHRegSetPathA.\r
- */\r
-DWORD WINAPI SHRegSetPathW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue,\r
- LPCWSTR lpszPath, DWORD dwFlags)\r
-{\r
- WCHAR szBuff[MAX_PATH];\r
-\r
- FIXME("(hkey=%p,%s,%s,%p,%ld) - semi-stub\n",hKey, debugstr_w(lpszSubKey),\r
- debugstr_w(lpszValue), lpszPath, dwFlags);\r
-\r
- lstrcpyW(szBuff, lpszPath);\r
-\r
- /* FIXME: PathUnExpandEnvStringsW(szBuff); */\r
-\r
- return SHSetValueW(hKey,lpszSubKey, lpszValue, REG_SZ, szBuff,\r
- lstrlenW(szBuff));\r
-}\r
-\r
-/*************************************************************************\r
- * SHGetValueA [SHLWAPI.@]\r
- *\r
- * Get a value from the registry.\r
- *\r
- * PARAMS\r
- * hKey [I] Handle to registry key\r
- * lpszSubKey [I] Name of sub key containing value to get\r
- * lpszValue [I] Name of value to get\r
- * pwType [O] Pointer to the values type\r
- * pvData [O] Pointer to the values data\r
- * pcbData [O] Pointer to the values size\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS. Output parameters contain the details read.\r
- * Failure: An error code from RegOpenKeyExA() or SHQueryValueExA().\r
- */\r
-DWORD WINAPI SHGetValueA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue,\r
- LPDWORD pwType, LPVOID pvData, LPDWORD pcbData)\r
-{\r
- DWORD dwRet = 0;\r
- HKEY hSubKey = 0;\r
-\r
- TRACE("(hkey=%p,%s,%s,%p,%p,%p)\n", hKey, debugstr_a(lpszSubKey),\r
- debugstr_a(lpszValue), pwType, pvData, pcbData);\r
-\r
- /* lpszSubKey can be 0. In this case the value is taken from the\r
- * current key.\r
- */\r
- if(lpszSubKey)\r
- dwRet = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_QUERY_VALUE, &hSubKey);\r
-\r
- if (! dwRet)\r
- {\r
- /* SHQueryValueEx expands Environment strings */\r
- dwRet = SHQueryValueExA(hSubKey ? hSubKey : hKey, lpszValue, 0, pwType, pvData, pcbData);\r
- if (hSubKey) RegCloseKey(hSubKey);\r
- }\r
- return dwRet;\r
-}\r
-\r
-/*************************************************************************\r
- * SHGetValueW [SHLWAPI.@]\r
- *\r
- * See SHGetValueA.\r
- */\r
-DWORD WINAPI SHGetValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue,\r
- LPDWORD pwType, LPVOID pvData, LPDWORD pcbData)\r
-{\r
- DWORD dwRet = 0;\r
- HKEY hSubKey = 0;\r
-\r
- TRACE("(hkey=%p,%s,%s,%p,%p,%p)\n", hKey, debugstr_w(lpszSubKey),\r
- debugstr_w(lpszValue), pwType, pvData, pcbData);\r
-\r
- if(lpszSubKey)\r
- dwRet = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_QUERY_VALUE, &hSubKey);\r
-\r
- if (! dwRet)\r
- {\r
- dwRet = SHQueryValueExW(hSubKey ? hSubKey : hKey, lpszValue, 0, pwType, pvData, pcbData);\r
- if (hSubKey) RegCloseKey(hSubKey);\r
- }\r
- return dwRet;\r
-}\r
-\r
-/*************************************************************************\r
- * SHSetValueA [SHLWAPI.@]\r
- *\r
- * Set a value in the registry.\r
- *\r
- * PARAMS\r
- * hKey [I] Handle to registry key\r
- * lpszSubKey [I] Name of sub key under hKey\r
- * lpszValue [I] Name of value to set\r
- * dwType [I] Type of the value\r
- * pvData [I] Data of the value\r
- * cbData [I] Size of the value\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS. The value is set with the data given.\r
- * Failure: An error code from RegCreateKeyExA() or RegSetValueExA()\r
- *\r
- * NOTES\r
- * If lpszSubKey does not exist, it is created before the value is set. If\r
- * lpszSubKey is NULL or an empty string, then the value is added directly\r
- * to hKey instead.\r
- */\r
-DWORD WINAPI SHSetValueA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue,\r
- DWORD dwType, LPCVOID pvData, DWORD cbData)\r
-{\r
- DWORD dwRet = ERROR_SUCCESS, dwDummy;\r
- HKEY hSubKey;\r
- static const char szEmpty[] = { '\0' };\r
-\r
- TRACE("(hkey=%p,%s,%s,%ld,%p,%ld)\n", hKey, debugstr_a(lpszSubKey),\r
- debugstr_a(lpszValue), dwType, pvData, cbData);\r
-\r
- if (lpszSubKey && *lpszSubKey)\r
- dwRet = RegCreateKeyExA(hKey, lpszSubKey, 0, szEmpty,\r
- 0, KEY_SET_VALUE, NULL, &hSubKey, &dwDummy);\r
- else\r
- hSubKey = hKey;\r
- if (!dwRet)\r
- {\r
- dwRet = RegSetValueExA(hSubKey, lpszValue, 0, dwType, pvData, cbData);\r
- if (hSubKey != hKey)\r
- RegCloseKey(hSubKey);\r
- }\r
- return dwRet;\r
-}\r
-\r
-/*************************************************************************\r
- * SHSetValueW [SHLWAPI.@]\r
- *\r
- * See SHSetValueA.\r
- */\r
-DWORD WINAPI SHSetValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue,\r
- DWORD dwType, LPCVOID pvData, DWORD cbData)\r
-{\r
- DWORD dwRet = ERROR_SUCCESS, dwDummy;\r
- HKEY hSubKey;\r
- static const WCHAR szEmpty[] = { '\0' };\r
-\r
- TRACE("(hkey=%p,%s,%s,%ld,%p,%ld)\n", hKey, debugstr_w(lpszSubKey),\r
- debugstr_w(lpszValue), dwType, pvData, cbData);\r
-\r
- if (lpszSubKey && *lpszSubKey)\r
- dwRet = RegCreateKeyExW(hKey, lpszSubKey, 0, szEmpty,\r
- 0, KEY_SET_VALUE, NULL, &hSubKey, &dwDummy);\r
- else\r
- hSubKey = hKey;\r
- if (!dwRet)\r
- {\r
- dwRet = RegSetValueExW(hSubKey, lpszValue, 0, dwType, pvData, cbData);\r
- if (hSubKey != hKey)\r
- RegCloseKey(hSubKey);\r
- }\r
- return dwRet;\r
-}\r
-\r
-/*************************************************************************\r
- * SHQueryInfoKeyA [SHLWAPI.@]\r
- *\r
- * Get information about a registry key. See RegQueryInfoKeyA().\r
- *\r
- * RETURNS\r
- * The result of calling RegQueryInfoKeyA().\r
- */\r
-LONG WINAPI SHQueryInfoKeyA(HKEY hKey, LPDWORD pwSubKeys, LPDWORD pwSubKeyMax,\r
- LPDWORD pwValues, LPDWORD pwValueMax)\r
-{\r
- TRACE("(hkey=%p,%p,%p,%p,%p)\n", hKey, pwSubKeys, pwSubKeyMax,\r
- pwValues, pwValueMax);\r
- return RegQueryInfoKeyA(hKey, NULL, NULL, NULL, pwSubKeys, pwSubKeyMax,\r
- NULL, pwValues, pwValueMax, NULL, NULL, NULL);\r
-}\r
-\r
-/*************************************************************************\r
- * SHQueryInfoKeyW [SHLWAPI.@]\r
- *\r
- * See SHQueryInfoKeyA.\r
- */\r
-LONG WINAPI SHQueryInfoKeyW(HKEY hKey, LPDWORD pwSubKeys, LPDWORD pwSubKeyMax,\r
- LPDWORD pwValues, LPDWORD pwValueMax)\r
-{\r
- TRACE("(hkey=%p,%p,%p,%p,%p)\n", hKey, pwSubKeys, pwSubKeyMax,\r
- pwValues, pwValueMax);\r
- return RegQueryInfoKeyW(hKey, NULL, NULL, NULL, pwSubKeys, pwSubKeyMax,\r
- NULL, pwValues, pwValueMax, NULL, NULL, NULL);\r
-}\r
-\r
-/*************************************************************************\r
- * SHQueryValueExA [SHLWAPI.@]\r
- *\r
- * Get a value from the registry, expanding environment variable strings.\r
- *\r
- * PARAMS\r
- * hKey [I] Handle to registry key\r
- * lpszValue [I] Name of value to query\r
- * lpReserved [O] Reserved for future use; must be NULL\r
- * pwType [O] Optional pointer updated with the values type\r
- * pvData [O] Optional pointer updated with the values data\r
- * pcbData [O] Optional pointer updated with the values size\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS. Any non NULL output parameters are updated with\r
- * information about the value.\r
- * Failure: ERROR_OUTOFMEMORY if memory allocation fails, or the type of the\r
- * data is REG_EXPAND_SZ and pcbData is NULL. Otherwise an error\r
- * code from RegQueryValueExA() or ExpandEnvironmentStringsA().\r
- *\r
- * NOTES\r
- * Either pwType, pvData or pcbData may be NULL if the caller doesn't want\r
- * the type, data or size information for the value.\r
- *\r
- * If the type of the data is REG_EXPAND_SZ, it is expanded to REG_SZ. The\r
- * value returned will be truncated if it is of type REG_SZ and bigger than\r
- * the buffer given to store it.\r
- *\r
- * REG_EXPAND_SZ:\r
- * case-1: the unexpanded string is smaller than the expanded one\r
- * subcase-1: the buffer is to small to hold the unexpanded string:\r
- * function fails and returns the size of the unexpanded string.\r
- *\r
- * subcase-2: buffer is to small to hold the expanded string:\r
- * the function return success (!!) and the result is truncated\r
- * *** This is clearly a error in the native implementation. ***\r
- *\r
- * case-2: the unexpanded string is bigger than the expanded one\r
- * The buffer must have enough space to hold the unexpanded\r
- * string even if the result is smaller.\r
- *\r
- */\r
-DWORD WINAPI SHQueryValueExA( HKEY hKey, LPCSTR lpszValue,\r
- LPDWORD lpReserved, LPDWORD pwType,\r
- LPVOID pvData, LPDWORD pcbData)\r
-{\r
- DWORD dwRet, dwType, dwUnExpDataLen = 0, dwExpDataLen;\r
-\r
- TRACE("(hkey=%p,%s,%p,%p,%p,%p=%ld)\n", hKey, debugstr_a(lpszValue),\r
- lpReserved, pwType, pvData, pcbData, pcbData ? *pcbData : 0);\r
-\r
- if (pcbData) dwUnExpDataLen = *pcbData;\r
-\r
- dwRet = RegQueryValueExA(hKey, lpszValue, lpReserved, &dwType, pvData, &dwUnExpDataLen);\r
-\r
- if (pcbData && (dwType == REG_EXPAND_SZ))\r
- {\r
- DWORD nBytesToAlloc;\r
-\r
- /* Expand type REG_EXPAND_SZ into REG_SZ */\r
- LPSTR szData;\r
-\r
- /* If the caller didn't supply a buffer or the buffer is to small we have\r
- * to allocate our own\r
- */\r
- if ((!pvData) || (dwRet == ERROR_MORE_DATA) )\r
- {\r
- char cNull = '\0';\r
- nBytesToAlloc = (!pvData || (dwRet == ERROR_MORE_DATA)) ? dwUnExpDataLen : *pcbData;\r
-\r
- szData = (LPSTR) LocalAlloc(GMEM_ZEROINIT, nBytesToAlloc);\r
- RegQueryValueExA (hKey, lpszValue, lpReserved, NULL, (LPBYTE)szData, &nBytesToAlloc);\r
- dwExpDataLen = ExpandEnvironmentStringsA(szData, &cNull, 1);\r
- dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);\r
- LocalFree((HLOCAL) szData);\r
- }\r
- else\r
- {\r
- nBytesToAlloc = (lstrlenA(pvData)+1) * sizeof (CHAR);\r
- szData = (LPSTR) LocalAlloc(GMEM_ZEROINIT, nBytesToAlloc );\r
- lstrcpyA(szData, pvData);\r
- dwExpDataLen = ExpandEnvironmentStringsA(szData, pvData, *pcbData / sizeof(CHAR));\r
- if (dwExpDataLen > *pcbData) dwRet = ERROR_MORE_DATA;\r
- dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);\r
- LocalFree((HLOCAL) szData);\r
- }\r
- }\r
-\r
- /* Update the type and data size if the caller wanted them */\r
- if ( dwType == REG_EXPAND_SZ ) dwType = REG_SZ;\r
- if ( pwType ) *pwType = dwType;\r
- if ( pcbData ) *pcbData = dwUnExpDataLen;\r
- return dwRet;\r
-}\r
-\r
-\r
-/*************************************************************************\r
- * SHQueryValueExW [SHLWAPI.@]\r
- *\r
- * See SHQueryValueExA.\r
- */\r
-DWORD WINAPI SHQueryValueExW(HKEY hKey, LPCWSTR lpszValue,\r
- LPDWORD lpReserved, LPDWORD pwType,\r
- LPVOID pvData, LPDWORD pcbData)\r
-{\r
- DWORD dwRet, dwType, dwUnExpDataLen = 0, dwExpDataLen;\r
-\r
- TRACE("(hkey=%p,%s,%p,%p,%p,%p=%ld)\n", hKey, debugstr_w(lpszValue),\r
- lpReserved, pwType, pvData, pcbData, pcbData ? *pcbData : 0);\r
-\r
- if (pcbData) dwUnExpDataLen = *pcbData;\r
-\r
- dwRet = RegQueryValueExW(hKey, lpszValue, lpReserved, &dwType, pvData, &dwUnExpDataLen);\r
- if (dwRet!=ERROR_SUCCESS && dwRet!=ERROR_MORE_DATA)\r
- return dwRet;\r
-\r
- if (pcbData && (dwType == REG_EXPAND_SZ))\r
- {\r
- DWORD nBytesToAlloc;\r
-\r
- /* Expand type REG_EXPAND_SZ into REG_SZ */\r
- LPWSTR szData;\r
-\r
- /* If the caller didn't supply a buffer or the buffer is too small we have\r
- * to allocate our own\r
- */\r
- if ((!pvData) || (dwRet == ERROR_MORE_DATA) )\r
- {\r
- WCHAR cNull = '\0';\r
- nBytesToAlloc = (!pvData || (dwRet == ERROR_MORE_DATA)) ? dwUnExpDataLen : *pcbData;\r
-\r
- szData = (LPWSTR) LocalAlloc(GMEM_ZEROINIT, nBytesToAlloc);\r
- RegQueryValueExW (hKey, lpszValue, lpReserved, NULL, (LPBYTE)szData, &nBytesToAlloc);\r
- dwExpDataLen = ExpandEnvironmentStringsW(szData, &cNull, 1);\r
- dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);\r
- LocalFree((HLOCAL) szData);\r
- }\r
- else\r
- {\r
- nBytesToAlloc = (lstrlenW(pvData) + 1) * sizeof(WCHAR);\r
- szData = (LPWSTR) LocalAlloc(GMEM_ZEROINIT, nBytesToAlloc );\r
- lstrcpyW(szData, pvData);\r
- dwExpDataLen = ExpandEnvironmentStringsW(szData, pvData, *pcbData/sizeof(WCHAR) );\r
- if (dwExpDataLen > *pcbData) dwRet = ERROR_MORE_DATA;\r
- dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);\r
- LocalFree((HLOCAL) szData);\r
- }\r
- }\r
-\r
- /* Update the type and data size if the caller wanted them */\r
- if ( dwType == REG_EXPAND_SZ ) dwType = REG_SZ;\r
- if ( pwType ) *pwType = dwType;\r
- if ( pcbData ) *pcbData = dwUnExpDataLen;\r
- return dwRet;\r
-}\r
-\r
-/*************************************************************************\r
- * SHDeleteKeyA [SHLWAPI.@]\r
- *\r
- * Delete a registry key and any sub keys/values present\r
- *\r
- * PARAMS\r
- * hKey [I] Handle to registry key\r
- * lpszSubKey [I] Name of sub key to delete\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS. The key is deleted.\r
- * Failure: An error code from RegOpenKeyExA(), RegQueryInfoKeyA(),\r
- * RegEnumKeyExA() or RegDeleteKeyA().\r
- */\r
-DWORD WINAPI SHDeleteKeyA(HKEY hKey, LPCSTR lpszSubKey)\r
-{\r
- DWORD dwRet, dwMaxSubkeyLen = 0, dwSize;\r
- CHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;\r
- HKEY hSubKey = 0;\r
-\r
- TRACE("(hkey=%p,%s)\n", hKey, debugstr_a(lpszSubKey));\r
-\r
- dwRet = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);\r
- if(!dwRet)\r
- {\r
- /* Find the maximum subkey length so that we can allocate a buffer */\r
- dwRet = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, NULL,\r
- &dwMaxSubkeyLen, NULL, NULL, NULL, NULL, NULL, NULL);\r
- if(!dwRet)\r
- {\r
- dwMaxSubkeyLen++;\r
- if (dwMaxSubkeyLen > sizeof(szNameBuf))\r
- /* Name too big: alloc a buffer for it */\r
- lpszName = HeapAlloc(GetProcessHeap(), 0, dwMaxSubkeyLen*sizeof(CHAR));\r
-\r
- if(!lpszName)\r
- dwRet = ERROR_NOT_ENOUGH_MEMORY;\r
- else\r
- {\r
- while (dwRet == ERROR_SUCCESS)\r
- {\r
- dwSize = dwMaxSubkeyLen;\r
- dwRet = RegEnumKeyExA(hSubKey, 0, lpszName, &dwSize, NULL, NULL, NULL, NULL);\r
- if (dwRet == ERROR_SUCCESS || dwRet == ERROR_MORE_DATA)\r
- dwRet = SHDeleteKeyA(hSubKey, lpszName);\r
- }\r
- if (dwRet == ERROR_NO_MORE_ITEMS)\r
- dwRet = ERROR_SUCCESS;\r
- if (lpszName != szNameBuf)\r
- HeapFree(GetProcessHeap(), 0, lpszName); /* Free buffer if allocated */\r
- }\r
- }\r
-\r
- RegCloseKey(hSubKey);\r
- if(!dwRet)\r
- dwRet = RegDeleteKeyA(hKey, lpszSubKey);\r
- }\r
- return dwRet;\r
-}\r
-\r
-/*************************************************************************\r
- * SHDeleteKeyW [SHLWAPI.@]\r
- *\r
- * See SHDeleteKeyA.\r
- */\r
-DWORD WINAPI SHDeleteKeyW(HKEY hKey, LPCWSTR lpszSubKey)\r
-{\r
- DWORD dwRet, dwKeyCount = 0, dwMaxSubkeyLen = 0, dwSize, i;\r
- WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;\r
- HKEY hSubKey = 0;\r
-\r
- TRACE("(hkey=%p,%s)\n", hKey, debugstr_w(lpszSubKey));\r
-\r
- dwRet = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);\r
- if(!dwRet)\r
- {\r
- /* Find how many subkeys there are */\r
- dwRet = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, &dwKeyCount,\r
- &dwMaxSubkeyLen, NULL, NULL, NULL, NULL, NULL, NULL);\r
- if(!dwRet)\r
- {\r
- dwMaxSubkeyLen++;\r
- if (dwMaxSubkeyLen > sizeof(szNameBuf)/sizeof(WCHAR))\r
- /* Name too big: alloc a buffer for it */\r
- lpszName = HeapAlloc(GetProcessHeap(), 0, dwMaxSubkeyLen*sizeof(WCHAR));\r
-\r
- if(!lpszName)\r
- dwRet = ERROR_NOT_ENOUGH_MEMORY;\r
- else\r
- {\r
- /* Recursively delete all the subkeys */\r
- for(i = 0; i < dwKeyCount && !dwRet; i++)\r
- {\r
- dwSize = dwMaxSubkeyLen;\r
- dwRet = RegEnumKeyExW(hSubKey, i, lpszName, &dwSize, NULL, NULL, NULL, NULL);\r
- if(!dwRet)\r
- dwRet = SHDeleteKeyW(hSubKey, lpszName);\r
- }\r
-\r
- if (lpszName != szNameBuf)\r
- HeapFree(GetProcessHeap(), 0, lpszName); /* Free buffer if allocated */\r
- }\r
- }\r
-\r
- RegCloseKey(hSubKey);\r
- if(!dwRet)\r
- dwRet = RegDeleteKeyW(hKey, lpszSubKey);\r
- }\r
- return dwRet;\r
-}\r
-\r
-/*************************************************************************\r
- * SHDeleteEmptyKeyA [SHLWAPI.@]\r
- *\r
- * Delete a registry key with no sub keys.\r
- *\r
- * PARAMS\r
- * hKey [I] Handle to registry key\r
- * lpszSubKey [I] Name of sub key to delete\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS. The key is deleted.\r
- * Failure: If the key is not empty, returns ERROR_KEY_HAS_CHILDREN. Otherwise\r
- * returns an error code from RegOpenKeyExA(), RegQueryInfoKeyA() or\r
- * RegDeleteKeyA().\r
- */\r
-DWORD WINAPI SHDeleteEmptyKeyA(HKEY hKey, LPCSTR lpszSubKey)\r
-{\r
- DWORD dwRet, dwKeyCount = 0;\r
- HKEY hSubKey = 0;\r
-\r
- TRACE("(hkey=%p,%s)\n", hKey, debugstr_a(lpszSubKey));\r
-\r
- dwRet = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);\r
- if(!dwRet)\r
- {\r
- dwRet = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, &dwKeyCount,\r
- NULL, NULL, NULL, NULL, NULL, NULL, NULL);\r
- RegCloseKey(hSubKey);\r
- if(!dwRet)\r
- {\r
- if (!dwKeyCount)\r
- dwRet = RegDeleteKeyA(hKey, lpszSubKey);\r
- else\r
- dwRet = ERROR_KEY_HAS_CHILDREN;\r
- }\r
- }\r
- return dwRet;\r
-}\r
-\r
-/*************************************************************************\r
- * SHDeleteEmptyKeyW [SHLWAPI.@]\r
- *\r
- * See SHDeleteEmptyKeyA.\r
- */\r
-DWORD WINAPI SHDeleteEmptyKeyW(HKEY hKey, LPCWSTR lpszSubKey)\r
-{\r
- DWORD dwRet, dwKeyCount = 0;\r
- HKEY hSubKey = 0;\r
-\r
- TRACE("(hkey=%p, %s)\n", hKey, debugstr_w(lpszSubKey));\r
-\r
- dwRet = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);\r
- if(!dwRet)\r
- {\r
- dwRet = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, &dwKeyCount,\r
- NULL, NULL, NULL, NULL, NULL, NULL, NULL);\r
- RegCloseKey(hSubKey);\r
- if(!dwRet)\r
- {\r
- if (!dwKeyCount)\r
- dwRet = RegDeleteKeyW(hKey, lpszSubKey);\r
- else\r
- dwRet = ERROR_KEY_HAS_CHILDREN;\r
- }\r
- }\r
- return dwRet;\r
-}\r
-\r
-/*************************************************************************\r
- * SHDeleteOrphanKeyA [SHLWAPI.@]\r
- *\r
- * Delete a registry key with no sub keys or values.\r
- *\r
- * PARAMS\r
- * hKey [I] Handle to registry key\r
- * lpszSubKey [I] Name of sub key to possibly delete\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS. The key has been deleted if it was an orphan.\r
- * Failure: An error from RegOpenKeyExA(), RegQueryValueExA(), or RegDeleteKeyA().\r
- */\r
-DWORD WINAPI SHDeleteOrphanKeyA(HKEY hKey, LPCSTR lpszSubKey)\r
-{\r
- HKEY hSubKey;\r
- DWORD dwKeyCount = 0, dwValueCount = 0, dwRet;\r
-\r
- TRACE("(hkey=%p,%s)\n", hKey, debugstr_a(lpszSubKey));\r
-\r
- dwRet = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);\r
-\r
- if(!dwRet)\r
- {\r
- /* Get subkey and value count */\r
- dwRet = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, &dwKeyCount,\r
- NULL, NULL, &dwValueCount, NULL, NULL, NULL, NULL);\r
-\r
- if(!dwRet && !dwKeyCount && !dwValueCount)\r
- {\r
- dwRet = RegDeleteKeyA(hKey, lpszSubKey);\r
- }\r
- RegCloseKey(hSubKey);\r
- }\r
- return dwRet;\r
-}\r
-\r
-/*************************************************************************\r
- * SHDeleteOrphanKeyW [SHLWAPI.@]\r
- *\r
- * See SHDeleteOrphanKeyA.\r
- */\r
-DWORD WINAPI SHDeleteOrphanKeyW(HKEY hKey, LPCWSTR lpszSubKey)\r
-{\r
- HKEY hSubKey;\r
- DWORD dwKeyCount = 0, dwValueCount = 0, dwRet;\r
-\r
- TRACE("(hkey=%p,%s)\n", hKey, debugstr_w(lpszSubKey));\r
-\r
- dwRet = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);\r
-\r
- if(!dwRet)\r
- {\r
- /* Get subkey and value count */\r
- dwRet = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, &dwKeyCount,\r
- NULL, NULL, &dwValueCount, NULL, NULL, NULL, NULL);\r
-\r
- if(!dwRet && !dwKeyCount && !dwValueCount)\r
- {\r
- dwRet = RegDeleteKeyW(hKey, lpszSubKey);\r
- }\r
- RegCloseKey(hSubKey);\r
- }\r
- return dwRet;\r
-}\r
-\r
-/*************************************************************************\r
- * SHDeleteValueA [SHLWAPI.@]\r
- *\r
- * Delete a value from the registry.\r
- *\r
- * PARAMS\r
- * hKey [I] Handle to registry key\r
- * lpszSubKey [I] Name of sub key containing value to delete\r
- * lpszValue [I] Name of value to delete\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS. The value is deleted.\r
- * Failure: An error code from RegOpenKeyExA() or RegDeleteValueA().\r
- */\r
-DWORD WINAPI SHDeleteValueA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue)\r
-{\r
- DWORD dwRet;\r
- HKEY hSubKey;\r
-\r
- TRACE("(hkey=%p,%s,%s)\n", hKey, debugstr_a(lpszSubKey), debugstr_a(lpszValue));\r
-\r
- dwRet = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_SET_VALUE, &hSubKey);\r
- if (!dwRet)\r
- {\r
- dwRet = RegDeleteValueA(hSubKey, lpszValue);\r
- RegCloseKey(hSubKey);\r
- }\r
- return dwRet;\r
-}\r
-\r
-/*************************************************************************\r
- * SHDeleteValueW [SHLWAPI.@]\r
- *\r
- * See SHDeleteValueA.\r
- */\r
-DWORD WINAPI SHDeleteValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue)\r
-{\r
- DWORD dwRet;\r
- HKEY hSubKey;\r
-\r
- TRACE("(hkey=%p,%s,%s)\n", hKey, debugstr_w(lpszSubKey), debugstr_w(lpszValue));\r
-\r
- dwRet = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_SET_VALUE, &hSubKey);\r
- if (!dwRet)\r
- {\r
- dwRet = RegDeleteValueW(hSubKey, lpszValue);\r
- RegCloseKey(hSubKey);\r
- }\r
- return dwRet;\r
-}\r
-\r
-/*************************************************************************\r
- * SHEnumKeyExA [SHLWAPI.@]\r
- *\r
- * Enumerate sub keys in a registry key.\r
- *\r
- * PARAMS\r
- * hKey [I] Handle to registry key\r
- * dwIndex [I] Index of key to enumerate\r
- * lpszSubKey [O] Pointer updated with the subkey name\r
- * pwLen [O] Pointer updated with the subkey length\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS. lpszSubKey and pwLen are updated.\r
- * Failure: An error code from RegEnumKeyExA().\r
- */\r
-LONG WINAPI SHEnumKeyExA(HKEY hKey, DWORD dwIndex, LPSTR lpszSubKey,\r
- LPDWORD pwLen)\r
-{\r
- TRACE("(hkey=%p,%ld,%s,%p)\n", hKey, dwIndex, debugstr_a(lpszSubKey), pwLen);\r
-\r
- return RegEnumKeyExA(hKey, dwIndex, lpszSubKey, pwLen, NULL, NULL, NULL, NULL);\r
-}\r
-\r
-/*************************************************************************\r
- * SHEnumKeyExW [SHLWAPI.@]\r
- *\r
- * See SHEnumKeyExA.\r
- */\r
-LONG WINAPI SHEnumKeyExW(HKEY hKey, DWORD dwIndex, LPWSTR lpszSubKey,\r
- LPDWORD pwLen)\r
-{\r
- TRACE("(hkey=%p,%ld,%s,%p)\n", hKey, dwIndex, debugstr_w(lpszSubKey), pwLen);\r
-\r
- return RegEnumKeyExW(hKey, dwIndex, lpszSubKey, pwLen, NULL, NULL, NULL, NULL);\r
-}\r
-\r
-/*************************************************************************\r
- * SHEnumValueA [SHLWAPI.@]\r
- *\r
- * Enumerate values in a registry key.\r
- *\r
- * PARAMS\r
- * hKey [I] Handle to registry key\r
- * dwIndex [I] Index of key to enumerate\r
- * lpszValue [O] Pointer updated with the values name\r
- * pwLen [O] Pointer updated with the values length\r
- * pwType [O] Pointer updated with the values type\r
- * pvData [O] Pointer updated with the values data\r
- * pcbData [O] Pointer updated with the values size\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS. Output parameters are updated.\r
- * Failure: An error code from RegEnumValueA().\r
- */\r
-LONG WINAPI SHEnumValueA(HKEY hKey, DWORD dwIndex, LPSTR lpszValue,\r
- LPDWORD pwLen, LPDWORD pwType,\r
- LPVOID pvData, LPDWORD pcbData)\r
-{\r
- TRACE("(hkey=%p,%ld,%s,%p,%p,%p,%p)\n", hKey, dwIndex,\r
- debugstr_a(lpszValue), pwLen, pwType, pvData, pcbData);\r
-\r
- return RegEnumValueA(hKey, dwIndex, lpszValue, pwLen, NULL,\r
- pwType, pvData, pcbData);\r
-}\r
-\r
-/*************************************************************************\r
- * SHEnumValueW [SHLWAPI.@]\r
- *\r
- * See SHEnumValueA.\r
- */\r
-LONG WINAPI SHEnumValueW(HKEY hKey, DWORD dwIndex, LPWSTR lpszValue,\r
- LPDWORD pwLen, LPDWORD pwType,\r
- LPVOID pvData, LPDWORD pcbData)\r
-{\r
- TRACE("(hkey=%p,%ld,%s,%p,%p,%p,%p)\n", hKey, dwIndex,\r
- debugstr_w(lpszValue), pwLen, pwType, pvData, pcbData);\r
-\r
- return RegEnumValueW(hKey, dwIndex, lpszValue, pwLen, NULL,\r
- pwType, pvData, pcbData);\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.205]\r
- *\r
- * Get a value from the registry.\r
- *\r
- * PARAMS\r
- * hKey [I] Handle to registry key\r
- * pSubKey [I] Name of sub key containing value to get\r
- * pValue [I] Name of value to get\r
- * pwType [O] Destination for the values type\r
- * pvData [O] Destination for the values data\r
- * pbData [O] Destination for the values size\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS. Output parameters contain the details read.\r
- * Failure: An error code from RegOpenKeyExA() or SHQueryValueExA(),\r
- * or ERROR_INVALID_FUNCTION in the machine is in safe mode.\r
- */\r
-DWORD WINAPI SHGetValueGoodBootA(HKEY hkey, LPCSTR pSubKey, LPCSTR pValue,\r
- LPDWORD pwType, LPVOID pvData, LPDWORD pbData)\r
-{\r
- if (GetSystemMetrics(SM_CLEANBOOT))\r
- return ERROR_INVALID_FUNCTION;\r
- return SHGetValueA(hkey, pSubKey, pValue, pwType, pvData, pbData);\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.206]\r
- *\r
- * Unicode version of SHGetValueGoodBootW.\r
- */\r
-DWORD WINAPI SHGetValueGoodBootW(HKEY hkey, LPCWSTR pSubKey, LPCWSTR pValue,\r
- LPDWORD pwType, LPVOID pvData, LPDWORD pbData)\r
-{\r
- if (GetSystemMetrics(SM_CLEANBOOT))\r
- return ERROR_INVALID_FUNCTION;\r
- return SHGetValueW(hkey, pSubKey, pValue, pwType, pvData, pbData);\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.320]\r
- *\r
- * Set a MIME content type in the registry.\r
- *\r
- * PARAMS\r
- * lpszSubKey [I] Name of key under HKEY_CLASSES_ROOT.\r
- * lpszValue [I] Value to set\r
- *\r
- * RETURNS\r
- * Success: TRUE\r
- * Failure: FALSE\r
- */\r
-BOOL WINAPI RegisterMIMETypeForExtensionA(LPCSTR lpszSubKey, LPCSTR lpszValue)\r
-{\r
- DWORD dwRet;\r
-\r
- if (!lpszValue)\r
- {\r
- WARN("Invalid lpszValue would crash under Win32!\n");\r
- return FALSE;\r
- }\r
-\r
- dwRet = SHSetValueA(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeA,\r
- REG_SZ, lpszValue, strlen(lpszValue));\r
- return dwRet ? FALSE : TRUE;\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.321]\r
- *\r
- * Unicode version of RegisterMIMETypeForExtensionA.\r
- */\r
-BOOL WINAPI RegisterMIMETypeForExtensionW(LPCWSTR lpszSubKey, LPCWSTR lpszValue)\r
-{\r
- DWORD dwRet;\r
-\r
- if (!lpszValue)\r
- {\r
- WARN("Invalid lpszValue would crash under Win32!\n");\r
- return FALSE;\r
- }\r
-\r
- dwRet = SHSetValueW(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeW,\r
- REG_SZ, lpszValue, strlenW(lpszValue));\r
- return dwRet ? FALSE : TRUE;\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.322]\r
- *\r
- * Delete a MIME content type from the registry.\r
- *\r
- * PARAMS\r
- * lpszSubKey [I] Name of sub key\r
- *\r
- * RETURNS\r
- * Success: TRUE\r
- * Failure: FALSE\r
- */\r
-BOOL WINAPI UnregisterMIMETypeForExtensionA(LPCSTR lpszSubKey)\r
-{\r
- HRESULT ret = SHDeleteValueA(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeA);\r
- return ret ? FALSE : TRUE;\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.323]\r
- *\r
- * Unicode version of UnregisterMIMETypeForExtensionA.\r
- */\r
-BOOL WINAPI UnregisterMIMETypeForExtensionW(LPCWSTR lpszSubKey)\r
-{\r
- HRESULT ret = SHDeleteValueW(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeW);\r
- return ret ? FALSE : TRUE;\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.328]\r
- *\r
- * Get the registry path to a MIME content key.\r
- *\r
- * PARAMS\r
- * lpszType [I] Content type to get the path for\r
- * lpszBuffer [O] Destination for path\r
- * dwLen [I] Length of lpszBuffer\r
- *\r
- * RETURNS\r
- * Success: TRUE. lpszBuffer contains the full path.\r
- * Failure: FALSE.\r
- *\r
- * NOTES\r
- * The base path for the key is "MIME\Database\Content Type\"\r
- */\r
-BOOL WINAPI GetMIMETypeSubKeyA(LPCSTR lpszType, LPSTR lpszBuffer, DWORD dwLen)\r
-{\r
- TRACE("(%s,%p,%ld)\n", debugstr_a(lpszType), lpszBuffer, dwLen);\r
-\r
- if (dwLen > dwLenMimeDbContent && lpszType && lpszBuffer)\r
- {\r
- size_t dwStrLen = strlen(lpszType);\r
-\r
- if (dwStrLen < dwLen - dwLenMimeDbContent)\r
- {\r
- memcpy(lpszBuffer, szMimeDbContentA, dwLenMimeDbContent);\r
- memcpy(lpszBuffer + dwLenMimeDbContent, lpszType, dwStrLen + 1);\r
- return TRUE;\r
- }\r
- }\r
- return FALSE;\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.329]\r
- *\r
- * Unicode version of GetMIMETypeSubKeyA.\r
- */\r
-BOOL WINAPI GetMIMETypeSubKeyW(LPCWSTR lpszType, LPWSTR lpszBuffer, DWORD dwLen)\r
-{\r
- TRACE("(%s,%p,%ld)\n", debugstr_w(lpszType), lpszBuffer, dwLen);\r
-\r
- if (dwLen > dwLenMimeDbContent && lpszType && lpszBuffer)\r
- {\r
- DWORD dwStrLen = strlenW(lpszType);\r
-\r
- if (dwStrLen < dwLen - dwLenMimeDbContent)\r
- {\r
- memcpy(lpszBuffer, szMimeDbContentW, dwLenMimeDbContent * sizeof(WCHAR));\r
- memcpy(lpszBuffer + dwLenMimeDbContent, lpszType, (dwStrLen + 1) * sizeof(WCHAR));\r
- return TRUE;\r
- }\r
- }\r
- return FALSE;\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.330]\r
- *\r
- * Get the file extension for a given Mime type.\r
- *\r
- * PARAMS\r
- * lpszType [I] Mime type to get the file extension for\r
- * lpExt [O] Destination for the resulting extension\r
- * iLen [I] Length of lpExt in characters\r
- *\r
- * RETURNS\r
- * Success: TRUE. lpExt contains the file extension.\r
- * Failure: FALSE, if any parameter is invalid or the extension cannot be\r
- * retrieved. If iLen > 0, lpExt is set to an empty string.\r
- *\r
- * NOTES\r
- * - The extension returned in lpExt always has a leading '.' character, even\r
- * if the registry Mime database entry does not.\r
- * - iLen must be long enough for the file extension for this function to succeed.\r
- */\r
-BOOL WINAPI MIME_GetExtensionA(LPCSTR lpszType, LPSTR lpExt, INT iLen)\r
-{\r
- char szSubKey[MAX_PATH];\r
- DWORD dwlen = iLen - 1, dwType;\r
- BOOL bRet = FALSE;\r
-\r
- if (iLen > 0 && lpExt)\r
- *lpExt = '\0';\r
-\r
- if (lpszType && lpExt && iLen > 2 &&\r
- GetMIMETypeSubKeyA(lpszType, szSubKey, MAX_PATH) &&\r
- !SHGetValueA(HKEY_CLASSES_ROOT, szSubKey, szExtensionA, &dwType, lpExt + 1, &dwlen) &&\r
- lpExt[1])\r
- {\r
- if (lpExt[1] == '.')\r
- memmove(lpExt, lpExt + 1, strlen(lpExt + 1) + 1);\r
- else\r
- *lpExt = '.'; /* Supply a '.' */\r
- bRet = TRUE;\r
- }\r
- return bRet;\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.331]\r
- *\r
- * Unicode version of MIME_GetExtensionA.\r
- */\r
-BOOL WINAPI MIME_GetExtensionW(LPCWSTR lpszType, LPWSTR lpExt, INT iLen)\r
-{\r
- WCHAR szSubKey[MAX_PATH];\r
- DWORD dwlen = iLen - 1, dwType;\r
- BOOL bRet = FALSE;\r
-\r
- if (iLen > 0 && lpExt)\r
- *lpExt = '\0';\r
-\r
- if (lpszType && lpExt && iLen > 2 &&\r
- GetMIMETypeSubKeyW(lpszType, szSubKey, MAX_PATH) &&\r
- !SHGetValueW(HKEY_CLASSES_ROOT, szSubKey, szExtensionW, &dwType, lpExt + 1, &dwlen) &&\r
- lpExt[1])\r
- {\r
- if (lpExt[1] == '.')\r
- memmove(lpExt, lpExt + 1, (strlenW(lpExt + 1) + 1) * sizeof(WCHAR));\r
- else\r
- *lpExt = '.'; /* Supply a '.' */\r
- bRet = TRUE;\r
- }\r
- return bRet;\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.324]\r
- *\r
- * Set the file extension for a MIME content key.\r
- *\r
- * PARAMS\r
- * lpszExt [I] File extension to set\r
- * lpszType [I] Content type to set the extension for\r
- *\r
- * RETURNS\r
- * Success: TRUE. The file extension is set in the registry.\r
- * Failure: FALSE.\r
- */\r
-BOOL WINAPI RegisterExtensionForMIMETypeA(LPCSTR lpszExt, LPCSTR lpszType)\r
-{\r
- DWORD dwLen;\r
- char szKey[MAX_PATH];\r
-\r
- TRACE("(%s,%s)\n", debugstr_a(lpszExt), debugstr_a(lpszType));\r
-\r
- if (!GetMIMETypeSubKeyA(lpszType, szKey, MAX_PATH)) /* Get full path to the key */\r
- return FALSE;\r
-\r
- dwLen = strlen(lpszExt) + 1;\r
-\r
- if (SHSetValueA(HKEY_CLASSES_ROOT, szKey, szExtensionA, REG_SZ, lpszExt, dwLen))\r
- return FALSE;\r
- return TRUE;\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.325]\r
- *\r
- * Unicode version of RegisterExtensionForMIMETypeA.\r
- */\r
-BOOL WINAPI RegisterExtensionForMIMETypeW(LPCWSTR lpszExt, LPCWSTR lpszType)\r
-{\r
- DWORD dwLen;\r
- WCHAR szKey[MAX_PATH];\r
-\r
- TRACE("(%s,%s)\n", debugstr_w(lpszExt), debugstr_w(lpszType));\r
-\r
- /* Get the full path to the key */\r
- if (!GetMIMETypeSubKeyW(lpszType, szKey, MAX_PATH)) /* Get full path to the key */\r
- return FALSE;\r
-\r
- dwLen = (lstrlenW(lpszExt) + 1) * sizeof(WCHAR);\r
-\r
- if (SHSetValueW(HKEY_CLASSES_ROOT, szKey, szExtensionW, REG_SZ, lpszExt, dwLen))\r
- return FALSE;\r
- return TRUE;\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.326]\r
- *\r
- * Delete a file extension from a MIME content type.\r
- *\r
- * PARAMS\r
- * lpszType [I] Content type to delete the extension for\r
- *\r
- * RETURNS\r
- * Success: TRUE. The file extension is deleted from the registry.\r
- * Failure: FALSE. The extension may have been removed but the key remains.\r
- *\r
- * NOTES\r
- * If deleting the extension leaves an orphan key, the key is removed also.\r
- */\r
-BOOL WINAPI UnregisterExtensionForMIMETypeA(LPCSTR lpszType)\r
-{\r
- char szKey[MAX_PATH];\r
-\r
- TRACE("(%s)\n", debugstr_a(lpszType));\r
-\r
- if (!GetMIMETypeSubKeyA(lpszType, szKey, MAX_PATH)) /* Get full path to the key */\r
- return FALSE;\r
-\r
- if (!SHDeleteValueA(HKEY_CLASSES_ROOT, szKey, szExtensionA))\r
- return FALSE;\r
-\r
- if (!SHDeleteOrphanKeyA(HKEY_CLASSES_ROOT, szKey))\r
- return FALSE;\r
- return TRUE;\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.327]\r
- *\r
- * Unicode version of UnregisterExtensionForMIMETypeA.\r
- */\r
-BOOL WINAPI UnregisterExtensionForMIMETypeW(LPCWSTR lpszType)\r
-{\r
- WCHAR szKey[MAX_PATH];\r
-\r
- TRACE("(%s)\n", debugstr_w(lpszType));\r
-\r
- if (!GetMIMETypeSubKeyW(lpszType, szKey, MAX_PATH)) /* Get full path to the key */\r
- return FALSE;\r
-\r
- if (!SHDeleteValueW(HKEY_CLASSES_ROOT, szKey, szExtensionW))\r
- return FALSE;\r
-\r
- if (!SHDeleteOrphanKeyW(HKEY_CLASSES_ROOT, szKey))\r
- return FALSE;\r
- return TRUE;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegDuplicateHKey [SHLWAPI.@]\r
- *\r
- * Create a duplicate of a registry handle.\r
- *\r
- * PARAMS\r
- * hKey [I] key to duplicate.\r
- *\r
- * RETURNS\r
- * A new handle pointing to the same key as hKey.\r
- */\r
-HKEY WINAPI SHRegDuplicateHKey(HKEY hKey)\r
-{\r
- HKEY newKey = 0;\r
-\r
- RegOpenKeyExA(hKey, 0, 0, MAXIMUM_ALLOWED, &newKey);\r
- TRACE("new key is %p\n", newKey);\r
- return newKey;\r
-}\r
-\r
-\r
-/*************************************************************************\r
- * SHCopyKeyA [SHLWAPI.@]\r
- *\r
- * Copy a key and its values/sub keys to another location.\r
- *\r
- * PARAMS\r
- * hKeySrc [I] Source key to copy from\r
- * lpszSubKey [I] Sub key under hKeyDst, or NULL to use hKeyDst directly\r
- * hKeyDst [I] Destination key\r
- * dwReserved [I] Reserved, must be 0\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS. The key is copied to the destination key.\r
- * Failure: A standard windows error code.\r
- *\r
- * NOTES\r
- * If hKeyDst is a key under hKeySrc, this function will misbehave\r
- * (It will loop until out of stack, or the registry is full). This\r
- * bug is present in Win32 also.\r
- */\r
-DWORD WINAPI SHCopyKeyA(HKEY hKeySrc, LPCSTR lpszSubKey, HKEY hKeyDst, DWORD dwReserved)\r
-{\r
- WCHAR szSubKeyW[MAX_PATH];\r
-\r
- TRACE("(hkey=%p,%s,%p08x,%ld)\n", hKeySrc, debugstr_a(lpszSubKey), hKeyDst, dwReserved);\r
-\r
- if (lpszSubKey)\r
- MultiByteToWideChar(0, 0, lpszSubKey, -1, szSubKeyW, MAX_PATH);\r
-\r
- return SHCopyKeyW(hKeySrc, lpszSubKey ? szSubKeyW : NULL, hKeyDst, dwReserved);\r
-}\r
-\r
-/*************************************************************************\r
- * SHCopyKeyW [SHLWAPI.@]\r
- *\r
- * See SHCopyKeyA.\r
- */\r
-DWORD WINAPI SHCopyKeyW(HKEY hKeySrc, LPCWSTR lpszSubKey, HKEY hKeyDst, DWORD dwReserved)\r
-{\r
- DWORD dwKeyCount = 0, dwValueCount = 0, dwMaxKeyLen = 0;\r
- DWORD dwMaxValueLen = 0, dwMaxDataLen = 0, i;\r
- BYTE buff[1024];\r
- LPVOID lpBuff = (LPVOID)buff;\r
- WCHAR szName[MAX_PATH], *lpszName = szName;\r
- DWORD dwRet = S_OK;\r
-\r
- TRACE("hkey=%p,%s,%p08x,%ld)\n", hKeySrc, debugstr_w(lpszSubKey), hKeyDst, dwReserved);\r
-\r
- if(!hKeyDst || !hKeySrc)\r
- dwRet = ERROR_INVALID_PARAMETER;\r
- else\r
- {\r
- /* Open destination key */\r
- if(lpszSubKey)\r
- dwRet = RegOpenKeyExW(hKeyDst, lpszSubKey, 0, KEY_ALL_ACCESS, &hKeyDst);\r
-\r
- if(dwRet)\r
- hKeyDst = 0; /* Don't close this key since we didn't open it */\r
- else\r
- {\r
- /* Get details about sub keys and values */\r
- dwRet = RegQueryInfoKeyW(hKeySrc, NULL, NULL, NULL, &dwKeyCount, &dwMaxKeyLen,\r
- NULL, &dwValueCount, &dwMaxValueLen, &dwMaxDataLen,\r
- NULL, NULL);\r
- if(!dwRet)\r
- {\r
- if (dwMaxValueLen > dwMaxKeyLen)\r
- dwMaxKeyLen = dwMaxValueLen; /* Get max size for key/value names */\r
-\r
- if (dwMaxKeyLen++ > MAX_PATH - 1)\r
- lpszName = HeapAlloc(GetProcessHeap(), 0, dwMaxKeyLen * sizeof(WCHAR));\r
-\r
- if (dwMaxDataLen > sizeof(buff))\r
- lpBuff = HeapAlloc(GetProcessHeap(), 0, dwMaxDataLen);\r
-\r
- if (!lpszName || !lpBuff)\r
- dwRet = ERROR_NOT_ENOUGH_MEMORY;\r
- }\r
- }\r
- }\r
-\r
- /* Copy all the sub keys */\r
- for(i = 0; i < dwKeyCount && !dwRet; i++)\r
- {\r
- HKEY hSubKeySrc, hSubKeyDst;\r
- DWORD dwSize = dwMaxKeyLen;\r
-\r
- dwRet = RegEnumKeyExW(hKeySrc, i, lpszName, &dwSize, NULL, NULL, NULL, NULL);\r
-\r
- if(!dwRet)\r
- {\r
- /* Open source sub key */\r
- dwRet = RegOpenKeyExW(hKeySrc, lpszName, 0, KEY_READ, &hSubKeySrc);\r
-\r
- if(!dwRet)\r
- {\r
- /* Create destination sub key */\r
- dwRet = RegCreateKeyW(hKeyDst, lpszName, &hSubKeyDst);\r
-\r
- if(!dwRet)\r
- {\r
- /* Recursively copy keys and values from the sub key */\r
- dwRet = SHCopyKeyW(hSubKeySrc, NULL, hSubKeyDst, 0);\r
- RegCloseKey(hSubKeyDst);\r
- }\r
- }\r
- RegCloseKey(hSubKeySrc);\r
- }\r
- }\r
-\r
- /* Copy all the values in this key */\r
- for (i = 0; i < dwValueCount && !dwRet; i++)\r
- {\r
- DWORD dwNameSize = dwMaxKeyLen, dwType, dwLen = dwMaxDataLen;\r
-\r
- dwRet = RegEnumValueW(hKeySrc, i, lpszName, &dwNameSize, NULL, &dwType, buff, &dwLen);\r
-\r
- if (!dwRet)\r
- dwRet = SHSetValueW(hKeyDst, NULL, lpszName, dwType, lpBuff, dwLen);\r
- }\r
-\r
- /* Free buffers if allocated */\r
- if (lpszName != szName)\r
- HeapFree(GetProcessHeap(), 0, lpszName);\r
- if (lpBuff != buff)\r
- HeapFree(GetProcessHeap(), 0, lpBuff);\r
-\r
- if (lpszSubKey && hKeyDst)\r
- RegCloseKey(hKeyDst);\r
- return dwRet;\r
-}\r
-\r
-/*\r
- * The following functions are ORDINAL ONLY:\r
- */\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.280]\r
- *\r
- * Read an integer value from the registry, falling back to a default.\r
- *\r
- * PARAMS\r
- * hKey [I] Registry key to read from\r
- * lpszValue [I] Value name to read\r
- * iDefault [I] Default value to return\r
- *\r
- * RETURNS\r
- * The value contained in the given registry value if present, otherwise\r
- * iDefault.\r
- */\r
-int WINAPI SHRegGetIntW(HKEY hKey, LPCWSTR lpszValue, int iDefault)\r
-{\r
- TRACE("(%p,%s,%d)\n", hKey, debugstr_w(lpszValue), iDefault);\r
-\r
- if (hKey)\r
- {\r
- WCHAR szBuff[32];\r
- DWORD dwSize = sizeof(szBuff);\r
- szBuff[0] = '\0';\r
- SHQueryValueExW(hKey, lpszValue, 0, 0, szBuff, &dwSize);\r
-\r
- if(*szBuff >= '0' && *szBuff <= '9')\r
- return StrToIntW(szBuff);\r
- }\r
- return iDefault;\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.343]\r
- *\r
- * Create or open an explorer ClassId Key.\r
- *\r
- * PARAMS\r
- * guid [I] Explorer ClassId key to open\r
- * lpszValue [I] Value name under the ClassId Key\r
- * bUseHKCU [I] TRUE=Use HKEY_CURRENT_USER, FALSE=Use HKEY_CLASSES_ROOT\r
- * bCreate [I] TRUE=Create the key if it doesn't exist, FALSE=Don't\r
- * phKey [O] Destination for the resulting key handle\r
- *\r
- * RETURNS\r
- * Success: S_OK. phKey contains the resulting registry handle.\r
- * Failure: An HRESULT error code indicating the problem.\r
- */\r
-HRESULT WINAPI SHRegGetCLSIDKeyA(REFGUID guid, LPCSTR lpszValue, BOOL bUseHKCU, BOOL bCreate, PHKEY phKey)\r
-{\r
- WCHAR szValue[MAX_PATH];\r
-\r
- if (lpszValue)\r
- MultiByteToWideChar(CP_ACP, 0, lpszValue, -1, szValue, sizeof(szValue)/sizeof(WCHAR));\r
-\r
- return SHRegGetCLSIDKeyW(guid, lpszValue ? szValue : NULL, bUseHKCU, bCreate, phKey);\r
-}\r
-\r
-/*************************************************************************\r
- * @ [SHLWAPI.344]\r
- *\r
- * Unicode version of SHRegGetCLSIDKeyA.\r
- */\r
-HRESULT WINAPI SHRegGetCLSIDKeyW(REFGUID guid, LPCWSTR lpszValue, BOOL bUseHKCU,\r
- BOOL bCreate, PHKEY phKey)\r
-{\r
- static const WCHAR szClassIdKey[] = { 'S','o','f','t','w','a','r','e','\\',\r
- 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',\r
- 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',\r
- 'E','x','p','l','o','r','e','r','\\','C','L','S','I','D','\\' };\r
-#define szClassIdKeyLen (sizeof(szClassIdKey)/sizeof(WCHAR))\r
- WCHAR szKey[MAX_PATH];\r
- DWORD dwRet;\r
- HKEY hkey;\r
-\r
- /* Create the key string */\r
- memcpy(szKey, szClassIdKey, sizeof(szClassIdKey));\r
- SHStringFromGUIDW(guid, szKey + szClassIdKeyLen, 39); /* Append guid */\r
-\r
- if(lpszValue)\r
- {\r
- szKey[szClassIdKeyLen + 39] = '\\';\r
- strcpyW(szKey + szClassIdKeyLen + 40, lpszValue); /* Append value name */\r
- }\r
-\r
- hkey = bUseHKCU ? HKEY_CURRENT_USER : HKEY_CLASSES_ROOT;\r
-\r
- if(bCreate)\r
- dwRet = RegCreateKeyW(hkey, szKey, phKey);\r
- else\r
- dwRet = RegOpenKeyExW(hkey, szKey, 0, KEY_READ, phKey);\r
-\r
- return dwRet ? HRESULT_FROM_WIN32(dwRet) : S_OK;\r
-}\r
-\r
-/*************************************************************************\r
- * SHRegisterValidateTemplate [SHLWAPI.@]\r
- *\r
- * observed from the ie 5.5 installer:\r
- * - allocates a buffer with the size of the given file\r
- * - read the file content into the buffer\r
- * - creates the key szTemplateKey\r
- * - sets "205523652929647911071668590831910975402"=dword:00002e37 at\r
- * the key\r
- *\r
- * PARAMS\r
- * filename [I] An existing file its content is read into an allocated\r
- * buffer\r
- * unknown [I]\r
- *\r
- * RETURNS\r
- * Success: ERROR_SUCCESS.\r
- */\r
-HRESULT WINAPI SHRegisterValidateTemplate(LPCWSTR filename, BOOL unknown)\r
-{\r
-/* static const WCHAR szTemplateKey[] = { 'S','o','f','t','w','a','r','e','\\',\r
- * 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',\r
- * 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',\r
- * 'E','x','p','l','o','r','e','r','\\',\r
- * 'T','e','m','p','l','a','t','e','R','e','g','i','s','t','r','y',0 };\r
- */\r
- FIXME("stub: %s, %08x\n", debugstr_w(filename), unknown);\r
-\r
- return S_OK;\r
-}\r
+/*
+ * SHLWAPI registry functions
+ *
+ * Copyright 1998 Juergen Schmied
+ * Copyright 2001 Guy Albertelli
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdarg.h>
+#include <string.h>
+#include "windef.h"
+#include "winbase.h"
+#include "winuser.h"
+#include "winreg.h"
+#include "wine/debug.h"
+#define NO_SHLWAPI_STREAM
+#include "shlwapi.h"
+#include "wine/unicode.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(shell);
+
+/* Key/Value names for MIME content types */
+static const char *lpszContentTypeA = "Content Type";
+static const WCHAR lpszContentTypeW[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0'};
+
+static const char *szMimeDbContentA = "MIME\\Database\\Content Type\\";
+static const WCHAR szMimeDbContentW[] = { 'M', 'I', 'M','E','\\',
+ 'D','a','t','a','b','a','s','e','\\','C','o','n','t','e','n','t',
+ ' ','T','y','p','e','\\', 0 };
+static const DWORD dwLenMimeDbContent = 27; /* strlen of szMimeDbContentA/W */
+
+static const char *szExtensionA = "Extension";
+static const WCHAR szExtensionW[] = { 'E', 'x', 't','e','n','s','i','o','n','\0' };
+
+/* internal structure of what the HUSKEY points to */
+typedef struct {
+ HKEY HKCUstart; /* Start key in CU hive */
+ HKEY HKCUkey; /* Opened key in CU hive */
+ HKEY HKLMstart; /* Start key in LM hive */
+ HKEY HKLMkey; /* Opened key in LM hive */
+ WCHAR lpszPath[MAX_PATH];
+} SHUSKEY, *LPSHUSKEY;
+
+DWORD WINAPI SHStringFromGUIDW(REFGUID,LPWSTR,INT);
+HRESULT WINAPI SHRegGetCLSIDKeyW(REFGUID,LPCWSTR,BOOL,BOOL,PHKEY);
+
+
+#define REG_HKCU TRUE
+#define REG_HKLM FALSE
+/*************************************************************************
+ * REG_GetHKEYFromHUSKEY
+ *
+ * Function: Return the proper registry key from the HUSKEY structure
+ * also allow special predefined values.
+ */
+static HKEY WINAPI REG_GetHKEYFromHUSKEY(HUSKEY hUSKey, BOOL which)
+{
+ HKEY test = (HKEY) hUSKey;
+ LPSHUSKEY mihk = (LPSHUSKEY) hUSKey;
+
+ if ((test == HKEY_CLASSES_ROOT) ||
+ (test == HKEY_CURRENT_CONFIG) ||
+ (test == HKEY_CURRENT_USER) ||
+ (test == HKEY_DYN_DATA) ||
+ (test == HKEY_LOCAL_MACHINE) ||
+ (test == HKEY_PERFORMANCE_DATA) ||
+/* FIXME: need to define for Win2k, ME, XP
+ * (test == HKEY_PERFORMANCE_TEXT) ||
+ * (test == HKEY_PERFORMANCE_NLSTEXT) ||
+ */
+ (test == HKEY_USERS)) return test;
+ if (which == REG_HKCU) return mihk->HKCUkey;
+ return mihk->HKLMkey;
+}
+
+
+/*************************************************************************
+ * SHRegOpenUSKeyA [SHLWAPI.@]
+ *
+ * Open a user-specific registry key.
+ *
+ * PARAMS
+ * Path [I] Key name to open
+ * AccessType [I] Access type
+ * hRelativeUSKey [I] Relative user key
+ * phNewUSKey [O] Destination for created key
+ * fIgnoreHKCU [I] TRUE=Don't check HKEY_CURRENT_USER
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS
+ * Failure: An error code from RegOpenKeyExA().
+ */
+LONG WINAPI SHRegOpenUSKeyA(LPCSTR Path, REGSAM AccessType, HUSKEY hRelativeUSKey,
+ PHUSKEY phNewUSKey, BOOL fIgnoreHKCU)
+{
+ WCHAR szPath[MAX_PATH];
+
+ if (Path)
+ MultiByteToWideChar(CP_ACP, 0, Path, -1, szPath, MAX_PATH);
+
+ return SHRegOpenUSKeyW(Path ? szPath : NULL, AccessType, hRelativeUSKey,
+ phNewUSKey, fIgnoreHKCU);
+}
+
+/*************************************************************************
+ * SHRegOpenUSKeyW [SHLWAPI.@]
+ *
+ * See SHRegOpenUSKeyA.
+ */
+LONG WINAPI SHRegOpenUSKeyW(LPCWSTR Path, REGSAM AccessType, HUSKEY hRelativeUSKey,
+ PHUSKEY phNewUSKey, BOOL fIgnoreHKCU)
+{
+ LONG ret2, ret1 = ~ERROR_SUCCESS;
+ LPSHUSKEY hKey;
+
+ TRACE("(%s,0x%lx,%p,%p,%d)\n", debugstr_w(Path),(LONG)AccessType,
+ hRelativeUSKey, phNewUSKey, fIgnoreHKCU);
+
+ if (phNewUSKey)
+ *phNewUSKey = NULL;
+
+ /* Create internal HUSKEY */
+ hKey = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*hKey));
+ lstrcpynW(hKey->lpszPath, Path, sizeof(hKey->lpszPath));
+
+ if (hRelativeUSKey)
+ {
+ hKey->HKCUstart = SHRegDuplicateHKey(REG_GetHKEYFromHUSKEY(hRelativeUSKey, REG_HKCU));
+ hKey->HKLMstart = SHRegDuplicateHKey(REG_GetHKEYFromHUSKEY(hRelativeUSKey, REG_HKLM));
+
+ /* FIXME: if either of these keys is NULL, create the start key from
+ * the relative keys start+path
+ */
+ }
+ else
+ {
+ hKey->HKCUstart = HKEY_CURRENT_USER;
+ hKey->HKLMstart = HKEY_LOCAL_MACHINE;
+ }
+
+ if (!fIgnoreHKCU)
+ {
+ ret1 = RegOpenKeyExW(hKey->HKCUstart, hKey->lpszPath, 0, AccessType, &hKey->HKCUkey);
+ if (ret1)
+ hKey->HKCUkey = 0;
+ }
+
+ ret2 = RegOpenKeyExW(hKey->HKLMstart, hKey->lpszPath, 0, AccessType, &hKey->HKLMkey);
+ if (ret2)
+ hKey->HKLMkey = 0;
+
+ if (ret1 || ret2)
+ TRACE("one or more opens failed: HKCU=%ld HKLM=%ld\n", ret1, ret2);
+
+ if (ret1 && ret2)
+ {
+ /* Neither open succeeded: fail */
+ SHRegCloseUSKey(hKey);
+ return ret2;
+ }
+
+ TRACE("HUSKEY=%p\n", hKey);
+ if (phNewUSKey)
+ *phNewUSKey = (HUSKEY)hKey;
+ return ERROR_SUCCESS;
+}
+
+/*************************************************************************
+ * SHRegCloseUSKey [SHLWAPI.@]
+ *
+ * Close a user-specific registry key
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS
+ * Failure: An error code from RegCloseKey().
+ */
+LONG WINAPI SHRegCloseUSKey(
+ HUSKEY hUSKey) /* [I] Key to close */
+{
+ LPSHUSKEY hKey = (LPSHUSKEY)hUSKey;
+ LONG ret = ERROR_SUCCESS;
+
+ if (hKey->HKCUkey)
+ ret = RegCloseKey(hKey->HKCUkey);
+ if (hKey->HKCUstart && hKey->HKCUstart != HKEY_CURRENT_USER)
+ ret = RegCloseKey(hKey->HKCUstart);
+ if (hKey->HKLMkey)
+ ret = RegCloseKey(hKey->HKLMkey);
+ if (hKey->HKLMstart && hKey->HKLMstart != HKEY_LOCAL_MACHINE)
+ ret = RegCloseKey(hKey->HKCUstart);
+
+ HeapFree(GetProcessHeap(), 0, hKey);
+ return ret;
+}
+
+/*************************************************************************
+ * SHRegCreateUSKeyA [SHLWAPI.@]
+ *
+ * Create or open a user-specific registry key.
+ *
+ * PARAMS
+ * pszPath [I] Key name to create or open.
+ * samDesired [I] Wanted security access.
+ * hRelativeUSKey [I] Base path if pszPath is relative. NULL otherwise.
+ * phNewUSKey [O] Receives a handle to the new or openened key.
+ * dwFlags [I] Base key under which the key should be opened.
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS
+ * Failure: Nonzero error code from winerror.h
+ */
+LONG WINAPI SHRegCreateUSKeyA(LPCSTR pszPath, REGSAM samDesired, HUSKEY hRelativeUSKey,
+ PHUSKEY phNewUSKey, DWORD dwFlags)
+{
+ FIXME("(%s, 0x%08lx, %p, %p, 0x%08lx) stub\n", debugstr_a(pszPath), samDesired,
+ hRelativeUSKey, phNewUSKey, dwFlags);
+ return ERROR_SUCCESS;
+}
+
+/*************************************************************************
+ * SHRegCreateUSKeyW [SHLWAPI.@]
+ *
+ * See SHRegCreateUSKeyA.
+ */
+LONG WINAPI SHRegCreateUSKeyW(LPCWSTR pszPath, REGSAM samDesired, HUSKEY hRelativeUSKey,
+ PHUSKEY phNewUSKey, DWORD dwFlags)
+{
+ FIXME("(%s, 0x%08lx, %p, %p, 0x%08lx) stub\n", debugstr_w(pszPath), samDesired,
+ hRelativeUSKey, phNewUSKey, dwFlags);
+ return ERROR_SUCCESS;
+}
+
+/*************************************************************************
+ * SHRegDeleteEmptyUSKeyA [SHLWAPI.@]
+ *
+ * Delete an empty user-specific registry key.
+ *
+ * PARAMS
+ * hUSKey [I] Handle to an open registry key.
+ * pszValue [I] Empty key name.
+ * delRegFlags [I] Flag that specifies the base from which to delete
+ * the key.
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS
+ * Failure: Nonzero error code from winerror.h
+ */
+LONG WINAPI SHRegDeleteEmptyUSKeyA(HUSKEY hUSKey, LPCSTR pszValue, SHREGDEL_FLAGS delRegFlags)
+{
+ FIXME("(%p, %s, 0x%08x) stub\n", hUSKey, debugstr_a(pszValue), delRegFlags);
+ return ERROR_SUCCESS;
+}
+
+/*************************************************************************
+ * SHRegDeleteEmptyUSKeyW [SHLWAPI.@]
+ *
+ * See SHRegDeleteEmptyUSKeyA.
+ */
+LONG WINAPI SHRegDeleteEmptyUSKeyW(HUSKEY hUSKey, LPCWSTR pszValue, SHREGDEL_FLAGS delRegFlags)
+{
+ FIXME("(%p, %s, 0x%08x) stub\n", hUSKey, debugstr_w(pszValue), delRegFlags);
+ return ERROR_SUCCESS;
+}
+
+/*************************************************************************
+ * SHRegDeleteUSValueA [SHLWAPI.@]
+ *
+ * Delete a user-specific registry value.
+ *
+ * PARAMS
+ * hUSKey [I] Handle to an open registry key.
+ * pszValue [I] Specifies the value to delete.
+ * delRegFlags [I] Flag that specifies the base of the key from which to
+ * delete the value.
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS
+ * Failure: Nonzero error code from winerror.h
+ */
+LONG WINAPI SHRegDeleteUSValueA(HUSKEY hUSKey, LPCSTR pszValue, SHREGDEL_FLAGS delRegFlags)
+{
+ FIXME("(%p, %s, 0x%08x) stub\n", hUSKey, debugstr_a(pszValue), delRegFlags);
+ return ERROR_SUCCESS;
+}
+
+/*************************************************************************
+ * SHRegDeleteUSValueW [SHLWAPI.@]
+ *
+ * See SHRegDeleteUSValueA.
+ */
+LONG WINAPI SHRegDeleteUSValueW(HUSKEY hUSKey, LPCWSTR pszValue, SHREGDEL_FLAGS delRegFlags)
+{
+ FIXME("(%p, %s, 0x%08x) stub\n", hUSKey, debugstr_w(pszValue), delRegFlags);
+ return ERROR_SUCCESS;
+}
+
+/*************************************************************************
+ * SHRegEnumUSValueA [SHLWAPI.@]
+ *
+ * Enumerate values of a specified registry key.
+ *
+ * PARAMS
+ * hUSKey [I] Handle to an open registry key.
+ * dwIndex [I] Index of the value to be retrieved.
+ * pszValueName [O] Buffer to receive the value name.
+ * pcchValueNameLen [I] Size of pszValueName in characters.
+ * pdwType [O] Receives data type of the value.
+ * pvData [O] Receives value data. May be NULL.
+ * pcbData [I/O] Size of pvData in bytes.
+ * enumRegFlags [I] Flag that specifies the base key under which to
+ * enumerate values.
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS
+ * Failure: Nonzero error code from winerror.h
+ */
+LONG WINAPI SHRegEnumUSValueA(HUSKEY hUSKey, DWORD dwIndex, LPSTR pszValueName,
+ LPDWORD pcchValueNameLen, LPDWORD pdwType, LPVOID pvData,
+ LPDWORD pcbData, SHREGENUM_FLAGS enumRegFlags)
+{
+ FIXME("(%p, 0x%08lx, %s, %p, %p, %p, %p, 0x%08x) stub\n", hUSKey, dwIndex,
+ debugstr_a(pszValueName), pcchValueNameLen, pdwType, pvData, pcbData, enumRegFlags);
+ return ERROR_INVALID_FUNCTION;
+}
+
+/*************************************************************************
+ * SHRegEnumUSValueW [SHLWAPI.@]
+ *
+ * See SHRegEnumUSValueA.
+ */
+LONG WINAPI SHRegEnumUSValueW(HUSKEY hUSKey, DWORD dwIndex, LPWSTR pszValueName,
+ LPDWORD pcchValueNameLen, LPDWORD pdwType, LPVOID pvData,
+ LPDWORD pcbData, SHREGENUM_FLAGS enumRegFlags)
+{
+ FIXME("(%p, 0x%08lx, %s, %p, %p, %p, %p, 0x%08x) stub\n", hUSKey, dwIndex,
+ debugstr_w(pszValueName), pcchValueNameLen, pdwType, pvData, pcbData, enumRegFlags);
+ return ERROR_INVALID_FUNCTION;
+}
+
+/*************************************************************************
+ * SHRegQueryUSValueA [SHLWAPI.@]
+ *
+ * Query a user-specific registry value.
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS
+ * Failure: An error code from RegQueryValueExA().
+ */
+LONG WINAPI SHRegQueryUSValueA(
+ HUSKEY hUSKey, /* [I] Key to query */
+ LPCSTR pszValue, /* [I] Value name under hUSKey */
+ LPDWORD pdwType, /* [O] Destination for value type */
+ LPVOID pvData, /* [O] Destination for value data */
+ LPDWORD pcbData, /* [O] Destination for value length */
+ BOOL fIgnoreHKCU, /* [I] TRUE=Don't check HKEY_CURRENT_USER */
+ LPVOID pvDefaultData, /* [I] Default data if pszValue does not exist */
+ DWORD dwDefaultDataSize) /* [I] Length of pvDefaultData */
+{
+ LONG ret = ~ERROR_SUCCESS;
+ LONG i, maxmove;
+ HKEY dokey;
+ CHAR *src, *dst;
+
+ /* if user wants HKCU, and it exists, then try it */
+ if (!fIgnoreHKCU && (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKCU))) {
+ ret = RegQueryValueExA(dokey,
+ pszValue, 0, pdwType, pvData, pcbData);
+ TRACE("HKCU RegQueryValue returned %08lx\n", ret);
+ }
+
+ /* if HKCU did not work and HKLM exists, then try it */
+ if ((ret != ERROR_SUCCESS) &&
+ (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKLM))) {
+ ret = RegQueryValueExA(dokey,
+ pszValue, 0, pdwType, pvData, pcbData);
+ TRACE("HKLM RegQueryValue returned %08lx\n", ret);
+ }
+
+ /* if neither worked, and default data exists, then use it */
+ if (ret != ERROR_SUCCESS) {
+ if (pvDefaultData && (dwDefaultDataSize != 0)) {
+ maxmove = (dwDefaultDataSize >= *pcbData) ? *pcbData : dwDefaultDataSize;
+ src = (CHAR*)pvDefaultData;
+ dst = (CHAR*)pvData;
+ for(i=0; i<maxmove; i++) *dst++ = *src++;
+ *pcbData = maxmove;
+ TRACE("setting default data\n");
+ ret = ERROR_SUCCESS;
+ }
+ }
+ return ret;
+}
+
+
+/*************************************************************************
+ * SHRegQueryUSValueW [SHLWAPI.@]
+ *
+ * See SHRegQueryUSValueA.
+ */
+LONG WINAPI SHRegQueryUSValueW(
+ HUSKEY hUSKey,
+ LPCWSTR pszValue,
+ LPDWORD pdwType,
+ LPVOID pvData,
+ LPDWORD pcbData,
+ BOOL fIgnoreHKCU,
+ LPVOID pvDefaultData,
+ DWORD dwDefaultDataSize)
+{
+ LONG ret = ~ERROR_SUCCESS;
+ LONG i, maxmove;
+ HKEY dokey;
+ CHAR *src, *dst;
+
+ /* if user wants HKCU, and it exists, then try it */
+ if (!fIgnoreHKCU && (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKCU))) {
+ ret = RegQueryValueExW(dokey,
+ pszValue, 0, pdwType, pvData, pcbData);
+ TRACE("HKCU RegQueryValue returned %08lx\n", ret);
+ }
+
+ /* if HKCU did not work and HKLM exists, then try it */
+ if ((ret != ERROR_SUCCESS) &&
+ (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKLM))) {
+ ret = RegQueryValueExW(dokey,
+ pszValue, 0, pdwType, pvData, pcbData);
+ TRACE("HKLM RegQueryValue returned %08lx\n", ret);
+ }
+
+ /* if neither worked, and default data exists, then use it */
+ if (ret != ERROR_SUCCESS) {
+ if (pvDefaultData && (dwDefaultDataSize != 0)) {
+ maxmove = (dwDefaultDataSize >= *pcbData) ? *pcbData : dwDefaultDataSize;
+ src = (CHAR*)pvDefaultData;
+ dst = (CHAR*)pvData;
+ for(i=0; i<maxmove; i++) *dst++ = *src++;
+ *pcbData = maxmove;
+ TRACE("setting default data\n");
+ ret = ERROR_SUCCESS;
+ }
+ }
+ return ret;
+}
+
+/*************************************************************************
+ * SHRegGetUSValueA [SHLWAPI.@]
+ *
+ * Get a user-specific registry value.
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS
+ * Failure: An error code from SHRegOpenUSKeyA() or SHRegQueryUSValueA().
+ *
+ * NOTES
+ * This function opens pSubKey, queries the value, and then closes the key.
+ */
+LONG WINAPI SHRegGetUSValueA(
+ LPCSTR pSubKey, /* [I] Key name to open */
+ LPCSTR pValue, /* [I] Value name to open */
+ LPDWORD pwType, /* [O] Destination for the type of the value */
+ LPVOID pvData, /* [O] Destination for the value */
+ LPDWORD pcbData, /* [I] Destination for the length of the value **/
+ BOOL flagIgnoreHKCU, /* [I] TRUE=Don't check HKEY_CURRENT_USER */
+ LPVOID pDefaultData, /* [I] Default value if it doesn't exist */
+ DWORD wDefaultDataSize) /* [I] Length of pDefaultData */
+{
+ HUSKEY myhuskey;
+ LONG ret;
+
+ if (!pvData || !pcbData) return ERROR_INVALID_FUNCTION; /* FIXME:wrong*/
+ TRACE("key '%s', value '%s', datalen %ld, %s\n",
+ debugstr_a(pSubKey), debugstr_a(pValue), *pcbData,
+ (flagIgnoreHKCU) ? "Ignoring HKCU" : "Tries HKCU then HKLM");
+
+ ret = SHRegOpenUSKeyA(pSubKey, 0x1, 0, &myhuskey, flagIgnoreHKCU);
+ if (ret == ERROR_SUCCESS) {
+ ret = SHRegQueryUSValueA(myhuskey, pValue, pwType, pvData,
+ pcbData, flagIgnoreHKCU, pDefaultData,
+ wDefaultDataSize);
+ SHRegCloseUSKey(myhuskey);
+ }
+ return ret;
+}
+
+/*************************************************************************
+ * SHRegGetUSValueW [SHLWAPI.@]
+ *
+ * See SHRegGetUSValueA.
+ */
+LONG WINAPI SHRegGetUSValueW(
+ LPCWSTR pSubKey,
+ LPCWSTR pValue,
+ LPDWORD pwType,
+ LPVOID pvData,
+ LPDWORD pcbData,
+ BOOL flagIgnoreHKCU,
+ LPVOID pDefaultData,
+ DWORD wDefaultDataSize)
+{
+ HUSKEY myhuskey;
+ LONG ret;
+
+ if (!pvData || !pcbData) return ERROR_INVALID_FUNCTION; /* FIXME:wrong*/
+ TRACE("key '%s', value '%s', datalen %ld, %s\n",
+ debugstr_w(pSubKey), debugstr_w(pValue), *pcbData,
+ (flagIgnoreHKCU) ? "Ignoring HKCU" : "Tries HKCU then HKLM");
+
+ ret = SHRegOpenUSKeyW(pSubKey, 0x1, 0, &myhuskey, flagIgnoreHKCU);
+ if (ret == ERROR_SUCCESS) {
+ ret = SHRegQueryUSValueW(myhuskey, pValue, pwType, pvData,
+ pcbData, flagIgnoreHKCU, pDefaultData,
+ wDefaultDataSize);
+ SHRegCloseUSKey(myhuskey);
+ }
+ return ret;
+}
+
+/*************************************************************************
+ * SHRegSetUSValueA [SHLWAPI.@]
+ *
+ * Set a user-specific registry value.
+ *
+ * PARAMS
+ * pszSubKey [I] Name of key to set the value in
+ * pszValue [I] Name of value under pszSubKey to set the value in
+ * dwType [I] Type of the value
+ * pvData [I] Data to set as the value
+ * cbData [I] length of pvData
+ * dwFlags [I] SHREGSET_ flags from "shlwapi.h"
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS
+ * Failure: An error code from SHRegOpenUSKeyA() or SHRegWriteUSValueA(), or
+ * ERROR_INVALID_FUNCTION if pvData is NULL.
+ *
+ * NOTES
+ * This function opens pszSubKey, sets the value, and then closes the key.
+ */
+LONG WINAPI SHRegSetUSValueA(LPCSTR pszSubKey, LPCSTR pszValue, DWORD dwType,
+ LPVOID pvData, DWORD cbData, DWORD dwFlags)
+{
+ BOOL ignoreHKCU = TRUE;
+ HUSKEY hkey;
+ LONG ret;
+
+ TRACE("(%s,%s,%ld,%p,%ld,0x%08lx\n", debugstr_a(pszSubKey), debugstr_a(pszValue),
+ dwType, pvData, cbData, dwFlags);
+
+ if (!pvData)
+ return ERROR_INVALID_FUNCTION;
+
+ if (dwFlags & SHREGSET_HKCU || dwFlags & SHREGSET_FORCE_HKCU)
+ ignoreHKCU = FALSE;
+
+ ret = SHRegOpenUSKeyA(pszSubKey, KEY_ALL_ACCESS, 0, &hkey, ignoreHKCU);
+ if (ret == ERROR_SUCCESS)
+ {
+ ret = SHRegWriteUSValueA(hkey, pszValue, dwType, pvData, cbData, dwFlags);
+ SHRegCloseUSKey(hkey);
+ }
+ return ret;
+}
+
+/*************************************************************************
+ * SHRegSetUSValueW [SHLWAPI.@]
+ *
+ * See SHRegSetUSValueA.
+ */
+LONG WINAPI SHRegSetUSValueW(LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwType,
+ LPVOID pvData, DWORD cbData, DWORD dwFlags)
+{
+ BOOL ignoreHKCU = TRUE;
+ HUSKEY hkey;
+ LONG ret;
+
+ TRACE("(%s,%s,%ld,%p,%ld,0x%08lx\n", debugstr_w(pszSubKey), debugstr_w(pszValue),
+ dwType, pvData, cbData, dwFlags);
+
+ if (!pvData)
+ return ERROR_INVALID_FUNCTION;
+
+ if (dwFlags & SHREGSET_HKCU || dwFlags & SHREGSET_FORCE_HKCU)
+ ignoreHKCU = FALSE;
+
+ ret = SHRegOpenUSKeyW(pszSubKey, KEY_ALL_ACCESS, 0, &hkey, ignoreHKCU);
+ if (ret == ERROR_SUCCESS)
+ {
+ ret = SHRegWriteUSValueW(hkey, pszValue, dwType, pvData, cbData, dwFlags);
+ SHRegCloseUSKey(hkey);
+ }
+ return ret;
+}
+
+/*************************************************************************
+ * SHRegGetBoolUSValueA [SHLWAPI.@]
+ *
+ * Get a user-specific registry boolean value.
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS
+ * Failure: An error code from SHRegOpenUSKeyA() or SHRegQueryUSValueA().
+ *
+ * NOTES
+ * This function opens pszSubKey, queries the value, and then closes the key.
+ *
+ * Boolean values are one of the following:
+ * True: YES,TRUE,non-zero
+ * False: NO,FALSE,0
+ */
+BOOL WINAPI SHRegGetBoolUSValueA(
+ LPCSTR pszSubKey, /* [I] Key name to open */
+ LPCSTR pszValue, /* [I] Value name to open */
+ BOOL fIgnoreHKCU, /* [I] TRUE=Don't check HKEY_CURRENT_USER */
+ BOOL fDefault) /* [I] Default value to use if pszValue is not present */
+{
+ LONG retvalue;
+ DWORD type, datalen, work;
+ BOOL ret = fDefault;
+ CHAR data[10];
+
+ TRACE("key '%s', value '%s', %s\n",
+ debugstr_a(pszSubKey), debugstr_a(pszValue),
+ (fIgnoreHKCU) ? "Ignoring HKCU" : "Tries HKCU then HKLM");
+
+ datalen = sizeof(data)-1;
+ if (!(retvalue = SHRegGetUSValueA( pszSubKey, pszValue, &type,
+ data, &datalen,
+ fIgnoreHKCU, 0, 0))) {
+ /* process returned data via type into bool */
+ switch (type) {
+ case REG_SZ:
+ data[9] = '\0'; /* set end of string */
+ if (lstrcmpiA(data, "YES") == 0) ret = TRUE;
+ if (lstrcmpiA(data, "TRUE") == 0) ret = TRUE;
+ if (lstrcmpiA(data, "NO") == 0) ret = FALSE;
+ if (lstrcmpiA(data, "FALSE") == 0) ret = FALSE;
+ break;
+ case REG_DWORD:
+ work = *(LPDWORD)data;
+ ret = (work != 0);
+ break;
+ case REG_BINARY:
+ if (datalen == 1) {
+ ret = (data[0] != '\0');
+ break;
+ }
+ default:
+ FIXME("Unsupported registry data type %ld\n", type);
+ ret = FALSE;
+ }
+ TRACE("got value (type=%ld), returing <%s>\n", type,
+ (ret) ? "TRUE" : "FALSE");
+ }
+ else {
+ ret = fDefault;
+ TRACE("returning default data <%s>\n",
+ (ret) ? "TRUE" : "FALSE");
+ }
+ return ret;
+}
+
+/*************************************************************************
+ * SHRegGetBoolUSValueW [SHLWAPI.@]
+ *
+ * See SHRegGetBoolUSValueA.
+ */
+BOOL WINAPI SHRegGetBoolUSValueW(
+ LPCWSTR pszSubKey,
+ LPCWSTR pszValue,
+ BOOL fIgnoreHKCU,
+ BOOL fDefault)
+{
+ static const WCHAR wYES[]= {'Y','E','S','\0'};
+ static const WCHAR wTRUE[]= {'T','R','U','E','\0'};
+ static const WCHAR wNO[]= {'N','O','\0'};
+ static const WCHAR wFALSE[]={'F','A','L','S','E','\0'};
+ LONG retvalue;
+ DWORD type, datalen, work;
+ BOOL ret = fDefault;
+ WCHAR data[10];
+
+ TRACE("key '%s', value '%s', %s\n",
+ debugstr_w(pszSubKey), debugstr_w(pszValue),
+ (fIgnoreHKCU) ? "Ignoring HKCU" : "Tries HKCU then HKLM");
+
+ datalen = (sizeof(data)-1) * sizeof(WCHAR);
+ if (!(retvalue = SHRegGetUSValueW( pszSubKey, pszValue, &type,
+ data, &datalen,
+ fIgnoreHKCU, 0, 0))) {
+ /* process returned data via type into bool */
+ switch (type) {
+ case REG_SZ:
+ data[9] = L'\0'; /* set end of string */
+ if (lstrcmpiW(data, wYES)==0 || lstrcmpiW(data, wTRUE)==0)
+ ret = TRUE;
+ else if (lstrcmpiW(data, wNO)==0 || lstrcmpiW(data, wFALSE)==0)
+ ret = FALSE;
+ break;
+ case REG_DWORD:
+ work = *(LPDWORD)data;
+ ret = (work != 0);
+ break;
+ case REG_BINARY:
+ if (datalen == 1) {
+ ret = (data[0] != L'\0');
+ break;
+ }
+ default:
+ FIXME("Unsupported registry data type %ld\n", type);
+ ret = FALSE;
+ }
+ TRACE("got value (type=%ld), returing <%s>\n", type,
+ (ret) ? "TRUE" : "FALSE");
+ }
+ else {
+ ret = fDefault;
+ TRACE("returning default data <%s>\n",
+ (ret) ? "TRUE" : "FALSE");
+ }
+ return ret;
+}
+
+/*************************************************************************
+ * SHRegQueryInfoUSKeyA [SHLWAPI.@]
+ *
+ * Get information about a user-specific registry key.
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS
+ * Failure: An error code from RegQueryInfoKeyA().
+ */
+LONG WINAPI SHRegQueryInfoUSKeyA(
+ HUSKEY hUSKey, /* [I] Key to query */
+ LPDWORD pcSubKeys, /* [O] Destination for number of sub keys */
+ LPDWORD pcchMaxSubKeyLen, /* [O] Destination for the length of the biggest sub key name */
+ LPDWORD pcValues, /* [O] Destination for number of values */
+ LPDWORD pcchMaxValueNameLen,/* [O] Destination for the length of the biggest value */
+ SHREGENUM_FLAGS enumRegFlags) /* [in] SHREGENUM_ flags from "shlwapi.h" */
+{
+ HKEY dokey;
+ LONG ret;
+
+ TRACE("(%p,%p,%p,%p,%p,%d)\n",
+ hUSKey,pcSubKeys,pcchMaxSubKeyLen,pcValues,
+ pcchMaxValueNameLen,enumRegFlags);
+
+ /* if user wants HKCU, and it exists, then try it */
+ if (((enumRegFlags == SHREGENUM_HKCU) ||
+ (enumRegFlags == SHREGENUM_DEFAULT)) &&
+ (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKCU))) {
+ ret = RegQueryInfoKeyA(dokey, 0, 0, 0,
+ pcSubKeys, pcchMaxSubKeyLen, 0,
+ pcValues, pcchMaxValueNameLen, 0, 0, 0);
+ if ((ret == ERROR_SUCCESS) ||
+ (enumRegFlags == SHREGENUM_HKCU))
+ return ret;
+ }
+ if (((enumRegFlags == SHREGENUM_HKLM) ||
+ (enumRegFlags == SHREGENUM_DEFAULT)) &&
+ (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKLM))) {
+ return RegQueryInfoKeyA(dokey, 0, 0, 0,
+ pcSubKeys, pcchMaxSubKeyLen, 0,
+ pcValues, pcchMaxValueNameLen, 0, 0, 0);
+ }
+ return ERROR_INVALID_FUNCTION;
+}
+
+/*************************************************************************
+ * SHRegQueryInfoUSKeyW [SHLWAPI.@]
+ *
+ * See SHRegQueryInfoUSKeyA.
+ */
+LONG WINAPI SHRegQueryInfoUSKeyW(
+ HUSKEY hUSKey,
+ LPDWORD pcSubKeys,
+ LPDWORD pcchMaxSubKeyLen,
+ LPDWORD pcValues,
+ LPDWORD pcchMaxValueNameLen,
+ SHREGENUM_FLAGS enumRegFlags)
+{
+ HKEY dokey;
+ LONG ret;
+
+ TRACE("(%p,%p,%p,%p,%p,%d)\n",
+ hUSKey,pcSubKeys,pcchMaxSubKeyLen,pcValues,
+ pcchMaxValueNameLen,enumRegFlags);
+
+ /* if user wants HKCU, and it exists, then try it */
+ if (((enumRegFlags == SHREGENUM_HKCU) ||
+ (enumRegFlags == SHREGENUM_DEFAULT)) &&
+ (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKCU))) {
+ ret = RegQueryInfoKeyW(dokey, 0, 0, 0,
+ pcSubKeys, pcchMaxSubKeyLen, 0,
+ pcValues, pcchMaxValueNameLen, 0, 0, 0);
+ if ((ret == ERROR_SUCCESS) ||
+ (enumRegFlags == SHREGENUM_HKCU))
+ return ret;
+ }
+ if (((enumRegFlags == SHREGENUM_HKLM) ||
+ (enumRegFlags == SHREGENUM_DEFAULT)) &&
+ (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKLM))) {
+ return RegQueryInfoKeyW(dokey, 0, 0, 0,
+ pcSubKeys, pcchMaxSubKeyLen, 0,
+ pcValues, pcchMaxValueNameLen, 0, 0, 0);
+ }
+ return ERROR_INVALID_FUNCTION;
+}
+
+/*************************************************************************
+ * SHRegEnumUSKeyA [SHLWAPI.@]
+ *
+ * Enumerate a user-specific registry key.
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS
+ * Failure: An error code from RegEnumKeyExA().
+ */
+LONG WINAPI SHRegEnumUSKeyA(
+ HUSKEY hUSKey, /* [in] Key to enumerate */
+ DWORD dwIndex, /* [in] Index within hUSKey */
+ LPSTR pszName, /* [out] Name of the enumerated value */
+ LPDWORD pcchValueNameLen, /* [in/out] Length of pszName */
+ SHREGENUM_FLAGS enumRegFlags) /* [in] SHREGENUM_ flags from "shlwapi.h" */
+{
+ HKEY dokey;
+
+ TRACE("(%p,%ld,%p,%p(%ld),%d)\n",
+ hUSKey, dwIndex, pszName, pcchValueNameLen,
+ *pcchValueNameLen, enumRegFlags);
+
+ if (((enumRegFlags == SHREGENUM_HKCU) ||
+ (enumRegFlags == SHREGENUM_DEFAULT)) &&
+ (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKCU))) {
+ return RegEnumKeyExA(dokey, dwIndex, pszName, pcchValueNameLen,
+ 0, 0, 0, 0);
+ }
+
+ if (((enumRegFlags == SHREGENUM_HKLM) ||
+ (enumRegFlags == SHREGENUM_DEFAULT)) &&
+ (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKLM))) {
+ return RegEnumKeyExA(dokey, dwIndex, pszName, pcchValueNameLen,
+ 0, 0, 0, 0);
+ }
+ FIXME("no support for SHREGENUM_BOTH\n");
+ return ERROR_INVALID_FUNCTION;
+}
+
+/*************************************************************************
+ * SHRegEnumUSKeyW [SHLWAPI.@]
+ *
+ * See SHRegEnumUSKeyA.
+ */
+LONG WINAPI SHRegEnumUSKeyW(
+ HUSKEY hUSKey,
+ DWORD dwIndex,
+ LPWSTR pszName,
+ LPDWORD pcchValueNameLen,
+ SHREGENUM_FLAGS enumRegFlags)
+{
+ HKEY dokey;
+
+ TRACE("(%p,%ld,%p,%p(%ld),%d)\n",
+ hUSKey, dwIndex, pszName, pcchValueNameLen,
+ *pcchValueNameLen, enumRegFlags);
+
+ if (((enumRegFlags == SHREGENUM_HKCU) ||
+ (enumRegFlags == SHREGENUM_DEFAULT)) &&
+ (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKCU))) {
+ return RegEnumKeyExW(dokey, dwIndex, pszName, pcchValueNameLen,
+ 0, 0, 0, 0);
+ }
+
+ if (((enumRegFlags == SHREGENUM_HKLM) ||
+ (enumRegFlags == SHREGENUM_DEFAULT)) &&
+ (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKLM))) {
+ return RegEnumKeyExW(dokey, dwIndex, pszName, pcchValueNameLen,
+ 0, 0, 0, 0);
+ }
+ FIXME("no support for SHREGENUM_BOTH\n");
+ return ERROR_INVALID_FUNCTION;
+}
+
+
+/*************************************************************************
+ * SHRegWriteUSValueA [SHLWAPI.@]
+ *
+ * Write a user-specific registry value.
+ *
+ * PARAMS
+ * hUSKey [I] Key to write the value to
+ * pszValue [I] Name of value under hUSKey to write the value as
+ * dwType [I] Type of the value
+ * pvData [I] Data to set as the value
+ * cbData [I] length of pvData
+ * dwFlags [I] SHREGSET_ flags from "shlwapi.h"
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS.
+ * Failure: ERROR_INVALID_PARAMETER, if any parameter is invalid, otherwise
+ * an error code from RegSetValueExA().
+ *
+ * NOTES
+ * dwFlags must have at least SHREGSET_FORCE_HKCU or SHREGSET_FORCE_HKLM set.
+ */
+LONG WINAPI SHRegWriteUSValueA(HUSKEY hUSKey, LPCSTR pszValue, DWORD dwType,
+ LPVOID pvData, DWORD cbData, DWORD dwFlags)
+{
+ WCHAR szValue[MAX_PATH];
+
+ if (pszValue)
+ MultiByteToWideChar(CP_ACP, 0, pszValue, -1, szValue, MAX_PATH);
+
+ return SHRegWriteUSValueW(hUSKey, pszValue ? szValue : NULL, dwType,
+ pvData, cbData, dwFlags);
+}
+
+/*************************************************************************
+ * SHRegWriteUSValueW [SHLWAPI.@]
+ *
+ * See SHRegWriteUSValueA.
+ */
+LONG WINAPI SHRegWriteUSValueW(HUSKEY hUSKey, LPCWSTR pszValue, DWORD dwType,
+ LPVOID pvData, DWORD cbData, DWORD dwFlags)
+{
+ DWORD dummy;
+ LPSHUSKEY hKey = (LPSHUSKEY)hUSKey;
+ LONG ret = ERROR_SUCCESS;
+
+ TRACE("(%p,%s,%ld,%p,%ld,%ld)\n", hUSKey, debugstr_w(pszValue),
+ dwType, pvData, cbData, dwFlags);
+
+ if (!hUSKey || IsBadWritePtr(hUSKey, sizeof(SHUSKEY)) ||
+ !(dwFlags & (SHREGSET_FORCE_HKCU|SHREGSET_FORCE_HKLM)))
+ return ERROR_INVALID_PARAMETER;
+
+ if (dwFlags & (SHREGSET_FORCE_HKCU|SHREGSET_HKCU))
+ {
+ if (!hKey->HKCUkey)
+ {
+ /* Create the key */
+ ret = RegCreateKeyW(hKey->HKCUstart, hKey->lpszPath, &hKey->HKCUkey);
+ TRACE("Creating HKCU key, ret = %ld\n", ret);
+ if (ret && (dwFlags & (SHREGSET_FORCE_HKCU)))
+ {
+ hKey->HKCUkey = 0;
+ return ret;
+ }
+ }
+
+ if (!ret)
+ {
+ if ((dwFlags & SHREGSET_FORCE_HKCU) ||
+ RegQueryValueExW(hKey->HKCUkey, pszValue, NULL, NULL, NULL, &dummy))
+ {
+ /* Doesn't exist or we are forcing: Write value */
+ ret = RegSetValueExW(hKey->HKCUkey, pszValue, 0, dwType, pvData, cbData);
+ TRACE("Writing HKCU value, ret = %ld\n", ret);
+ }
+ }
+ }
+
+ if (dwFlags & (SHREGSET_FORCE_HKLM|SHREGSET_HKLM))
+ {
+ if (!hKey->HKLMkey)
+ {
+ /* Create the key */
+ ret = RegCreateKeyW(hKey->HKLMstart, hKey->lpszPath, &hKey->HKLMkey);
+ TRACE("Creating HKLM key, ret = %ld\n", ret);
+ if (ret && (dwFlags & (SHREGSET_FORCE_HKLM)))
+ {
+ hKey->HKLMkey = 0;
+ return ret;
+ }
+ }
+
+ if (!ret)
+ {
+ if ((dwFlags & SHREGSET_FORCE_HKLM) ||
+ RegQueryValueExW(hKey->HKLMkey, pszValue, NULL, NULL, NULL, &dummy))
+ {
+ /* Doesn't exist or we are forcing: Write value */
+ ret = RegSetValueExW(hKey->HKLMkey, pszValue, 0, dwType, pvData, cbData);
+ TRACE("Writing HKLM value, ret = %ld\n", ret);
+ }
+ }
+ }
+
+ return ret;
+}
+
+/*************************************************************************
+ * SHRegGetPathA [SHLWAPI.@]
+ *
+ * Get a path from the registry.
+ *
+ * PARAMS
+ * hKey [I] Handle to registry key
+ * lpszSubKey [I] Name of sub key containing path to get
+ * lpszValue [I] Name of value containing path to get
+ * lpszPath [O] Buffer for returned path
+ * dwFlags [I] Reserved
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS. lpszPath contains the path.
+ * Failure: An error code from RegOpenKeyExA() or SHQueryValueExA().
+ */
+DWORD WINAPI SHRegGetPathA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue,
+ LPSTR lpszPath, DWORD dwFlags)
+{
+ DWORD dwSize = MAX_PATH;
+
+ TRACE("(hkey=%p,%s,%s,%p,%ld)\n", hKey, debugstr_a(lpszSubKey),
+ debugstr_a(lpszValue), lpszPath, dwFlags);
+
+ return SHGetValueA(hKey, lpszSubKey, lpszValue, 0, lpszPath, &dwSize);
+}
+
+/*************************************************************************
+ * SHRegGetPathW [SHLWAPI.@]
+ *
+ * See SHRegGetPathA.
+ */
+DWORD WINAPI SHRegGetPathW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue,
+ LPWSTR lpszPath, DWORD dwFlags)
+{
+ DWORD dwSize = MAX_PATH;
+
+ TRACE("(hkey=%p,%s,%s,%p,%ld)\n", hKey, debugstr_w(lpszSubKey),
+ debugstr_w(lpszValue), lpszPath, dwFlags);
+
+ return SHGetValueW(hKey, lpszSubKey, lpszValue, 0, lpszPath, &dwSize);
+}
+
+
+/*************************************************************************
+ * SHRegSetPathA [SHLWAPI.@]
+ *
+ * Write a path to the registry.
+ *
+ * PARAMS
+ * hKey [I] Handle to registry key
+ * lpszSubKey [I] Name of sub key containing path to set
+ * lpszValue [I] Name of value containing path to set
+ * lpszPath [O] Path to write
+ * dwFlags [I] Reserved, must be 0.
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS.
+ * Failure: An error code from SHSetValueA().
+ */
+DWORD WINAPI SHRegSetPathA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue,
+ LPCSTR lpszPath, DWORD dwFlags)
+{
+ char szBuff[MAX_PATH];
+
+ FIXME("(hkey=%p,%s,%s,%p,%ld) - semi-stub\n",hKey, debugstr_a(lpszSubKey),
+ debugstr_a(lpszValue), lpszPath, dwFlags);
+
+ lstrcpyA(szBuff, lpszPath);
+
+ /* FIXME: PathUnExpandEnvStringsA(szBuff); */
+
+ return SHSetValueA(hKey,lpszSubKey, lpszValue, REG_SZ, szBuff,
+ lstrlenA(szBuff));
+}
+
+/*************************************************************************
+ * SHRegSetPathW [SHLWAPI.@]
+ *
+ * See SHRegSetPathA.
+ */
+DWORD WINAPI SHRegSetPathW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue,
+ LPCWSTR lpszPath, DWORD dwFlags)
+{
+ WCHAR szBuff[MAX_PATH];
+
+ FIXME("(hkey=%p,%s,%s,%p,%ld) - semi-stub\n",hKey, debugstr_w(lpszSubKey),
+ debugstr_w(lpszValue), lpszPath, dwFlags);
+
+ lstrcpyW(szBuff, lpszPath);
+
+ /* FIXME: PathUnExpandEnvStringsW(szBuff); */
+
+ return SHSetValueW(hKey,lpszSubKey, lpszValue, REG_SZ, szBuff,
+ lstrlenW(szBuff));
+}
+
+/*************************************************************************
+ * SHGetValueA [SHLWAPI.@]
+ *
+ * Get a value from the registry.
+ *
+ * PARAMS
+ * hKey [I] Handle to registry key
+ * lpszSubKey [I] Name of sub key containing value to get
+ * lpszValue [I] Name of value to get
+ * pwType [O] Pointer to the values type
+ * pvData [O] Pointer to the values data
+ * pcbData [O] Pointer to the values size
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS. Output parameters contain the details read.
+ * Failure: An error code from RegOpenKeyExA() or SHQueryValueExA().
+ */
+DWORD WINAPI SHGetValueA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue,
+ LPDWORD pwType, LPVOID pvData, LPDWORD pcbData)
+{
+ DWORD dwRet = 0;
+ HKEY hSubKey = 0;
+
+ TRACE("(hkey=%p,%s,%s,%p,%p,%p)\n", hKey, debugstr_a(lpszSubKey),
+ debugstr_a(lpszValue), pwType, pvData, pcbData);
+
+ /* lpszSubKey can be 0. In this case the value is taken from the
+ * current key.
+ */
+ if(lpszSubKey)
+ dwRet = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_QUERY_VALUE, &hSubKey);
+
+ if (! dwRet)
+ {
+ /* SHQueryValueEx expands Environment strings */
+ dwRet = SHQueryValueExA(hSubKey ? hSubKey : hKey, lpszValue, 0, pwType, pvData, pcbData);
+ if (hSubKey) RegCloseKey(hSubKey);
+ }
+ return dwRet;
+}
+
+/*************************************************************************
+ * SHGetValueW [SHLWAPI.@]
+ *
+ * See SHGetValueA.
+ */
+DWORD WINAPI SHGetValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue,
+ LPDWORD pwType, LPVOID pvData, LPDWORD pcbData)
+{
+ DWORD dwRet = 0;
+ HKEY hSubKey = 0;
+
+ TRACE("(hkey=%p,%s,%s,%p,%p,%p)\n", hKey, debugstr_w(lpszSubKey),
+ debugstr_w(lpszValue), pwType, pvData, pcbData);
+
+ if(lpszSubKey)
+ dwRet = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_QUERY_VALUE, &hSubKey);
+
+ if (! dwRet)
+ {
+ dwRet = SHQueryValueExW(hSubKey ? hSubKey : hKey, lpszValue, 0, pwType, pvData, pcbData);
+ if (hSubKey) RegCloseKey(hSubKey);
+ }
+ return dwRet;
+}
+
+/*************************************************************************
+ * SHSetValueA [SHLWAPI.@]
+ *
+ * Set a value in the registry.
+ *
+ * PARAMS
+ * hKey [I] Handle to registry key
+ * lpszSubKey [I] Name of sub key under hKey
+ * lpszValue [I] Name of value to set
+ * dwType [I] Type of the value
+ * pvData [I] Data of the value
+ * cbData [I] Size of the value
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS. The value is set with the data given.
+ * Failure: An error code from RegCreateKeyExA() or RegSetValueExA()
+ *
+ * NOTES
+ * If lpszSubKey does not exist, it is created before the value is set. If
+ * lpszSubKey is NULL or an empty string, then the value is added directly
+ * to hKey instead.
+ */
+DWORD WINAPI SHSetValueA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue,
+ DWORD dwType, LPCVOID pvData, DWORD cbData)
+{
+ DWORD dwRet = ERROR_SUCCESS, dwDummy;
+ HKEY hSubKey;
+ static const char szEmpty[] = { '\0' };
+
+ TRACE("(hkey=%p,%s,%s,%ld,%p,%ld)\n", hKey, debugstr_a(lpszSubKey),
+ debugstr_a(lpszValue), dwType, pvData, cbData);
+
+ if (lpszSubKey && *lpszSubKey)
+ dwRet = RegCreateKeyExA(hKey, lpszSubKey, 0, (LPSTR)szEmpty,
+ 0, KEY_SET_VALUE, NULL, &hSubKey, &dwDummy);
+ else
+ hSubKey = hKey;
+ if (!dwRet)
+ {
+ dwRet = RegSetValueExA(hSubKey, lpszValue, 0, dwType, pvData, cbData);
+ if (hSubKey != hKey)
+ RegCloseKey(hSubKey);
+ }
+ return dwRet;
+}
+
+/*************************************************************************
+ * SHSetValueW [SHLWAPI.@]
+ *
+ * See SHSetValueA.
+ */
+DWORD WINAPI SHSetValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue,
+ DWORD dwType, LPCVOID pvData, DWORD cbData)
+{
+ DWORD dwRet = ERROR_SUCCESS, dwDummy;
+ HKEY hSubKey;
+ static const WCHAR szEmpty[] = { '\0' };
+
+ TRACE("(hkey=%p,%s,%s,%ld,%p,%ld)\n", hKey, debugstr_w(lpszSubKey),
+ debugstr_w(lpszValue), dwType, pvData, cbData);
+
+ if (lpszSubKey && *lpszSubKey)
+ dwRet = RegCreateKeyExW(hKey, lpszSubKey, 0, (LPWSTR)szEmpty,
+ 0, KEY_SET_VALUE, NULL, &hSubKey, &dwDummy);
+ else
+ hSubKey = hKey;
+ if (!dwRet)
+ {
+ dwRet = RegSetValueExW(hSubKey, lpszValue, 0, dwType, pvData, cbData);
+ if (hSubKey != hKey)
+ RegCloseKey(hSubKey);
+ }
+ return dwRet;
+}
+
+/*************************************************************************
+ * SHQueryInfoKeyA [SHLWAPI.@]
+ *
+ * Get information about a registry key. See RegQueryInfoKeyA().
+ *
+ * RETURNS
+ * The result of calling RegQueryInfoKeyA().
+ */
+LONG WINAPI SHQueryInfoKeyA(HKEY hKey, LPDWORD pwSubKeys, LPDWORD pwSubKeyMax,
+ LPDWORD pwValues, LPDWORD pwValueMax)
+{
+ TRACE("(hkey=%p,%p,%p,%p,%p)\n", hKey, pwSubKeys, pwSubKeyMax,
+ pwValues, pwValueMax);
+ return RegQueryInfoKeyA(hKey, NULL, NULL, NULL, pwSubKeys, pwSubKeyMax,
+ NULL, pwValues, pwValueMax, NULL, NULL, NULL);
+}
+
+/*************************************************************************
+ * SHQueryInfoKeyW [SHLWAPI.@]
+ *
+ * See SHQueryInfoKeyA.
+ */
+LONG WINAPI SHQueryInfoKeyW(HKEY hKey, LPDWORD pwSubKeys, LPDWORD pwSubKeyMax,
+ LPDWORD pwValues, LPDWORD pwValueMax)
+{
+ TRACE("(hkey=%p,%p,%p,%p,%p)\n", hKey, pwSubKeys, pwSubKeyMax,
+ pwValues, pwValueMax);
+ return RegQueryInfoKeyW(hKey, NULL, NULL, NULL, pwSubKeys, pwSubKeyMax,
+ NULL, pwValues, pwValueMax, NULL, NULL, NULL);
+}
+
+/*************************************************************************
+ * SHQueryValueExA [SHLWAPI.@]
+ *
+ * Get a value from the registry, expanding environment variable strings.
+ *
+ * PARAMS
+ * hKey [I] Handle to registry key
+ * lpszValue [I] Name of value to query
+ * lpReserved [O] Reserved for future use; must be NULL
+ * pwType [O] Optional pointer updated with the values type
+ * pvData [O] Optional pointer updated with the values data
+ * pcbData [O] Optional pointer updated with the values size
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS. Any non NULL output parameters are updated with
+ * information about the value.
+ * Failure: ERROR_OUTOFMEMORY if memory allocation fails, or the type of the
+ * data is REG_EXPAND_SZ and pcbData is NULL. Otherwise an error
+ * code from RegQueryValueExA() or ExpandEnvironmentStringsA().
+ *
+ * NOTES
+ * Either pwType, pvData or pcbData may be NULL if the caller doesn't want
+ * the type, data or size information for the value.
+ *
+ * If the type of the data is REG_EXPAND_SZ, it is expanded to REG_SZ. The
+ * value returned will be truncated if it is of type REG_SZ and bigger than
+ * the buffer given to store it.
+ *
+ * REG_EXPAND_SZ:
+ * case-1: the unexpanded string is smaller than the expanded one
+ * subcase-1: the buffer is too small to hold the unexpanded string:
+ * function fails and returns the size of the unexpanded string.
+ *
+ * subcase-2: buffer is too small to hold the expanded string:
+ * the function return success (!!) and the result is truncated
+ * *** This is clearly an error in the native implementation. ***
+ *
+ * case-2: the unexpanded string is bigger than the expanded one
+ * The buffer must have enough space to hold the unexpanded
+ * string even if the result is smaller.
+ *
+ */
+DWORD WINAPI SHQueryValueExA( HKEY hKey, LPCSTR lpszValue,
+ LPDWORD lpReserved, LPDWORD pwType,
+ LPVOID pvData, LPDWORD pcbData)
+{
+ DWORD dwRet, dwType, dwUnExpDataLen = 0, dwExpDataLen;
+
+ TRACE("(hkey=%p,%s,%p,%p,%p,%p=%ld)\n", hKey, debugstr_a(lpszValue),
+ lpReserved, pwType, pvData, pcbData, pcbData ? *pcbData : 0);
+
+ if (pcbData) dwUnExpDataLen = *pcbData;
+
+ dwRet = RegQueryValueExA(hKey, lpszValue, lpReserved, &dwType, pvData, &dwUnExpDataLen);
+
+ if (pcbData && (dwType == REG_EXPAND_SZ))
+ {
+ DWORD nBytesToAlloc;
+
+ /* Expand type REG_EXPAND_SZ into REG_SZ */
+ LPSTR szData;
+
+ /* If the caller didn't supply a buffer or the buffer is too small we have
+ * to allocate our own
+ */
+ if ((!pvData) || (dwRet == ERROR_MORE_DATA) )
+ {
+ char cNull = '\0';
+ nBytesToAlloc = (!pvData || (dwRet == ERROR_MORE_DATA)) ? dwUnExpDataLen : *pcbData;
+
+ szData = (LPSTR) LocalAlloc(LMEM_ZEROINIT, nBytesToAlloc);
+ RegQueryValueExA (hKey, lpszValue, lpReserved, NULL, (LPBYTE)szData, &nBytesToAlloc);
+ dwExpDataLen = ExpandEnvironmentStringsA(szData, &cNull, 1);
+ dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);
+ LocalFree((HLOCAL) szData);
+ }
+ else
+ {
+ nBytesToAlloc = (lstrlenA(pvData)+1) * sizeof (CHAR);
+ szData = (LPSTR) LocalAlloc(LMEM_ZEROINIT, nBytesToAlloc );
+ lstrcpyA(szData, pvData);
+ dwExpDataLen = ExpandEnvironmentStringsA(szData, pvData, *pcbData / sizeof(CHAR));
+ if (dwExpDataLen > *pcbData) dwRet = ERROR_MORE_DATA;
+ dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);
+ LocalFree((HLOCAL) szData);
+ }
+ }
+
+ /* Update the type and data size if the caller wanted them */
+ if ( dwType == REG_EXPAND_SZ ) dwType = REG_SZ;
+ if ( pwType ) *pwType = dwType;
+ if ( pcbData ) *pcbData = dwUnExpDataLen;
+ return dwRet;
+}
+
+
+/*************************************************************************
+ * SHQueryValueExW [SHLWAPI.@]
+ *
+ * See SHQueryValueExA.
+ */
+DWORD WINAPI SHQueryValueExW(HKEY hKey, LPCWSTR lpszValue,
+ LPDWORD lpReserved, LPDWORD pwType,
+ LPVOID pvData, LPDWORD pcbData)
+{
+ DWORD dwRet, dwType, dwUnExpDataLen = 0, dwExpDataLen;
+
+ TRACE("(hkey=%p,%s,%p,%p,%p,%p=%ld)\n", hKey, debugstr_w(lpszValue),
+ lpReserved, pwType, pvData, pcbData, pcbData ? *pcbData : 0);
+
+ if (pcbData) dwUnExpDataLen = *pcbData;
+
+ dwRet = RegQueryValueExW(hKey, lpszValue, lpReserved, &dwType, pvData, &dwUnExpDataLen);
+ if (dwRet!=ERROR_SUCCESS && dwRet!=ERROR_MORE_DATA)
+ return dwRet;
+
+ if (pcbData && (dwType == REG_EXPAND_SZ))
+ {
+ DWORD nBytesToAlloc;
+
+ /* Expand type REG_EXPAND_SZ into REG_SZ */
+ LPWSTR szData;
+
+ /* If the caller didn't supply a buffer or the buffer is too small we have
+ * to allocate our own
+ */
+ if ((!pvData) || (dwRet == ERROR_MORE_DATA) )
+ {
+ WCHAR cNull = '\0';
+ nBytesToAlloc = (!pvData || (dwRet == ERROR_MORE_DATA)) ? dwUnExpDataLen : *pcbData;
+
+ szData = (LPWSTR) LocalAlloc(LMEM_ZEROINIT, nBytesToAlloc);
+ RegQueryValueExW (hKey, lpszValue, lpReserved, NULL, (LPBYTE)szData, &nBytesToAlloc);
+ dwExpDataLen = ExpandEnvironmentStringsW(szData, &cNull, 1);
+ dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);
+ LocalFree((HLOCAL) szData);
+ }
+ else
+ {
+ nBytesToAlloc = (lstrlenW(pvData) + 1) * sizeof(WCHAR);
+ szData = (LPWSTR) LocalAlloc(LMEM_ZEROINIT, nBytesToAlloc );
+ lstrcpyW(szData, pvData);
+ dwExpDataLen = ExpandEnvironmentStringsW(szData, pvData, *pcbData/sizeof(WCHAR) );
+ if (dwExpDataLen > *pcbData) dwRet = ERROR_MORE_DATA;
+ dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);
+ LocalFree((HLOCAL) szData);
+ }
+ }
+
+ /* Update the type and data size if the caller wanted them */
+ if ( dwType == REG_EXPAND_SZ ) dwType = REG_SZ;
+ if ( pwType ) *pwType = dwType;
+ if ( pcbData ) *pcbData = dwUnExpDataLen;
+ return dwRet;
+}
+
+/*************************************************************************
+ * SHDeleteKeyA [SHLWAPI.@]
+ *
+ * Delete a registry key and any sub keys/values present
+ *
+ * PARAMS
+ * hKey [I] Handle to registry key
+ * lpszSubKey [I] Name of sub key to delete
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS. The key is deleted.
+ * Failure: An error code from RegOpenKeyExA(), RegQueryInfoKeyA(),
+ * RegEnumKeyExA() or RegDeleteKeyA().
+ */
+DWORD WINAPI SHDeleteKeyA(HKEY hKey, LPCSTR lpszSubKey)
+{
+ DWORD dwRet, dwMaxSubkeyLen = 0, dwSize;
+ CHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
+ HKEY hSubKey = 0;
+
+ TRACE("(hkey=%p,%s)\n", hKey, debugstr_a(lpszSubKey));
+
+ dwRet = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
+ if(!dwRet)
+ {
+ /* Find the maximum subkey length so that we can allocate a buffer */
+ dwRet = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, NULL,
+ &dwMaxSubkeyLen, NULL, NULL, NULL, NULL, NULL, NULL);
+ if(!dwRet)
+ {
+ dwMaxSubkeyLen++;
+ if (dwMaxSubkeyLen > sizeof(szNameBuf))
+ /* Name too big: alloc a buffer for it */
+ lpszName = HeapAlloc(GetProcessHeap(), 0, dwMaxSubkeyLen*sizeof(CHAR));
+
+ if(!lpszName)
+ dwRet = ERROR_NOT_ENOUGH_MEMORY;
+ else
+ {
+ while (dwRet == ERROR_SUCCESS)
+ {
+ dwSize = dwMaxSubkeyLen;
+ dwRet = RegEnumKeyExA(hSubKey, 0, lpszName, &dwSize, NULL, NULL, NULL, NULL);
+ if (dwRet == ERROR_SUCCESS || dwRet == ERROR_MORE_DATA)
+ dwRet = SHDeleteKeyA(hSubKey, lpszName);
+ }
+ if (dwRet == ERROR_NO_MORE_ITEMS)
+ dwRet = ERROR_SUCCESS;
+ if (lpszName != szNameBuf)
+ HeapFree(GetProcessHeap(), 0, lpszName); /* Free buffer if allocated */
+ }
+ }
+
+ RegCloseKey(hSubKey);
+ if(!dwRet)
+ dwRet = RegDeleteKeyA(hKey, lpszSubKey);
+ }
+ return dwRet;
+}
+
+/*************************************************************************
+ * SHDeleteKeyW [SHLWAPI.@]
+ *
+ * See SHDeleteKeyA.
+ */
+DWORD WINAPI SHDeleteKeyW(HKEY hKey, LPCWSTR lpszSubKey)
+{
+ DWORD dwRet, dwKeyCount = 0, dwMaxSubkeyLen = 0, dwSize, i;
+ WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
+ HKEY hSubKey = 0;
+
+ TRACE("(hkey=%p,%s)\n", hKey, debugstr_w(lpszSubKey));
+
+ dwRet = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
+ if(!dwRet)
+ {
+ /* Find how many subkeys there are */
+ dwRet = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, &dwKeyCount,
+ &dwMaxSubkeyLen, NULL, NULL, NULL, NULL, NULL, NULL);
+ if(!dwRet)
+ {
+ dwMaxSubkeyLen++;
+ if (dwMaxSubkeyLen > sizeof(szNameBuf)/sizeof(WCHAR))
+ /* Name too big: alloc a buffer for it */
+ lpszName = HeapAlloc(GetProcessHeap(), 0, dwMaxSubkeyLen*sizeof(WCHAR));
+
+ if(!lpszName)
+ dwRet = ERROR_NOT_ENOUGH_MEMORY;
+ else
+ {
+ /* Recursively delete all the subkeys */
+ for(i = 0; i < dwKeyCount && !dwRet; i++)
+ {
+ dwSize = dwMaxSubkeyLen;
+ dwRet = RegEnumKeyExW(hSubKey, i, lpszName, &dwSize, NULL, NULL, NULL, NULL);
+ if(!dwRet)
+ dwRet = SHDeleteKeyW(hSubKey, lpszName);
+ }
+
+ if (lpszName != szNameBuf)
+ HeapFree(GetProcessHeap(), 0, lpszName); /* Free buffer if allocated */
+ }
+ }
+
+ RegCloseKey(hSubKey);
+ if(!dwRet)
+ dwRet = RegDeleteKeyW(hKey, lpszSubKey);
+ }
+ return dwRet;
+}
+
+/*************************************************************************
+ * SHDeleteEmptyKeyA [SHLWAPI.@]
+ *
+ * Delete a registry key with no sub keys.
+ *
+ * PARAMS
+ * hKey [I] Handle to registry key
+ * lpszSubKey [I] Name of sub key to delete
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS. The key is deleted.
+ * Failure: If the key is not empty, returns ERROR_KEY_HAS_CHILDREN. Otherwise
+ * returns an error code from RegOpenKeyExA(), RegQueryInfoKeyA() or
+ * RegDeleteKeyA().
+ */
+DWORD WINAPI SHDeleteEmptyKeyA(HKEY hKey, LPCSTR lpszSubKey)
+{
+ DWORD dwRet, dwKeyCount = 0;
+ HKEY hSubKey = 0;
+
+ TRACE("(hkey=%p,%s)\n", hKey, debugstr_a(lpszSubKey));
+
+ dwRet = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
+ if(!dwRet)
+ {
+ dwRet = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, &dwKeyCount,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ RegCloseKey(hSubKey);
+ if(!dwRet)
+ {
+ if (!dwKeyCount)
+ dwRet = RegDeleteKeyA(hKey, lpszSubKey);
+ else
+ dwRet = ERROR_KEY_HAS_CHILDREN;
+ }
+ }
+ return dwRet;
+}
+
+/*************************************************************************
+ * SHDeleteEmptyKeyW [SHLWAPI.@]
+ *
+ * See SHDeleteEmptyKeyA.
+ */
+DWORD WINAPI SHDeleteEmptyKeyW(HKEY hKey, LPCWSTR lpszSubKey)
+{
+ DWORD dwRet, dwKeyCount = 0;
+ HKEY hSubKey = 0;
+
+ TRACE("(hkey=%p, %s)\n", hKey, debugstr_w(lpszSubKey));
+
+ dwRet = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
+ if(!dwRet)
+ {
+ dwRet = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, &dwKeyCount,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+ RegCloseKey(hSubKey);
+ if(!dwRet)
+ {
+ if (!dwKeyCount)
+ dwRet = RegDeleteKeyW(hKey, lpszSubKey);
+ else
+ dwRet = ERROR_KEY_HAS_CHILDREN;
+ }
+ }
+ return dwRet;
+}
+
+/*************************************************************************
+ * SHDeleteOrphanKeyA [SHLWAPI.@]
+ *
+ * Delete a registry key with no sub keys or values.
+ *
+ * PARAMS
+ * hKey [I] Handle to registry key
+ * lpszSubKey [I] Name of sub key to possibly delete
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS. The key has been deleted if it was an orphan.
+ * Failure: An error from RegOpenKeyExA(), RegQueryValueExA(), or RegDeleteKeyA().
+ */
+DWORD WINAPI SHDeleteOrphanKeyA(HKEY hKey, LPCSTR lpszSubKey)
+{
+ HKEY hSubKey;
+ DWORD dwKeyCount = 0, dwValueCount = 0, dwRet;
+
+ TRACE("(hkey=%p,%s)\n", hKey, debugstr_a(lpszSubKey));
+
+ dwRet = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
+
+ if(!dwRet)
+ {
+ /* Get subkey and value count */
+ dwRet = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, &dwKeyCount,
+ NULL, NULL, &dwValueCount, NULL, NULL, NULL, NULL);
+
+ if(!dwRet && !dwKeyCount && !dwValueCount)
+ {
+ dwRet = RegDeleteKeyA(hKey, lpszSubKey);
+ }
+ RegCloseKey(hSubKey);
+ }
+ return dwRet;
+}
+
+/*************************************************************************
+ * SHDeleteOrphanKeyW [SHLWAPI.@]
+ *
+ * See SHDeleteOrphanKeyA.
+ */
+DWORD WINAPI SHDeleteOrphanKeyW(HKEY hKey, LPCWSTR lpszSubKey)
+{
+ HKEY hSubKey;
+ DWORD dwKeyCount = 0, dwValueCount = 0, dwRet;
+
+ TRACE("(hkey=%p,%s)\n", hKey, debugstr_w(lpszSubKey));
+
+ dwRet = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
+
+ if(!dwRet)
+ {
+ /* Get subkey and value count */
+ dwRet = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, &dwKeyCount,
+ NULL, NULL, &dwValueCount, NULL, NULL, NULL, NULL);
+
+ if(!dwRet && !dwKeyCount && !dwValueCount)
+ {
+ dwRet = RegDeleteKeyW(hKey, lpszSubKey);
+ }
+ RegCloseKey(hSubKey);
+ }
+ return dwRet;
+}
+
+/*************************************************************************
+ * SHDeleteValueA [SHLWAPI.@]
+ *
+ * Delete a value from the registry.
+ *
+ * PARAMS
+ * hKey [I] Handle to registry key
+ * lpszSubKey [I] Name of sub key containing value to delete
+ * lpszValue [I] Name of value to delete
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS. The value is deleted.
+ * Failure: An error code from RegOpenKeyExA() or RegDeleteValueA().
+ */
+DWORD WINAPI SHDeleteValueA(HKEY hKey, LPCSTR lpszSubKey, LPCSTR lpszValue)
+{
+ DWORD dwRet;
+ HKEY hSubKey;
+
+ TRACE("(hkey=%p,%s,%s)\n", hKey, debugstr_a(lpszSubKey), debugstr_a(lpszValue));
+
+ dwRet = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_SET_VALUE, &hSubKey);
+ if (!dwRet)
+ {
+ dwRet = RegDeleteValueA(hSubKey, lpszValue);
+ RegCloseKey(hSubKey);
+ }
+ return dwRet;
+}
+
+/*************************************************************************
+ * SHDeleteValueW [SHLWAPI.@]
+ *
+ * See SHDeleteValueA.
+ */
+DWORD WINAPI SHDeleteValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue)
+{
+ DWORD dwRet;
+ HKEY hSubKey;
+
+ TRACE("(hkey=%p,%s,%s)\n", hKey, debugstr_w(lpszSubKey), debugstr_w(lpszValue));
+
+ dwRet = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_SET_VALUE, &hSubKey);
+ if (!dwRet)
+ {
+ dwRet = RegDeleteValueW(hSubKey, lpszValue);
+ RegCloseKey(hSubKey);
+ }
+ return dwRet;
+}
+
+/*************************************************************************
+ * SHEnumKeyExA [SHLWAPI.@]
+ *
+ * Enumerate sub keys in a registry key.
+ *
+ * PARAMS
+ * hKey [I] Handle to registry key
+ * dwIndex [I] Index of key to enumerate
+ * lpszSubKey [O] Pointer updated with the subkey name
+ * pwLen [O] Pointer updated with the subkey length
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS. lpszSubKey and pwLen are updated.
+ * Failure: An error code from RegEnumKeyExA().
+ */
+LONG WINAPI SHEnumKeyExA(HKEY hKey, DWORD dwIndex, LPSTR lpszSubKey,
+ LPDWORD pwLen)
+{
+ TRACE("(hkey=%p,%ld,%s,%p)\n", hKey, dwIndex, debugstr_a(lpszSubKey), pwLen);
+
+ return RegEnumKeyExA(hKey, dwIndex, lpszSubKey, pwLen, NULL, NULL, NULL, NULL);
+}
+
+/*************************************************************************
+ * SHEnumKeyExW [SHLWAPI.@]
+ *
+ * See SHEnumKeyExA.
+ */
+LONG WINAPI SHEnumKeyExW(HKEY hKey, DWORD dwIndex, LPWSTR lpszSubKey,
+ LPDWORD pwLen)
+{
+ TRACE("(hkey=%p,%ld,%s,%p)\n", hKey, dwIndex, debugstr_w(lpszSubKey), pwLen);
+
+ return RegEnumKeyExW(hKey, dwIndex, lpszSubKey, pwLen, NULL, NULL, NULL, NULL);
+}
+
+/*************************************************************************
+ * SHEnumValueA [SHLWAPI.@]
+ *
+ * Enumerate values in a registry key.
+ *
+ * PARAMS
+ * hKey [I] Handle to registry key
+ * dwIndex [I] Index of key to enumerate
+ * lpszValue [O] Pointer updated with the values name
+ * pwLen [O] Pointer updated with the values length
+ * pwType [O] Pointer updated with the values type
+ * pvData [O] Pointer updated with the values data
+ * pcbData [O] Pointer updated with the values size
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS. Output parameters are updated.
+ * Failure: An error code from RegEnumValueA().
+ */
+LONG WINAPI SHEnumValueA(HKEY hKey, DWORD dwIndex, LPSTR lpszValue,
+ LPDWORD pwLen, LPDWORD pwType,
+ LPVOID pvData, LPDWORD pcbData)
+{
+ TRACE("(hkey=%p,%ld,%s,%p,%p,%p,%p)\n", hKey, dwIndex,
+ debugstr_a(lpszValue), pwLen, pwType, pvData, pcbData);
+
+ return RegEnumValueA(hKey, dwIndex, lpszValue, pwLen, NULL,
+ pwType, pvData, pcbData);
+}
+
+/*************************************************************************
+ * SHEnumValueW [SHLWAPI.@]
+ *
+ * See SHEnumValueA.
+ */
+LONG WINAPI SHEnumValueW(HKEY hKey, DWORD dwIndex, LPWSTR lpszValue,
+ LPDWORD pwLen, LPDWORD pwType,
+ LPVOID pvData, LPDWORD pcbData)
+{
+ TRACE("(hkey=%p,%ld,%s,%p,%p,%p,%p)\n", hKey, dwIndex,
+ debugstr_w(lpszValue), pwLen, pwType, pvData, pcbData);
+
+ return RegEnumValueW(hKey, dwIndex, lpszValue, pwLen, NULL,
+ pwType, pvData, pcbData);
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.205]
+ *
+ * Get a value from the registry.
+ *
+ * PARAMS
+ * hKey [I] Handle to registry key
+ * pSubKey [I] Name of sub key containing value to get
+ * pValue [I] Name of value to get
+ * pwType [O] Destination for the values type
+ * pvData [O] Destination for the values data
+ * pbData [O] Destination for the values size
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS. Output parameters contain the details read.
+ * Failure: An error code from RegOpenKeyExA() or SHQueryValueExA(),
+ * or ERROR_INVALID_FUNCTION in the machine is in safe mode.
+ */
+DWORD WINAPI SHGetValueGoodBootA(HKEY hkey, LPCSTR pSubKey, LPCSTR pValue,
+ LPDWORD pwType, LPVOID pvData, LPDWORD pbData)
+{
+ if (GetSystemMetrics(SM_CLEANBOOT))
+ return ERROR_INVALID_FUNCTION;
+ return SHGetValueA(hkey, pSubKey, pValue, pwType, pvData, pbData);
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.206]
+ *
+ * Unicode version of SHGetValueGoodBootW.
+ */
+DWORD WINAPI SHGetValueGoodBootW(HKEY hkey, LPCWSTR pSubKey, LPCWSTR pValue,
+ LPDWORD pwType, LPVOID pvData, LPDWORD pbData)
+{
+ if (GetSystemMetrics(SM_CLEANBOOT))
+ return ERROR_INVALID_FUNCTION;
+ return SHGetValueW(hkey, pSubKey, pValue, pwType, pvData, pbData);
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.320]
+ *
+ * Set a MIME content type in the registry.
+ *
+ * PARAMS
+ * lpszSubKey [I] Name of key under HKEY_CLASSES_ROOT.
+ * lpszValue [I] Value to set
+ *
+ * RETURNS
+ * Success: TRUE
+ * Failure: FALSE
+ */
+BOOL WINAPI RegisterMIMETypeForExtensionA(LPCSTR lpszSubKey, LPCSTR lpszValue)
+{
+ DWORD dwRet;
+
+ if (!lpszValue)
+ {
+ WARN("Invalid lpszValue would crash under Win32!\n");
+ return FALSE;
+ }
+
+ dwRet = SHSetValueA(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeA,
+ REG_SZ, lpszValue, strlen(lpszValue));
+ return dwRet ? FALSE : TRUE;
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.321]
+ *
+ * Unicode version of RegisterMIMETypeForExtensionA.
+ */
+BOOL WINAPI RegisterMIMETypeForExtensionW(LPCWSTR lpszSubKey, LPCWSTR lpszValue)
+{
+ DWORD dwRet;
+
+ if (!lpszValue)
+ {
+ WARN("Invalid lpszValue would crash under Win32!\n");
+ return FALSE;
+ }
+
+ dwRet = SHSetValueW(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeW,
+ REG_SZ, lpszValue, strlenW(lpszValue));
+ return dwRet ? FALSE : TRUE;
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.322]
+ *
+ * Delete a MIME content type from the registry.
+ *
+ * PARAMS
+ * lpszSubKey [I] Name of sub key
+ *
+ * RETURNS
+ * Success: TRUE
+ * Failure: FALSE
+ */
+BOOL WINAPI UnregisterMIMETypeForExtensionA(LPCSTR lpszSubKey)
+{
+ HRESULT ret = SHDeleteValueA(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeA);
+ return ret ? FALSE : TRUE;
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.323]
+ *
+ * Unicode version of UnregisterMIMETypeForExtensionA.
+ */
+BOOL WINAPI UnregisterMIMETypeForExtensionW(LPCWSTR lpszSubKey)
+{
+ HRESULT ret = SHDeleteValueW(HKEY_CLASSES_ROOT, lpszSubKey, lpszContentTypeW);
+ return ret ? FALSE : TRUE;
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.328]
+ *
+ * Get the registry path to a MIME content key.
+ *
+ * PARAMS
+ * lpszType [I] Content type to get the path for
+ * lpszBuffer [O] Destination for path
+ * dwLen [I] Length of lpszBuffer
+ *
+ * RETURNS
+ * Success: TRUE. lpszBuffer contains the full path.
+ * Failure: FALSE.
+ *
+ * NOTES
+ * The base path for the key is "MIME\Database\Content Type\"
+ */
+BOOL WINAPI GetMIMETypeSubKeyA(LPCSTR lpszType, LPSTR lpszBuffer, DWORD dwLen)
+{
+ TRACE("(%s,%p,%ld)\n", debugstr_a(lpszType), lpszBuffer, dwLen);
+
+ if (dwLen > dwLenMimeDbContent && lpszType && lpszBuffer)
+ {
+ size_t dwStrLen = strlen(lpszType);
+
+ if (dwStrLen < dwLen - dwLenMimeDbContent)
+ {
+ memcpy(lpszBuffer, szMimeDbContentA, dwLenMimeDbContent);
+ memcpy(lpszBuffer + dwLenMimeDbContent, lpszType, dwStrLen + 1);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.329]
+ *
+ * Unicode version of GetMIMETypeSubKeyA.
+ */
+BOOL WINAPI GetMIMETypeSubKeyW(LPCWSTR lpszType, LPWSTR lpszBuffer, DWORD dwLen)
+{
+ TRACE("(%s,%p,%ld)\n", debugstr_w(lpszType), lpszBuffer, dwLen);
+
+ if (dwLen > dwLenMimeDbContent && lpszType && lpszBuffer)
+ {
+ DWORD dwStrLen = strlenW(lpszType);
+
+ if (dwStrLen < dwLen - dwLenMimeDbContent)
+ {
+ memcpy(lpszBuffer, szMimeDbContentW, dwLenMimeDbContent * sizeof(WCHAR));
+ memcpy(lpszBuffer + dwLenMimeDbContent, lpszType, (dwStrLen + 1) * sizeof(WCHAR));
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.330]
+ *
+ * Get the file extension for a given Mime type.
+ *
+ * PARAMS
+ * lpszType [I] Mime type to get the file extension for
+ * lpExt [O] Destination for the resulting extension
+ * iLen [I] Length of lpExt in characters
+ *
+ * RETURNS
+ * Success: TRUE. lpExt contains the file extension.
+ * Failure: FALSE, if any parameter is invalid or the extension cannot be
+ * retrieved. If iLen > 0, lpExt is set to an empty string.
+ *
+ * NOTES
+ * - The extension returned in lpExt always has a leading '.' character, even
+ * if the registry Mime database entry does not.
+ * - iLen must be long enough for the file extension for this function to succeed.
+ */
+BOOL WINAPI MIME_GetExtensionA(LPCSTR lpszType, LPSTR lpExt, INT iLen)
+{
+ char szSubKey[MAX_PATH];
+ DWORD dwlen = iLen - 1, dwType;
+ BOOL bRet = FALSE;
+
+ if (iLen > 0 && lpExt)
+ *lpExt = '\0';
+
+ if (lpszType && lpExt && iLen > 2 &&
+ GetMIMETypeSubKeyA(lpszType, szSubKey, MAX_PATH) &&
+ !SHGetValueA(HKEY_CLASSES_ROOT, szSubKey, szExtensionA, &dwType, lpExt + 1, &dwlen) &&
+ lpExt[1])
+ {
+ if (lpExt[1] == '.')
+ memmove(lpExt, lpExt + 1, strlen(lpExt + 1) + 1);
+ else
+ *lpExt = '.'; /* Supply a '.' */
+ bRet = TRUE;
+ }
+ return bRet;
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.331]
+ *
+ * Unicode version of MIME_GetExtensionA.
+ */
+BOOL WINAPI MIME_GetExtensionW(LPCWSTR lpszType, LPWSTR lpExt, INT iLen)
+{
+ WCHAR szSubKey[MAX_PATH];
+ DWORD dwlen = iLen - 1, dwType;
+ BOOL bRet = FALSE;
+
+ if (iLen > 0 && lpExt)
+ *lpExt = '\0';
+
+ if (lpszType && lpExt && iLen > 2 &&
+ GetMIMETypeSubKeyW(lpszType, szSubKey, MAX_PATH) &&
+ !SHGetValueW(HKEY_CLASSES_ROOT, szSubKey, szExtensionW, &dwType, lpExt + 1, &dwlen) &&
+ lpExt[1])
+ {
+ if (lpExt[1] == '.')
+ memmove(lpExt, lpExt + 1, (strlenW(lpExt + 1) + 1) * sizeof(WCHAR));
+ else
+ *lpExt = '.'; /* Supply a '.' */
+ bRet = TRUE;
+ }
+ return bRet;
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.324]
+ *
+ * Set the file extension for a MIME content key.
+ *
+ * PARAMS
+ * lpszExt [I] File extension to set
+ * lpszType [I] Content type to set the extension for
+ *
+ * RETURNS
+ * Success: TRUE. The file extension is set in the registry.
+ * Failure: FALSE.
+ */
+BOOL WINAPI RegisterExtensionForMIMETypeA(LPCSTR lpszExt, LPCSTR lpszType)
+{
+ DWORD dwLen;
+ char szKey[MAX_PATH];
+
+ TRACE("(%s,%s)\n", debugstr_a(lpszExt), debugstr_a(lpszType));
+
+ if (!GetMIMETypeSubKeyA(lpszType, szKey, MAX_PATH)) /* Get full path to the key */
+ return FALSE;
+
+ dwLen = strlen(lpszExt) + 1;
+
+ if (SHSetValueA(HKEY_CLASSES_ROOT, szKey, szExtensionA, REG_SZ, lpszExt, dwLen))
+ return FALSE;
+ return TRUE;
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.325]
+ *
+ * Unicode version of RegisterExtensionForMIMETypeA.
+ */
+BOOL WINAPI RegisterExtensionForMIMETypeW(LPCWSTR lpszExt, LPCWSTR lpszType)
+{
+ DWORD dwLen;
+ WCHAR szKey[MAX_PATH];
+
+ TRACE("(%s,%s)\n", debugstr_w(lpszExt), debugstr_w(lpszType));
+
+ /* Get the full path to the key */
+ if (!GetMIMETypeSubKeyW(lpszType, szKey, MAX_PATH)) /* Get full path to the key */
+ return FALSE;
+
+ dwLen = (lstrlenW(lpszExt) + 1) * sizeof(WCHAR);
+
+ if (SHSetValueW(HKEY_CLASSES_ROOT, szKey, szExtensionW, REG_SZ, lpszExt, dwLen))
+ return FALSE;
+ return TRUE;
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.326]
+ *
+ * Delete a file extension from a MIME content type.
+ *
+ * PARAMS
+ * lpszType [I] Content type to delete the extension for
+ *
+ * RETURNS
+ * Success: TRUE. The file extension is deleted from the registry.
+ * Failure: FALSE. The extension may have been removed but the key remains.
+ *
+ * NOTES
+ * If deleting the extension leaves an orphan key, the key is removed also.
+ */
+BOOL WINAPI UnregisterExtensionForMIMETypeA(LPCSTR lpszType)
+{
+ char szKey[MAX_PATH];
+
+ TRACE("(%s)\n", debugstr_a(lpszType));
+
+ if (!GetMIMETypeSubKeyA(lpszType, szKey, MAX_PATH)) /* Get full path to the key */
+ return FALSE;
+
+ if (!SHDeleteValueA(HKEY_CLASSES_ROOT, szKey, szExtensionA))
+ return FALSE;
+
+ if (!SHDeleteOrphanKeyA(HKEY_CLASSES_ROOT, szKey))
+ return FALSE;
+ return TRUE;
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.327]
+ *
+ * Unicode version of UnregisterExtensionForMIMETypeA.
+ */
+BOOL WINAPI UnregisterExtensionForMIMETypeW(LPCWSTR lpszType)
+{
+ WCHAR szKey[MAX_PATH];
+
+ TRACE("(%s)\n", debugstr_w(lpszType));
+
+ if (!GetMIMETypeSubKeyW(lpszType, szKey, MAX_PATH)) /* Get full path to the key */
+ return FALSE;
+
+ if (!SHDeleteValueW(HKEY_CLASSES_ROOT, szKey, szExtensionW))
+ return FALSE;
+
+ if (!SHDeleteOrphanKeyW(HKEY_CLASSES_ROOT, szKey))
+ return FALSE;
+ return TRUE;
+}
+
+/*************************************************************************
+ * SHRegDuplicateHKey [SHLWAPI.@]
+ *
+ * Create a duplicate of a registry handle.
+ *
+ * PARAMS
+ * hKey [I] key to duplicate.
+ *
+ * RETURNS
+ * A new handle pointing to the same key as hKey.
+ */
+HKEY WINAPI SHRegDuplicateHKey(HKEY hKey)
+{
+ HKEY newKey = 0;
+
+ RegOpenKeyExA(hKey, 0, 0, MAXIMUM_ALLOWED, &newKey);
+ TRACE("new key is %p\n", newKey);
+ return newKey;
+}
+
+
+/*************************************************************************
+ * SHCopyKeyA [SHLWAPI.@]
+ *
+ * Copy a key and its values/sub keys to another location.
+ *
+ * PARAMS
+ * hKeySrc [I] Source key to copy from
+ * lpszSrcSubKey [I] Sub key under hKeySrc, or NULL to use hKeySrc directly
+ * hKeyDst [I] Destination key
+ * dwReserved [I] Reserved, must be 0
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS. The key is copied to the destination key.
+ * Failure: A standard windows error code.
+ *
+ * NOTES
+ * If hKeyDst is a key under hKeySrc, this function will misbehave
+ * (It will loop until out of stack, or the registry is full). This
+ * bug is present in Win32 also.
+ */
+DWORD WINAPI SHCopyKeyA(HKEY hKeySrc, LPCSTR lpszSrcSubKey, HKEY hKeyDst, DWORD dwReserved)
+{
+ WCHAR szSubKeyW[MAX_PATH];
+
+ TRACE("(hkey=%p,%s,%p08x,%ld)\n", hKeySrc, debugstr_a(lpszSrcSubKey), hKeyDst, dwReserved);
+
+ if (lpszSrcSubKey)
+ MultiByteToWideChar(0, 0, lpszSrcSubKey, -1, szSubKeyW, MAX_PATH);
+
+ return SHCopyKeyW(hKeySrc, lpszSrcSubKey ? szSubKeyW : NULL, hKeyDst, dwReserved);
+}
+
+/*************************************************************************
+ * SHCopyKeyW [SHLWAPI.@]
+ *
+ * See SHCopyKeyA.
+ */
+DWORD WINAPI SHCopyKeyW(HKEY hKeySrc, LPCWSTR lpszSrcSubKey, HKEY hKeyDst, DWORD dwReserved)
+{
+ DWORD dwKeyCount = 0, dwValueCount = 0, dwMaxKeyLen = 0;
+ DWORD dwMaxValueLen = 0, dwMaxDataLen = 0, i;
+ BYTE buff[1024];
+ LPVOID lpBuff = (LPVOID)buff;
+ WCHAR szName[MAX_PATH], *lpszName = szName;
+ DWORD dwRet = S_OK;
+
+ TRACE("hkey=%p,%s,%p08x,%ld)\n", hKeySrc, debugstr_w(lpszSrcSubKey), hKeyDst, dwReserved);
+
+ if(!hKeyDst || !hKeySrc)
+ dwRet = ERROR_INVALID_PARAMETER;
+ else
+ {
+ /* Open source key */
+ if(lpszSrcSubKey)
+ dwRet = RegOpenKeyExW(hKeySrc, lpszSrcSubKey, 0, KEY_ALL_ACCESS, &hKeySrc);
+
+ if(dwRet)
+ hKeyDst = NULL; /* Don't close this key since we didn't open it */
+ else
+ {
+ /* Get details about sub keys and values */
+ dwRet = RegQueryInfoKeyW(hKeySrc, NULL, NULL, NULL, &dwKeyCount, &dwMaxKeyLen,
+ NULL, &dwValueCount, &dwMaxValueLen, &dwMaxDataLen,
+ NULL, NULL);
+ if(!dwRet)
+ {
+ if (dwMaxValueLen > dwMaxKeyLen)
+ dwMaxKeyLen = dwMaxValueLen; /* Get max size for key/value names */
+
+ if (dwMaxKeyLen++ > MAX_PATH - 1)
+ lpszName = HeapAlloc(GetProcessHeap(), 0, dwMaxKeyLen * sizeof(WCHAR));
+
+ if (dwMaxDataLen > sizeof(buff))
+ lpBuff = HeapAlloc(GetProcessHeap(), 0, dwMaxDataLen);
+
+ if (!lpszName || !lpBuff)
+ dwRet = ERROR_NOT_ENOUGH_MEMORY;
+ }
+ }
+ }
+
+ /* Copy all the sub keys */
+ for(i = 0; i < dwKeyCount && !dwRet; i++)
+ {
+ HKEY hSubKeySrc, hSubKeyDst;
+ DWORD dwSize = dwMaxKeyLen;
+
+ dwRet = RegEnumKeyExW(hKeySrc, i, lpszName, &dwSize, NULL, NULL, NULL, NULL);
+
+ if(!dwRet)
+ {
+ /* Open source sub key */
+ dwRet = RegOpenKeyExW(hKeySrc, lpszName, 0, KEY_READ, &hSubKeySrc);
+
+ if(!dwRet)
+ {
+ /* Create destination sub key */
+ dwRet = RegCreateKeyW(hKeyDst, lpszName, &hSubKeyDst);
+
+ if(!dwRet)
+ {
+ /* Recursively copy keys and values from the sub key */
+ dwRet = SHCopyKeyW(hSubKeySrc, NULL, hSubKeyDst, 0);
+ RegCloseKey(hSubKeyDst);
+ }
+ }
+ RegCloseKey(hSubKeySrc);
+ }
+ }
+
+ /* Copy all the values in this key */
+ for (i = 0; i < dwValueCount && !dwRet; i++)
+ {
+ DWORD dwNameSize = dwMaxKeyLen, dwType, dwLen = dwMaxDataLen;
+
+ dwRet = RegEnumValueW(hKeySrc, i, lpszName, &dwNameSize, NULL, &dwType, buff, &dwLen);
+
+ if (!dwRet)
+ dwRet = SHSetValueW(hKeyDst, NULL, lpszName, dwType, lpBuff, dwLen);
+ }
+
+ /* Free buffers if allocated */
+ if (lpszName != szName)
+ HeapFree(GetProcessHeap(), 0, lpszName);
+ if (lpBuff != buff)
+ HeapFree(GetProcessHeap(), 0, lpBuff);
+
+ if (lpszSrcSubKey && hKeyDst)
+ RegCloseKey(hKeyDst);
+ return dwRet;
+}
+
+/*
+ * The following functions are ORDINAL ONLY:
+ */
+
+/*************************************************************************
+ * @ [SHLWAPI.280]
+ *
+ * Read an integer value from the registry, falling back to a default.
+ *
+ * PARAMS
+ * hKey [I] Registry key to read from
+ * lpszValue [I] Value name to read
+ * iDefault [I] Default value to return
+ *
+ * RETURNS
+ * The value contained in the given registry value if present, otherwise
+ * iDefault.
+ */
+int WINAPI SHRegGetIntW(HKEY hKey, LPCWSTR lpszValue, int iDefault)
+{
+ TRACE("(%p,%s,%d)\n", hKey, debugstr_w(lpszValue), iDefault);
+
+ if (hKey)
+ {
+ WCHAR szBuff[32];
+ DWORD dwSize = sizeof(szBuff);
+ szBuff[0] = '\0';
+ SHQueryValueExW(hKey, lpszValue, 0, 0, szBuff, &dwSize);
+
+ if(*szBuff >= '0' && *szBuff <= '9')
+ return StrToIntW(szBuff);
+ }
+ return iDefault;
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.343]
+ *
+ * Create or open an explorer ClassId Key.
+ *
+ * PARAMS
+ * guid [I] Explorer ClassId key to open
+ * lpszValue [I] Value name under the ClassId Key
+ * bUseHKCU [I] TRUE=Use HKEY_CURRENT_USER, FALSE=Use HKEY_CLASSES_ROOT
+ * bCreate [I] TRUE=Create the key if it doesn't exist, FALSE=Don't
+ * phKey [O] Destination for the resulting key handle
+ *
+ * RETURNS
+ * Success: S_OK. phKey contains the resulting registry handle.
+ * Failure: An HRESULT error code indicating the problem.
+ */
+HRESULT WINAPI SHRegGetCLSIDKeyA(REFGUID guid, LPCSTR lpszValue, BOOL bUseHKCU, BOOL bCreate, PHKEY phKey)
+{
+ WCHAR szValue[MAX_PATH];
+
+ if (lpszValue)
+ MultiByteToWideChar(CP_ACP, 0, lpszValue, -1, szValue, sizeof(szValue)/sizeof(WCHAR));
+
+ return SHRegGetCLSIDKeyW(guid, lpszValue ? szValue : NULL, bUseHKCU, bCreate, phKey);
+}
+
+/*************************************************************************
+ * @ [SHLWAPI.344]
+ *
+ * Unicode version of SHRegGetCLSIDKeyA.
+ */
+HRESULT WINAPI SHRegGetCLSIDKeyW(REFGUID guid, LPCWSTR lpszValue, BOOL bUseHKCU,
+ BOOL bCreate, PHKEY phKey)
+{
+ static const WCHAR szClassIdKey[] = { 'S','o','f','t','w','a','r','e','\\',
+ 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
+ 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
+ 'E','x','p','l','o','r','e','r','\\','C','L','S','I','D','\\' };
+#define szClassIdKeyLen (sizeof(szClassIdKey)/sizeof(WCHAR))
+ WCHAR szKey[MAX_PATH];
+ DWORD dwRet;
+ HKEY hkey;
+
+ /* Create the key string */
+ memcpy(szKey, szClassIdKey, sizeof(szClassIdKey));
+ SHStringFromGUIDW(guid, szKey + szClassIdKeyLen, 39); /* Append guid */
+
+ if(lpszValue)
+ {
+ szKey[szClassIdKeyLen + 39] = '\\';
+ strcpyW(szKey + szClassIdKeyLen + 40, lpszValue); /* Append value name */
+ }
+
+ hkey = bUseHKCU ? HKEY_CURRENT_USER : HKEY_CLASSES_ROOT;
+
+ if(bCreate)
+ dwRet = RegCreateKeyW(hkey, szKey, phKey);
+ else
+ dwRet = RegOpenKeyExW(hkey, szKey, 0, KEY_READ, phKey);
+
+ return dwRet ? HRESULT_FROM_WIN32(dwRet) : S_OK;
+}
+
+/*************************************************************************
+ * SHRegisterValidateTemplate [SHLWAPI.@]
+ *
+ * observed from the ie 5.5 installer:
+ * - allocates a buffer with the size of the given file
+ * - read the file content into the buffer
+ * - creates the key szTemplateKey
+ * - sets "205523652929647911071668590831910975402"=dword:00002e37 at
+ * the key
+ *
+ * PARAMS
+ * filename [I] An existing file its content is read into an allocated
+ * buffer
+ * unknown [I]
+ *
+ * RETURNS
+ * Success: ERROR_SUCCESS.
+ */
+HRESULT WINAPI SHRegisterValidateTemplate(LPCWSTR filename, BOOL unknown)
+{
+/* static const WCHAR szTemplateKey[] = { 'S','o','f','t','w','a','r','e','\\',
+ * 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
+ * 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
+ * 'E','x','p','l','o','r','e','r','\\',
+ * 'T','e','m','p','l','a','t','e','R','e','g','i','s','t','r','y',0 };
+ */
+ FIXME("stub: %s, %08x\n", debugstr_w(filename), unknown);
+
+ return S_OK;
+}