{
return E_INVALIDARG;
}
-
+
HRESULT hr = Uninit();
if (FAILED(hr))
return hr;
{
m_pszMachineName = NULL; // local registry
}
-
+
ASSERT(m_pszKeyName == NULL);
m_CurrentAccess = 0;
ASSERT(m_hKey == NULL);
if (!pszKeyName || !hKey)
return E_INVALIDARG;
-
+
// copy key name name
size_t size = _tcslen(pszKeyName);
if (pszPath)
size += _tcslen(pszPath);
-
+
m_pszKeyName = new TCHAR [size+2];
if (!m_pszKeyName)
return E_OUTOFMEMORY;
LONG nError = ERROR_SUCCESS;
if((m_hKey != NULL)&&(!IsHive(m_hKey)))
nError = RegCloseKey(m_hKey);
-
+
m_hKey = NULL;
-
+
return (nError == ERROR_SUCCESS)?S_OK:E_FAIL;
}
(_tcsicmp(pszSubkeyName,_T("HKEY_CLASSES_ROOT")) == 0))
{
rhKey = HKEY_CLASSES_ROOT;
-
+
if (m_pszMachineName)
return ERROR_FILE_NOT_FOUND;
-
+
return ERROR_SUCCESS;
}
else if ((_tcsicmp(pszSubkeyName,_T("HKCU")) == 0)||
(_tcsicmp(pszSubkeyName,_T("HKEY_CURRENT_USER")) == 0))
{
rhKey = HKEY_CURRENT_USER;
-
+
if (m_pszMachineName)
return ERROR_FILE_NOT_FOUND;
-
+
return ERROR_SUCCESS;
}
else if ((_tcsicmp(pszSubkeyName,_T("HKLM")) == 0)||
(_tcsicmp(pszSubkeyName,_T("HKEY_LOCAL_MACHINE")) == 0))
{
rhKey = HKEY_LOCAL_MACHINE;
-
+
if (m_pszMachineName)
return RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
-
+
return ERROR_SUCCESS;
}
else if ((_tcsicmp(pszSubkeyName,_T("HKU")) == 0)||
(_tcsicmp(pszSubkeyName,_T("HKEY_USERS")) == 0))
{
rhKey = HKEY_USERS;
-
+
if (m_pszMachineName)
return RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
-
+
return ERROR_SUCCESS;
}
else if ((_tcsicmp(pszSubkeyName,_T("HKPD")) == 0)||
(_tcsicmp(pszSubkeyName,_T("HKEY_PERFORMANCE_DATA")) == 0))
{
rhKey = HKEY_PERFORMANCE_DATA;
-
+
if (m_pszMachineName)
return RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
-
+
return ERROR_SUCCESS;
}
else if ((_tcsicmp(pszSubkeyName,_T("HKDD")) == 0)||
(_tcsicmp(pszSubkeyName,_T("HKEY_DYN_DATA")) == 0))
{
rhKey = HKEY_DYN_DATA;
-
+
if (m_pszMachineName)
return RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
-
+
return ERROR_SUCCESS;
}
else if ((_tcsicmp(pszSubkeyName,_T("HKCC")) == 0)||
(_tcsicmp(pszSubkeyName,_T("HKEY_CURRENT_CONFIG")) == 0))
{
rhKey = HKEY_CURRENT_CONFIG;
-
+
if (m_pszMachineName)
{
TCHAR *pch = m_pszMachineName;
while (*pch)
pch++;
pch--;
-
+
ASSERT(*pch == _T('\\'));
if (*pch != _T('\\'))
return ERROR_INTERNAL_ERROR;
*pch = 0;
-
+
LONG nError = RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
*pch = _T('\\');
-
+
return nError;
}
-
+
return ERROR_SUCCESS;
}
else
return ERROR_FILE_NOT_FOUND;
}
}
-
+
return RegOpenKeyEx(m_hKey,pszSubkeyName,0,samDesired,&rhKey);
}
{
HKEY hKey;
LONG nError = OpenSubkey(samDesired, pszSubkeyName, hKey);
-
+
if (nError == ERROR_SUCCESS)
{
const TCHAR *pszKeyName = GetKeyName();
if (rdwMaxSubkeyNameLength < l)
rdwMaxSubkeyNameLength = l;
}
-
+
rdwMaxSubkeyNameLength++; // terminating null
-
+
return ERROR_SUCCESS;
}
-
+
LONG nRet;
nRet = RegQueryInfoKey(m_hKey,NULL,NULL,NULL,NULL,&rdwMaxSubkeyNameLength,NULL,NULL,NULL,NULL,NULL,NULL);
rdwMaxSubkeyNameLength = (nRet == ERROR_SUCCESS)?(rdwMaxSubkeyNameLength+1):0;
-
+
return nRet;
}
LONG CRegistryKey::GetNextSubkeyName(DWORD *pdwActualSize)
{
LONG nError;
-
+
if (m_hKey == NULL)
{
if (m_dwCurrentSubKeyIndex < (DWORD)(m_pszMachineName?5:7))
if (pdwActualSize)
*pdwActualSize = dwActualSize;
}
-
+
m_dwCurrentSubKeyIndex++;
if (pdwActualSize)
if (!m_hKey)
return 0; // the root key abstraction has only subkeys (hives)
-
+
LONG nError = RegQueryInfoKeyW(m_hKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&rdwMaxValueNameBuferSize,NULL,NULL,NULL);
rdwMaxValueNameBuferSize++;
m_pbValueDataBuffer = pbValueDataBuffer;
m_dwValueDataBufferSize = dwValueDataBufferSize;
m_pdwType = pdwType;
-
+
m_dwCurrentValueIndex = 0;
}
{
if (!m_hKey)
return ERROR_NO_MORE_ITEMS; // the root key abstraction has only subkeys (hives)
-
+
DWORD dwValueNameBufferSize = m_dwValueNameBufferSize;
DWORD dwValueDataBufferSize = m_dwValueDataBufferSize;
LONG nError = RegEnumValue(m_hKey,
if (pdwNameActualSize)
*pdwNameActualSize = dwValueNameBufferSize;
-
+
if (pdwDataActualSize)
*pdwDataActualSize = dwValueDataBufferSize;
-
+
m_dwCurrentValueIndex++;
return nError;
}
{
if (!m_hKey)
return 0; // the root key abstraction has only subkeys (hives)
-
+
return RegQueryInfoKeyW(m_hKey,NULL,NULL,NULL,NULL,NULL,NULL,&rdwValueCount,NULL,NULL,NULL,NULL);
}
DWORD *pdwValueDataActualSize)
{
DWORD dwBufferSize = dwValueDataBufferSize;
-
+
LONG nError = RegQueryValueEx(m_hKey,NULL,NULL,pdwType,pbValueDataBuffer,&dwBufferSize);
if (pdwValueDataActualSize && (nError == ERROR_SUCCESS))
BOOL blnVolatile)
{
DWORD dwDisposition;
-
+
LONG nError = RegCreateKeyEx(
m_hKey,
pszSubkeyName,
if ((nError == ERROR_SUCCESS)&&(pblnOpened))
*pblnOpened = dwDisposition == REG_OPENED_EXISTING_KEY;
-
+
return nError;
}
SYSTEMTIME st;
if (GetLastWriteTime(st) != ERROR_SUCCESS)
return _T("(Cannot get time last write time)");
-
+
static TCHAR Buffer[256];
_stprintf(Buffer,_T("%d.%d.%d %02d:%02d:%02d"),st.wDay,st.wMonth,st.wYear,st.wHour,st.wMinute,st.wSecond);
return Buffer;