OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [Utils/] [win32/] [RegKeyEx.cpp] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
// RegKeyEx.cpp : implementation file
23
//
24
 
25
#include "stdafx.h"
26
#include "RegKeyEx.h"
27
 
28
#ifdef _DEBUG
29
#define new DEBUG_NEW
30
#undef THIS_FILE
31
static char THIS_FILE[] = __FILE__;
32
#endif
33
 
34
 
35
CRegKeyEx::Value::Value () :
36
  m_dwType(REG_NONE)
37
{
38
}
39
 
40
CRegKeyEx::Value::Value (DWORD dw) :
41
  m_dwType(REG_NONE),
42
  m_dw(dw)
43
{
44
}
45
 
46
CRegKeyEx::Value::Value (LPCTSTR psz) :
47
  m_dwType(REG_SZ)
48
{
49
  m_psz=new TCHAR[1+_tcslen(psz)];
50
  _tcscpy(m_psz,psz);
51
}
52
 
53
CRegKeyEx::Value::~Value ()
54
{
55
  switch(Type()) {
56
    case REG_SZ:
57
    case REG_EXPAND_SZ:
58
      delete m_psz;
59
      break;
60
    default:
61
      break;
62
  }
63
}
64
 
65
/////////////////////////////////////////////////////////////////////////////
66
// CRegKeyEx
67
 
68
CRegKeyEx::~CRegKeyEx()
69
{
70
  if(m_hKey){
71
    Close();
72
  }
73
}
74
 
75
CRegKeyEx::CRegKeyEx(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired)
76
{
77
  Create(hKeyParent,lpszKeyName,REG_NONE,REG_OPTION_NON_VOLATILE,samDesired);
78
}
79
 
80
bool CRegKeyEx::QueryValue(LPCTSTR pszValueName,CString &str)
81
{
82
  DWORD dwLen,dwType;
83
  bool rc=(ERROR_SUCCESS==::RegQueryValueEx(m_hKey,pszValueName,NULL,&dwType,NULL,&dwLen)) && (REG_SZ==dwType||REG_EXPAND_SZ==dwType);
84
  if(rc){
85
    rc&=(ERROR_SUCCESS==CRegKey::QueryValue(str.GetBuffer(1+dwLen),pszValueName,&dwLen));
86
    str.ReleaseBuffer();
87
  }
88
  return rc;
89
}
90
 
91
bool CRegKeyEx::QueryValue(int nIndex,CString &strName,CString &strValue)
92
{
93
  DWORD dwType,dwMaxValueNameLen,dwMaxValueLen;
94
  bool rc=(ERROR_SUCCESS==::RegQueryInfoKey(m_hKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&dwMaxValueNameLen,&dwMaxValueLen,NULL,NULL));
95
  if(rc){
96
    dwMaxValueNameLen++;
97
    dwMaxValueLen++;
98
    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);
99
    strName.ReleaseBuffer();
100
    strValue.ReleaseBuffer();
101
  }
102
  return rc;
103
}
104
 
105
bool CRegKeyEx::QueryValue(LPCTSTR pszValueName,DWORD &dwValue)
106
{
107
  DWORD dwType;
108
  DWORD dwLen=sizeof DWORD;
109
  return (ERROR_SUCCESS==::RegQueryValueEx(m_hKey,pszValueName,NULL,&dwType,(LPBYTE)&dwValue,&dwLen) && REG_DWORD==dwType);
110
}
111
 
112
bool CRegKeyEx::QueryValue(int nIndex,CString &strName,DWORD &dwValue)
113
{
114
  DWORD dwType,dwMaxValueNameLen;
115
  DWORD dwValueLen=sizeof(DWORD);
116
  bool rc=(ERROR_SUCCESS==::RegQueryInfoKey(m_hKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&dwMaxValueNameLen,NULL,NULL,NULL));
117
  if(rc){
118
    rc&=(ERROR_SUCCESS==::RegEnumValue(m_hKey,nIndex,strName.GetBuffer(1+dwMaxValueNameLen),&dwMaxValueNameLen,NULL,&dwType,(LPBYTE)&dwValue,&dwValueLen)) && (REG_DWORD==dwType);
119
    strName.ReleaseBuffer();
120
  }
121
  return rc;
122
}
123
 
124
CRegKeyEx::Value CRegKeyEx::QueryValue(LPCTSTR pszValueName)
125
{
126
  DWORD dwType;
127
  if(ERROR_SUCCESS!=::RegQueryValueEx(m_hKey,pszValueName,NULL,&dwType,NULL,NULL)){
128
    dwType=REG_NONE;
129
  }
130
  switch(dwType){
131
    case REG_SZ:
132
      {
133
        CString strValue;
134
        return QueryValue(pszValueName,strValue)?Value(strValue):Value();
135
      }
136
      break;
137
    case REG_DWORD:
138
      {
139
        DWORD dw;
140
        return QueryValue(pszValueName,dw)?Value(dw):Value();
141
      }
142
      break;
143
    default:
144
      return Value();
145
      break;
146
  }
147
}
148
 
149
CRegKeyEx::Value CRegKeyEx::QueryValue(int nIndex,CString &strName)
150
{
151
  DWORD dwType;
152
  if(ERROR_SUCCESS!=::RegEnumValue(m_hKey,nIndex,NULL,NULL,NULL,&dwType,NULL,NULL)){
153
    dwType=REG_NONE;
154
  }
155
  switch(dwType){
156
    case REG_SZ:
157
      {
158
        CString strValue;
159
        return QueryValue(nIndex,strName,strValue)?Value(strValue):Value();
160
      }
161
      break;
162
    case REG_DWORD:
163
      {
164
        DWORD dw;
165
        return QueryValue(nIndex,strName,dw)?Value(dw):Value();
166
      }
167
      break;
168
    default:
169
      return Value();
170
      break;
171
  }
172
}
173
 
174
bool CRegKeyEx::QueryKey(int nIndex,CString &strName)
175
{
176
  DWORD dwNameLen;
177
  bool rc=(ERROR_SUCCESS==::RegQueryInfoKey(m_hKey,NULL,NULL,NULL,NULL,&dwNameLen,NULL,NULL,NULL,NULL,NULL,NULL));
178
  if(rc){
179
    dwNameLen++;
180
    rc&=(ERROR_SUCCESS==::RegEnumKey(m_hKey,nIndex,strName.GetBuffer(dwNameLen),dwNameLen));
181
    strName.ReleaseBuffer();
182
  }
183
  return rc;
184
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.