OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [tools/] [Utils/] [win32/] [RegKeyEx.cpp] - Blame information for rev 26

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

Line No. Rev Author Line
1 26 unneback
//####COPYRIGHTBEGIN####
2
//                                                                          
3
// ----------------------------------------------------------------------------
4
// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5
//
6
// This program is part of the eCos host tools.
7
//
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) 
11
// any later version.
12
// 
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 
16
// more details.
17
// 
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.
21
//
22
// ----------------------------------------------------------------------------
23
//                                                                          
24
//####COPYRIGHTEND####
25
// RegKeyEx.cpp : implementation file
26
//
27
 
28
#include "stdafx.h"
29
#include "RegKeyEx.h"
30
 
31
#ifdef _DEBUG
32
#define new DEBUG_NEW
33
#undef THIS_FILE
34
static char THIS_FILE[] = __FILE__;
35
#endif
36
 
37
 
38
CRegKeyEx::Value::Value () :
39
  m_dwType(REG_NONE)
40
{
41
}
42
 
43
CRegKeyEx::Value::Value (DWORD dw) :
44
  m_dwType(REG_NONE),
45
  m_dw(dw)
46
{
47
}
48
 
49
CRegKeyEx::Value::Value (LPCTSTR psz) :
50
  m_dwType(REG_SZ)
51
{
52
  m_psz=new TCHAR[1+_tcslen(psz)];
53
  _tcscpy(m_psz,psz);
54
}
55
 
56
CRegKeyEx::Value::~Value ()
57
{
58
  switch(Type()) {
59
    case REG_SZ:
60
    case REG_EXPAND_SZ:
61
      delete m_psz;
62
      break;
63
    default:
64
      break;
65
  }
66
}
67
 
68
/////////////////////////////////////////////////////////////////////////////
69
// CRegKeyEx
70
 
71
CRegKeyEx::~CRegKeyEx()
72
{
73
  if(m_hKey){
74
    Close();
75
  }
76
}
77
 
78
CRegKeyEx::CRegKeyEx(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired)
79
{
80
  Create(hKeyParent,lpszKeyName,REG_NONE,REG_OPTION_NON_VOLATILE,samDesired);
81
}
82
 
83
bool CRegKeyEx::QueryValue(LPCTSTR pszValueName,CString &str)
84
{
85
  DWORD dwLen,dwType;
86
  bool rc=(ERROR_SUCCESS==::RegQueryValueEx(m_hKey,pszValueName,NULL,&dwType,NULL,&dwLen)) && (REG_SZ==dwType||REG_EXPAND_SZ==dwType);
87
  if(rc){
88
    rc&=(ERROR_SUCCESS==CRegKey::QueryValue(str.GetBuffer(1+dwLen),pszValueName,&dwLen));
89
    str.ReleaseBuffer();
90
  }
91
  return rc;
92
}
93
 
94
bool CRegKeyEx::QueryValue(int nIndex,CString &strName,CString &strValue)
95
{
96
  DWORD dwType,dwMaxValueNameLen,dwMaxValueLen;
97
  bool rc=(ERROR_SUCCESS==::RegQueryInfoKey(m_hKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&dwMaxValueNameLen,&dwMaxValueLen,NULL,NULL));
98
  if(rc){
99
    dwMaxValueNameLen++;
100
    dwMaxValueLen++;
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();
104
  }
105
  return rc;
106
}
107
 
108
bool CRegKeyEx::QueryValue(LPCTSTR pszValueName,DWORD &dwValue)
109
{
110
  DWORD dwType;
111
  DWORD dwLen=sizeof DWORD;
112
  return (ERROR_SUCCESS==::RegQueryValueEx(m_hKey,pszValueName,NULL,&dwType,(LPBYTE)&dwValue,&dwLen) && REG_DWORD==dwType);
113
}
114
 
115
bool CRegKeyEx::QueryValue(int nIndex,CString &strName,DWORD &dwValue)
116
{
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));
120
  if(rc){
121
    rc&=(ERROR_SUCCESS==::RegEnumValue(m_hKey,nIndex,strName.GetBuffer(1+dwMaxValueNameLen),&dwMaxValueNameLen,NULL,&dwType,(LPBYTE)&dwValue,&dwValueLen)) && (REG_DWORD==dwType);
122
    strName.ReleaseBuffer();
123
  }
124
  return rc;
125
}
126
 
127
CRegKeyEx::Value CRegKeyEx::QueryValue(LPCTSTR pszValueName)
128
{
129
  DWORD dwType;
130
  if(ERROR_SUCCESS!=::RegQueryValueEx(m_hKey,pszValueName,NULL,&dwType,NULL,NULL)){
131
    dwType=REG_NONE;
132
  }
133
  switch(dwType){
134
    case REG_SZ:
135
      {
136
        CString strValue;
137
        return QueryValue(pszValueName,strValue)?Value(strValue):Value();
138
      }
139
      break;
140
    case REG_DWORD:
141
      {
142
        DWORD dw;
143
        return QueryValue(pszValueName,dw)?Value(dw):Value();
144
      }
145
      break;
146
    default:
147
      return Value();
148
      break;
149
  }
150
}
151
 
152
CRegKeyEx::Value CRegKeyEx::QueryValue(int nIndex,CString &strName)
153
{
154
  DWORD dwType;
155
  if(ERROR_SUCCESS!=::RegEnumValue(m_hKey,nIndex,NULL,NULL,NULL,&dwType,NULL,NULL)){
156
    dwType=REG_NONE;
157
  }
158
  switch(dwType){
159
    case REG_SZ:
160
      {
161
        CString strValue;
162
        return QueryValue(nIndex,strName,strValue)?Value(strValue):Value();
163
      }
164
      break;
165
    case REG_DWORD:
166
      {
167
        DWORD dw;
168
        return QueryValue(nIndex,strName,dw)?Value(dw):Value();
169
      }
170
      break;
171
    default:
172
      return Value();
173
      break;
174
  }
175
}
176
 
177
bool CRegKeyEx::QueryKey(int nIndex,CString &strName)
178
{
179
  DWORD dwNameLen;
180
  bool rc=(ERROR_SUCCESS==::RegQueryInfoKey(m_hKey,NULL,NULL,NULL,NULL,&dwNameLen,NULL,NULL,NULL,NULL,NULL,NULL));
181
  if(rc){
182
    dwNameLen++;
183
    rc&=(ERROR_SUCCESS==::RegEnumKey(m_hKey,nIndex,strName.GetBuffer(dwNameLen),dwNameLen));
184
    strName.ReleaseBuffer();
185
  }
186
  return rc;
187
}

powered by: WebSVN 2.1.0

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