1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 // RegKeyEx.cpp : implementation file
34 static char THIS_FILE[] = __FILE__;
38 CRegKeyEx::Value::Value () :
43 CRegKeyEx::Value::Value (DWORD dw) :
49 CRegKeyEx::Value::Value (LPCTSTR psz) :
52 m_psz=new TCHAR[1+_tcslen(psz)];
56 CRegKeyEx::Value::~Value ()
68 /////////////////////////////////////////////////////////////////////////////
71 CRegKeyEx::~CRegKeyEx()
78 CRegKeyEx::CRegKeyEx(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired)
80 Create(hKeyParent,lpszKeyName,REG_NONE,REG_OPTION_NON_VOLATILE,samDesired);
83 bool CRegKeyEx::QueryValue(LPCTSTR pszValueName,CString &str)
86 bool rc=(ERROR_SUCCESS==::RegQueryValueEx(m_hKey,pszValueName,NULL,&dwType,NULL,&dwLen)) && (REG_SZ==dwType||REG_EXPAND_SZ==dwType);
88 rc&=(ERROR_SUCCESS==CRegKey::QueryValue(str.GetBuffer(1+dwLen),pszValueName,&dwLen));
94 bool CRegKeyEx::QueryValue(int nIndex,CString &strName,CString &strValue)
96 DWORD dwType,dwMaxValueNameLen,dwMaxValueLen;
97 bool rc=(ERROR_SUCCESS==::RegQueryInfoKey(m_hKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&dwMaxValueNameLen,&dwMaxValueLen,NULL,NULL));
101 rc&=(ERROR_SUCCESS==::RegEnumValue(m_hKey,nIndex,strName.GetBuffer(dwMaxValueNameLen),&dwMaxValueNameLen,NULL,&dwType,(LPBYTE)strValue.GetBuffer(dwMaxValueLen),&dwMaxValueLen)) && (REG_SZ==dwType||REG_EXPAND_SZ==dwType);
102 strName.ReleaseBuffer();
103 strValue.ReleaseBuffer();
108 bool CRegKeyEx::QueryValue(LPCTSTR pszValueName,DWORD &dwValue)
111 DWORD dwLen=sizeof DWORD;
112 return (ERROR_SUCCESS==::RegQueryValueEx(m_hKey,pszValueName,NULL,&dwType,(LPBYTE)&dwValue,&dwLen) && REG_DWORD==dwType);
115 bool CRegKeyEx::QueryValue(int nIndex,CString &strName,DWORD &dwValue)
117 DWORD dwType,dwMaxValueNameLen;
118 DWORD dwValueLen=sizeof(DWORD);
119 bool rc=(ERROR_SUCCESS==::RegQueryInfoKey(m_hKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&dwMaxValueNameLen,NULL,NULL,NULL));
121 rc&=(ERROR_SUCCESS==::RegEnumValue(m_hKey,nIndex,strName.GetBuffer(1+dwMaxValueNameLen),&dwMaxValueNameLen,NULL,&dwType,(LPBYTE)&dwValue,&dwValueLen)) && (REG_DWORD==dwType);
122 strName.ReleaseBuffer();
127 CRegKeyEx::Value CRegKeyEx::QueryValue(LPCTSTR pszValueName)
130 if(ERROR_SUCCESS!=::RegQueryValueEx(m_hKey,pszValueName,NULL,&dwType,NULL,NULL)){
137 return QueryValue(pszValueName,strValue)?Value(strValue):Value();
143 return QueryValue(pszValueName,dw)?Value(dw):Value();
152 CRegKeyEx::Value CRegKeyEx::QueryValue(int nIndex,CString &strName)
155 if(ERROR_SUCCESS!=::RegEnumValue(m_hKey,nIndex,NULL,NULL,NULL,&dwType,NULL,NULL)){
162 return QueryValue(nIndex,strName,strValue)?Value(strValue):Value();
168 return QueryValue(nIndex,strName,dw)?Value(dw):Value();
177 bool CRegKeyEx::QueryKey(int nIndex,CString &strName)
180 bool rc=(ERROR_SUCCESS==::RegQueryInfoKey(m_hKey,NULL,NULL,NULL,NULL,&dwNameLen,NULL,NULL,NULL,NULL,NULL,NULL));
183 rc&=(ERROR_SUCCESS==::RegEnumKey(m_hKey,nIndex,strName.GetBuffer(dwNameLen),dwNameLen));
184 strName.ReleaseBuffer();