📄 reg.c
字号:
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 %08x\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 %08x\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 %d, %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 %d, %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,%d,%p,%d,0x%08x\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,%d,%p,%d,0x%08x\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 %d\n", type);
ret = FALSE;
}
TRACE("got value (type=%d), returning <%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] = '\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] != '\0');
break;
}
default:
FIXME("Unsupported registry data type %d\n", type);
ret = FALSE;
}
TRACE("got value (type=%d), returning <%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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -