ReactOS 0.4.15-dev-5666-gc548b97
CRegistryKey Class Reference

#include <RegistryKey.h>

Inheritance diagram for CRegistryKey:
Collaboration diagram for CRegistryKey:

Public Member Functions

STDMETHODIMP QueryInterface (REFIID InterfaceId, PVOID *Interface)
 
 CRegistryKey (IUnknown *OuterUnknown, HANDLE hKey, BOOL CanDelete)
 
virtual ~CRegistryKey ()
 
 CRegistryKey ()
 
HRESULT InitRoot (const TCHAR *pszMachineName=NULL)
 
HRESULT Init (HKEY hKey, const TCHAR *pszPath, const TCHAR *pszKeyName, REGSAM CurrentAccess)
 
HRESULT Uninit ()
 
virtual ~CRegistryKey ()
 
const TCHARGetKeyName ()
 
BOOL IsRoot ()
 
LONG OpenSubkey (REGSAM samDesired, const TCHAR *pszSubkeyName, HKEY &rhKey)
 
LONG OpenSubkey (REGSAM samDesired, const TCHAR *pszSubkeyName, CRegistryKey &rKey)
 
LONG GetSubkeyNameMaxLength (DWORD &rdwMaxSubkeyNameLength)
 
void InitSubkeyEnumeration (TCHAR *pchSubkeyNameBuffer, DWORD dwBufferSize)
 
LONG GetNextSubkeyName (DWORD *pdwActualSize=NULL)
 
LONG GetSubkeyCount (DWORD &rdwSubkeyCount)
 
LONG GetMaxValueNameLength (DWORD &rdwMaxValueNameBufferSize)
 
LONG GetMaxValueDataSize (DWORD &rdwMaxValueDataBufferSize)
 
void InitValueEnumeration (TCHAR *pszValueNameBuffer, DWORD dwValueNameBufferSize, BYTE *pbValueDataBuffer, DWORD dwValueDataBufferSize, DWORD *pdwType)
 
LONG GetNextValue (DWORD *pdwNameActualSize=NULL, DWORD *pdwDataActualSize=NULL)
 
LONG GetValueCount (DWORD &rdwValueCount)
 
LONG GetDefaultValue (DWORD *pdwType, BYTE *pbValueDataBuffer, DWORD dwValueDataBufferSize, DWORD *pdwValueDataActualSize)
 
DWORD GetValue (TCHAR *pchValueName, DWORD *pdwType, LPBYTE lpValueDataBuffer, DWORD *pdwValueDataSize)
 
LONG CreateSubkey (REGSAM samDesired, const TCHAR *pszKeyName, HKEY &rhKey, BOOL *pblnOpened=NULL, BOOL blnVolatile=FALSE)
 
LONG GetLastWriteTime (SYSTEMTIME &st)
 
const TCHARGetLastWriteTime ()
 
LONG DeleteValue (const TCHAR *pszValueName)
 
LONG DeleteSubkey (const TCHAR *pszPatternSubkeyName)
 
LONG SetValue (LPCTSTR pszValueName, DWORD dwType, BYTE *lpData, DWORD dwDataSize)
 
TCHARGetSubKeyNameByIndex (DWORD dwIndex)
 
LONG GetSecurityDescriptor (SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor, LPDWORD lpcbSecurityDescriptor)
 
LONG GetSecurityDescriptorLength (DWORD *pdwSecurityDescriptor)
 
BOOL IsPredefined ()
 
 operator HKEY ()
 
- Public Member Functions inherited from CUnknownImpl< IRegistryKey >
 STDMETHODIMP_ (ULONG) AddRef()
 
 STDMETHODIMP_ (ULONG) Release()
 

Static Public Member Functions

static BOOL IsHive (HKEY hKey)
 
static const TCHARGetValueTypeName (DWORD dwType)
 

Public Attributes

 IMP_IRegistryKey
 

Protected Attributes

HANDLE m_hKey
 
BOOL m_Deleted
 
BOOL m_CanDelete
 

Private Attributes

DWORD m_dwCurrentSubKeyIndex
 
TCHARm_pchSubkeyNameBuffer
 
DWORD m_dwSubkeyNameBufferSize
 
DWORD m_dwCurrentValueIndex
 
TCHARm_pszValueNameBuffer
 
DWORD m_dwValueNameBufferSize
 
BYTEm_pbValueDataBuffer
 
DWORD m_dwValueDataBufferSize
 
DWORDm_pdwType
 
HKEY m_hKey
 
TCHARm_pszKeyName
 
TCHARm_pszMachineName
 
REGSAM m_CurrentAccess
 

Additional Inherited Members

- Protected Member Functions inherited from CUnknownImpl< IRegistryKey >
 CUnknownImpl ()
 
virtual ~CUnknownImpl ()
 

Detailed Description

Definition at line 17 of file registry.cpp.

Constructor & Destructor Documentation

◆ CRegistryKey() [1/2]

CRegistryKey::CRegistryKey ( IUnknown OuterUnknown,
HANDLE  hKey,
BOOL  CanDelete 
)
inline

Definition at line 23 of file registry.cpp.

23 :
24 m_hKey(hKey),
26 m_CanDelete(CanDelete)
27 {
28 }
BOOL m_Deleted
Definition: registry.cpp:34
BOOL m_CanDelete
Definition: registry.cpp:35
HANDLE m_hKey
Definition: registry.cpp:33
#define FALSE
Definition: types.h:117
FxAutoRegKey hKey

◆ ~CRegistryKey() [1/2]

CRegistryKey::~CRegistryKey ( )
virtual

Definition at line 38 of file registry.cpp.

39{
40 if (!m_Deleted)
41 {
42 // close key only when has not been deleted yet
44 }
45}
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)

◆ CRegistryKey() [2/2]

CRegistryKey::CRegistryKey ( )

Definition at line 44 of file RegistryKey.cpp.

45{
49 m_hKey = NULL;
50}
TCHAR * m_pszKeyName
Definition: RegistryKey.h:253
TCHAR * m_pszMachineName
Definition: RegistryKey.h:254
REGSAM m_CurrentAccess
Definition: RegistryKey.h:255
#define NULL
Definition: types.h:112

◆ ~CRegistryKey() [2/2]

virtual CRegistryKey::~CRegistryKey ( )
virtual

Member Function Documentation

◆ CreateSubkey()

LONG CRegistryKey::CreateSubkey ( REGSAM  samDesired,
const TCHAR pszKeyName,
HKEY rhKey,
BOOL pblnOpened = NULL,
BOOL  blnVolatile = FALSE 
)

Definition at line 501 of file RegistryKey.cpp.

506{
507 DWORD dwDisposition;
508
509 LONG nError = RegCreateKeyEx(
510 m_hKey,
511 pszSubkeyName,
512 0,
513 NULL,
515 samDesired,
516 NULL,
517 &rhKey,
518 &dwDisposition);
519
520 if ((nError == ERROR_SUCCESS)&&(pblnOpened))
521 *pblnOpened = dwDisposition == REG_OPENED_EXISTING_KEY;
522
523 return nError;
524}
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned long DWORD
Definition: ntddk_ex.h:95
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
long LONG
Definition: pedump.c:60
#define RegCreateKeyEx
Definition: winreg.h:501

Referenced by CRegistryTree::NewKey().

◆ DeleteSubkey()

LONG CRegistryKey::DeleteSubkey ( const TCHAR pszPatternSubkeyName)

Definition at line 562 of file RegistryKey.cpp.

563{
564 return RegDeleteKey(m_hKey,pszSubkeyName);
565}
#define RegDeleteKey
Definition: winreg.h:502

Referenced by CRegistryTree::DeleteSubkeys().

◆ DeleteValue()

LONG CRegistryKey::DeleteValue ( const TCHAR pszValueName)

Definition at line 572 of file RegistryKey.cpp.

573{
574 return RegDeleteValue(m_hKey,pszValueName);
575}
#define RegDeleteValue
Definition: winreg.h:508

◆ GetDefaultValue()

LONG CRegistryKey::GetDefaultValue ( DWORD pdwType,
BYTE pbValueDataBuffer,
DWORD  dwValueDataBufferSize,
DWORD pdwValueDataActualSize 
)

Definition at line 450 of file RegistryKey.cpp.

454{
455 DWORD dwBufferSize = dwValueDataBufferSize;
456
457 LONG nError = RegQueryValueEx(m_hKey,NULL,NULL,pdwType,pbValueDataBuffer,&dwBufferSize);
458
459 if (pdwValueDataActualSize && (nError == ERROR_SUCCESS))
460 *pdwValueDataActualSize = dwBufferSize;
461
462 return nError;
463}
#define RegQueryValueEx
Definition: winreg.h:524

◆ GetKeyName()

const TCHAR * CRegistryKey::GetKeyName ( )

◆ GetLastWriteTime() [1/2]

const TCHAR * CRegistryKey::GetLastWriteTime ( )

Definition at line 540 of file RegistryKey.cpp.

541{
542 SYSTEMTIME st;
544 return _T("(Cannot get time last write time)");
545
546 static TCHAR Buffer[256];
547 _stprintf(Buffer,_T("%d.%d.%d %02d:%02d:%02d"),st.wDay,st.wMonth,st.wYear,st.wHour,st.wMinute,st.wSecond);
548 return Buffer;
549}
Definition: bufpool.h:45
const TCHAR * GetLastWriteTime()
#define _stprintf
Definition: utility.h:124
WORD wYear
Definition: winbase.h:905
WORD wMonth
Definition: winbase.h:906
WORD wHour
Definition: winbase.h:909
WORD wSecond
Definition: winbase.h:911
WORD wMinute
Definition: winbase.h:910
WORD wDay
Definition: winbase.h:908
char TCHAR
Definition: xmlstorage.h:189

Referenced by GetLastWriteTime().

◆ GetLastWriteTime() [2/2]

LONG CRegistryKey::GetLastWriteTime ( SYSTEMTIME st)

Definition at line 526 of file RegistryKey.cpp.

527{
528 FILETIME ftLocal,ft;
530
531 if (nError == ERROR_SUCCESS)
532 {
533 FileTimeToLocalFileTime(&ft,&ftLocal);
534 FileTimeToSystemTime(&ftLocal,&st);
535 }
536
537 return nError;
538}
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3690
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:188
BOOL WINAPI FileTimeToLocalFileTime(IN CONST FILETIME *lpFileTime, OUT LPFILETIME lpLocalFileTime)
Definition: time.c:221

◆ GetMaxValueDataSize()

LONG CRegistryKey::GetMaxValueDataSize ( DWORD rdwMaxValueDataBufferSize)

Definition at line 380 of file RegistryKey.cpp.

381{
382 return RegQueryInfoKeyW(m_hKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&rdwMaxValueDataBuferSize,NULL,NULL);
383}

◆ GetMaxValueNameLength()

LONG CRegistryKey::GetMaxValueNameLength ( DWORD rdwMaxValueNameBufferSize)

Definition at line 385 of file RegistryKey.cpp.

386{
387 rdwMaxValueNameBuferSize = 0;
388
389 if (!m_hKey)
390 return 0; // the root key abstraction has only subkeys (hives)
391
392 LONG nError = RegQueryInfoKeyW(m_hKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&rdwMaxValueNameBuferSize,NULL,NULL,NULL);
393
394 rdwMaxValueNameBuferSize++;
395 return nError;
396}

◆ GetNextSubkeyName()

LONG CRegistryKey::GetNextSubkeyName ( DWORD pdwActualSize = NULL)

Definition at line 333 of file RegistryKey.cpp.

334{
335 LONG nError;
336
337 if (m_hKey == NULL)
338 {
340 {
343 nError = ERROR_SUCCESS;
344 if (pdwActualSize)
345 *pdwActualSize = strlen(m_pchSubkeyNameBuffer);
346 }
347 else
348 {
349 nError = ERROR_NO_MORE_ITEMS;
350 }
351 }
352 else
353 {
354 DWORD dwActualSize = m_dwSubkeyNameBufferSize;
355 FILETIME ft;
356 nError = RegEnumKeyEx(m_hKey,
359 &dwActualSize,
360 NULL,
361 NULL,
362 NULL,
363 &ft);
364 if (pdwActualSize)
365 *pdwActualSize = dwActualSize;
366 }
367
369
370 if (pdwActualSize)
371 *pdwActualSize = strlen(m_pchSubkeyNameBuffer);
372 return nError;
373}
static const TCHAR * g_ppszHiveNames[]
Definition: RegistryKey.cpp:29
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
DWORD m_dwSubkeyNameBufferSize
Definition: RegistryKey.h:243
TCHAR * m_pchSubkeyNameBuffer
Definition: RegistryKey.h:242
DWORD m_dwCurrentSubKeyIndex
Definition: RegistryKey.h:241
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define _tcsncpy
Definition: tchar.h:1410
#define RegEnumKeyEx
Definition: winreg.h:510

Referenced by CRegistryTree::DeleteSubkeys(), and CRegistryTree::InternalGetSubkey().

◆ GetNextValue()

LONG CRegistryKey::GetNextValue ( DWORD pdwNameActualSize = NULL,
DWORD pdwDataActualSize = NULL 
)

Definition at line 416 of file RegistryKey.cpp.

417{
418 if (!m_hKey)
419 return ERROR_NO_MORE_ITEMS; // the root key abstraction has only subkeys (hives)
420
421 DWORD dwValueNameBufferSize = m_dwValueNameBufferSize;
422 DWORD dwValueDataBufferSize = m_dwValueDataBufferSize;
423 LONG nError = RegEnumValue(m_hKey,
426 &dwValueNameBufferSize,
427 NULL,
428 m_pdwType,
430 &dwValueDataBufferSize);
431
432 if (pdwNameActualSize)
433 *pdwNameActualSize = dwValueNameBufferSize;
434
435 if (pdwDataActualSize)
436 *pdwDataActualSize = dwValueDataBufferSize;
437
439 return nError;
440}
DWORD m_dwValueNameBufferSize
Definition: RegistryKey.h:247
DWORD m_dwCurrentValueIndex
Definition: RegistryKey.h:245
DWORD * m_pdwType
Definition: RegistryKey.h:250
TCHAR * m_pszValueNameBuffer
Definition: RegistryKey.h:246
DWORD m_dwValueDataBufferSize
Definition: RegistryKey.h:249
BYTE * m_pbValueDataBuffer
Definition: RegistryKey.h:248
#define RegEnumValue
Definition: winreg.h:511

◆ GetSecurityDescriptor()

LONG CRegistryKey::GetSecurityDescriptor ( SECURITY_INFORMATION  SecurityInformation,
PSECURITY_DESCRIPTOR  pSecurityDescriptor,
LPDWORD  lpcbSecurityDescriptor 
)

Definition at line 557 of file RegistryKey.cpp.

558{
559 return RegGetKeySecurity(m_hKey,SecurityInformation,pSecurityDescriptor,lpcbSecurityDescriptor);
560}
LONG WINAPI RegGetKeySecurity(HKEY hKey, SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor, LPDWORD lpcbSecurityDescriptor)
Definition: reg.c:3010
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ SECURITY_INFORMATION SecurityInformation
Definition: fltkernel.h:1340

◆ GetSecurityDescriptorLength()

LONG CRegistryKey::GetSecurityDescriptorLength ( DWORD pdwSecurityDescriptor)

Definition at line 551 of file RegistryKey.cpp.

552{
554 NULL,NULL,pdwSecurityDescriptor,NULL);
555}

◆ GetSubkeyCount()

LONG CRegistryKey::GetSubkeyCount ( DWORD rdwSubkeyCount)

Definition at line 375 of file RegistryKey.cpp.

376{
378}

◆ GetSubKeyNameByIndex()

TCHAR * CRegistryKey::GetSubKeyNameByIndex ( DWORD  dwIndex)

◆ GetSubkeyNameMaxLength()

LONG CRegistryKey::GetSubkeyNameMaxLength ( DWORD rdwMaxSubkeyNameLength)

Definition at line 300 of file RegistryKey.cpp.

301{
302 if (m_hKey == NULL)
303 { // root key
304 rdwMaxSubkeyNameLength = 0;
305 for(int i = 0; i < 7 ; i++)
306 {
307 size_t l = _tcslen(g_ppszHiveNames[i]);
308 if (rdwMaxSubkeyNameLength < l)
309 rdwMaxSubkeyNameLength = l;
310 }
311
312 rdwMaxSubkeyNameLength++; // terminating null
313
314 return ERROR_SUCCESS;
315 }
316
317 LONG nRet;
318
319 nRet = RegQueryInfoKey(m_hKey,NULL,NULL,NULL,NULL,&rdwMaxSubkeyNameLength,NULL,NULL,NULL,NULL,NULL,NULL);
320
321 rdwMaxSubkeyNameLength = (nRet == ERROR_SUCCESS)?(rdwMaxSubkeyNameLength+1):0;
322
323 return nRet;
324}
r l[0]
Definition: byte_order.h:167
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define RegQueryInfoKey
Definition: winreg.h:521
#define _tcslen
Definition: xmlstorage.h:198

Referenced by CRegistryTree::DeleteSubkeys(), and CRegistryTree::InternalGetSubkey().

◆ GetValue()

DWORD CRegistryKey::GetValue ( TCHAR pchValueName,
DWORD pdwType,
LPBYTE  lpValueDataBuffer,
DWORD pdwValueDataSize 
)

Definition at line 496 of file RegistryKey.cpp.

497{
498 return RegQueryValueEx(m_hKey,pchValueName,NULL,pdwType,lpValueDataBuffer,pdwValueDataSize);
499}

◆ GetValueCount()

LONG CRegistryKey::GetValueCount ( DWORD rdwValueCount)

Definition at line 442 of file RegistryKey.cpp.

443{
444 if (!m_hKey)
445 return 0; // the root key abstraction has only subkeys (hives)
446
448}

◆ GetValueTypeName()

const TCHAR * CRegistryKey::GetValueTypeName ( DWORD  dwType)
static

Definition at line 465 of file RegistryKey.cpp.

466{
467 switch(dwType)
468 {
469 case REG_NONE:
470 return _T("REG_NONE");
471 case REG_SZ:
472 return _T("REG_SZ");
473 case REG_EXPAND_SZ:
474 return _T("REG_EXPAND_SZ");
475 case REG_BINARY:
476 return _T("REG_BINARY");
478 return _T("REG_DWORD_LITTLE_ENDIAN");
480 return _T("REG_DWORD_BIG_ENDIAN");
481 case REG_LINK:
482 return _T("REG_LINK");
483 case REG_MULTI_SZ:
484 return _T("REG_MULTI_SZ");
486 return _T("REG_RESOURCE_LIST");
488 return _T("REG_FULL_RESOURCE_DESCRIPTOR");
490 return _T("REG_RESOURCE_REQUIREMENTS_LIST");
491 default:
492 return _T("Unkown Type");
493 }
494}
#define REG_SZ
Definition: layer.c:22
#define REG_BINARY
Definition: nt_native.h:1496
#define REG_DWORD_LITTLE_ENDIAN
Definition: nt_native.h:1498
#define REG_DWORD_BIG_ENDIAN
Definition: nt_native.h:1499
#define REG_RESOURCE_LIST
Definition: nt_native.h:1502
#define REG_MULTI_SZ
Definition: nt_native.h:1501
#define REG_RESOURCE_REQUIREMENTS_LIST
Definition: nt_native.h:1504
#define REG_LINK
Definition: nt_native.h:1500
#define REG_NONE
Definition: nt_native.h:1492
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define REG_FULL_RESOURCE_DESCRIPTOR
Definition: nt_native.h:1503

Referenced by CShellCommandDir::Execute(), and CShellCommandValue::Execute().

◆ Init()

HRESULT CRegistryKey::Init ( HKEY  hKey,
const TCHAR pszPath,
const TCHAR pszKeyName,
REGSAM  CurrentAccess 
)

Definition at line 91 of file RegistryKey.cpp.

92{
93 HRESULT hr = Uninit();
94 if (FAILED(hr))
95 return hr;
96
97 if (!pszKeyName || !hKey)
98 return E_INVALIDARG;
99
100 // copy key name name
101 size_t size = _tcslen(pszKeyName);
102 if (pszPath)
103 size += _tcslen(pszPath);
104
105 m_pszKeyName = new (std::nothrow) TCHAR [size+2];
106 if (!m_pszKeyName)
107 return E_OUTOFMEMORY;
108 _stprintf(m_pszKeyName,_T("%s%s\\"),pszPath?pszPath:_T(""),pszKeyName);
109
110 m_CurrentAccess = CurrentAccess;
111 m_hKey = hKey;
112 ASSERT(m_hKey);
113
114 return S_OK;
115}
HRESULT Uninit()
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
GLsizeiptr size
Definition: glext.h:5919
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define ASSERT(a)
Definition: mode.c:44
HRESULT hr
Definition: shlfolder.c:183

Referenced by CRegistryTree::InternalGetSubkey(), and OpenSubkey().

◆ InitRoot()

HRESULT CRegistryKey::InitRoot ( const TCHAR pszMachineName = NULL)

Definition at line 52 of file RegistryKey.cpp.

53{
54 if ((pszMachineName)&&
55 ((_tcslen(pszMachineName) < 3)||
56 (pszMachineName[0] != _T('\\'))||
57 (pszMachineName[1] != _T('\\'))
58 )
59 )
60 {
61 return E_INVALIDARG;
62 }
63
64 HRESULT hr = Uninit();
65 if (FAILED(hr))
66 return hr;
67
68 if (pszMachineName)
69 { // copy machine name
70 size_t size = _tcslen(pszMachineName);
71
72 m_pszMachineName = new (std::nothrow) TCHAR [size+2];
74 return E_OUTOFMEMORY;
75 _tcscpy(m_pszMachineName,pszMachineName);
76 m_pszMachineName[size] = _T('\\');
78 }
79 else
80 {
81 m_pszMachineName = NULL; // local registry
82 }
83
86 ASSERT(m_hKey == NULL);
87
88 return S_OK;
89}
#define _tcscpy
Definition: tchar.h:623

Referenced by CRegistryTree::CRegistryTree(), CRegistryTree::GetKey(), and CRegistryTree::SetMachineName().

◆ InitSubkeyEnumeration()

void CRegistryKey::InitSubkeyEnumeration ( TCHAR pchSubkeyNameBuffer,
DWORD  dwBufferSize 
)

Definition at line 326 of file RegistryKey.cpp.

327{
328 m_pchSubkeyNameBuffer = pszSubkeyNameBuffer;
329 m_dwSubkeyNameBufferSize = dwBufferSize;
331}

Referenced by CRegistryTree::DeleteSubkeys(), and CRegistryTree::InternalGetSubkey().

◆ InitValueEnumeration()

void CRegistryKey::InitValueEnumeration ( TCHAR pszValueNameBuffer,
DWORD  dwValueNameBufferSize,
BYTE pbValueDataBuffer,
DWORD  dwValueDataBufferSize,
DWORD pdwType 
)

Definition at line 398 of file RegistryKey.cpp.

403{
404 m_pszValueNameBuffer = pszValueNameBuffer;
405 m_dwValueNameBufferSize = dwValueNameBufferSize;
406 m_pbValueDataBuffer = pbValueDataBuffer;
407 m_dwValueDataBufferSize = dwValueDataBufferSize;
408 m_pdwType = pdwType;
409
411}

◆ IsHive()

BOOL CRegistryKey::IsHive ( HKEY  hKey)
static

Definition at line 140 of file RegistryKey.cpp.

141{
142 return ((hKey == HKEY_CLASSES_ROOT)||
145 (hKey == HKEY_USERS)||
148 (hKey == HKEY_DYN_DATA));
149}
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_CONFIG
Definition: winreg.h:15
#define HKEY_DYN_DATA
Definition: winreg.h:16
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define HKEY_PERFORMANCE_DATA
Definition: winreg.h:14
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define HKEY_USERS
Definition: winreg.h:13

Referenced by Uninit().

◆ IsPredefined()

BOOL CRegistryKey::IsPredefined ( )

◆ IsRoot()

◆ OpenSubkey() [1/2]

LONG CRegistryKey::OpenSubkey ( REGSAM  samDesired,
const TCHAR pszSubkeyName,
CRegistryKey rKey 
)

Definition at line 266 of file RegistryKey.cpp.

267{
268 HKEY hKey;
269 LONG nError = OpenSubkey(samDesired, pszSubkeyName, hKey);
270
271 if (nError == ERROR_SUCCESS)
272 {
273 const TCHAR *pszKeyName = GetKeyName();
274 size_t size = _tcslen(pszKeyName) + _tcslen(pszSubkeyName) + 1;
275 TCHAR *pszSubkeyFullName = new (std::nothrow) TCHAR [size];
276 if (!pszSubkeyFullName)
277 {
278 nError = RegCloseKey(hKey);
279 ASSERT(nError == ERROR_SUCCESS);
280 return ERROR_OUTOFMEMORY;
281 }
282 _tcscpy(pszSubkeyFullName,pszKeyName);
283 _tcscat(pszSubkeyFullName,pszSubkeyName);
284 HRESULT hr = rKey.Init(hKey,GetKeyName(),pszSubkeyName,samDesired);
285 delete[] pszSubkeyName;
286 if (FAILED(hr))
287 {
288 nError = RegCloseKey(hKey);
289 ASSERT(nError == ERROR_SUCCESS);
290 if (hr == (HRESULT)E_OUTOFMEMORY)
291 return ERROR_OUTOFMEMORY;
292 else
294 }
295 }
296
297 return nError;
298}
#define RegCloseKey(hKey)
Definition: registry.h:47
const TCHAR * GetKeyName()
LONG OpenSubkey(REGSAM samDesired, const TCHAR *pszSubkeyName, HKEY &rhKey)
HRESULT Init(HKEY hKey, const TCHAR *pszPath, const TCHAR *pszKeyName, REGSAM CurrentAccess)
Definition: RegistryKey.cpp:91
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define _tcscat
Definition: tchar.h:622
#define ERROR_INTERNAL_ERROR
Definition: winerror.h:840

◆ OpenSubkey() [2/2]

LONG CRegistryKey::OpenSubkey ( REGSAM  samDesired,
const TCHAR pszSubkeyName,
HKEY rhKey 
)

Definition at line 166 of file RegistryKey.cpp.

167{
168 if (m_hKey == NULL)
169 { // subkey of root key is hive root key.
170 if ((_tcsicmp(pszSubkeyName,_T("HKCR")) == 0)||
171 (_tcsicmp(pszSubkeyName,_T("HKEY_CLASSES_ROOT")) == 0))
172 {
173 rhKey = HKEY_CLASSES_ROOT;
174
177
178 return ERROR_SUCCESS;
179 }
180 else if ((_tcsicmp(pszSubkeyName,_T("HKCU")) == 0)||
181 (_tcsicmp(pszSubkeyName,_T("HKEY_CURRENT_USER")) == 0))
182 {
183 rhKey = HKEY_CURRENT_USER;
184
187
188 return ERROR_SUCCESS;
189 }
190 else if ((_tcsicmp(pszSubkeyName,_T("HKLM")) == 0)||
191 (_tcsicmp(pszSubkeyName,_T("HKEY_LOCAL_MACHINE")) == 0))
192 {
193 rhKey = HKEY_LOCAL_MACHINE;
194
196 return RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
197
198 return ERROR_SUCCESS;
199 }
200 else if ((_tcsicmp(pszSubkeyName,_T("HKU")) == 0)||
201 (_tcsicmp(pszSubkeyName,_T("HKEY_USERS")) == 0))
202 {
203 rhKey = HKEY_USERS;
204
206 return RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
207
208 return ERROR_SUCCESS;
209 }
210 else if ((_tcsicmp(pszSubkeyName,_T("HKPD")) == 0)||
211 (_tcsicmp(pszSubkeyName,_T("HKEY_PERFORMANCE_DATA")) == 0))
212 {
213 rhKey = HKEY_PERFORMANCE_DATA;
214
216 return RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
217
218 return ERROR_SUCCESS;
219 }
220 else if ((_tcsicmp(pszSubkeyName,_T("HKDD")) == 0)||
221 (_tcsicmp(pszSubkeyName,_T("HKEY_DYN_DATA")) == 0))
222 {
223 rhKey = HKEY_DYN_DATA;
224
226 return RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
227
228 return ERROR_SUCCESS;
229 }
230 else if ((_tcsicmp(pszSubkeyName,_T("HKCC")) == 0)||
231 (_tcsicmp(pszSubkeyName,_T("HKEY_CURRENT_CONFIG")) == 0))
232 {
233 rhKey = HKEY_CURRENT_CONFIG;
234
236 {
238 while (*pch)
239 pch++;
240 pch--;
241
242 ASSERT(*pch == _T('\\'));
243 if (*pch != _T('\\'))
245
246 *pch = 0;
247
248 LONG nError = RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
249
250 *pch = _T('\\');
251
252 return nError;
253 }
254
255 return ERROR_SUCCESS;
256 }
257 else
258 {
260 }
261 }
262
263 return RegOpenKeyEx(m_hKey,pszSubkeyName,0,samDesired,&rhKey);
264}
#define pch(ap)
Definition: match.c:418
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegConnectRegistry
Definition: winreg.h:495
#define _tcsicmp
Definition: xmlstorage.h:205

Referenced by CRegistryTree::DeleteSubkeys(), CRegistryTree::InternalGetSubkey(), and OpenSubkey().

◆ operator HKEY()

CRegistryKey::operator HKEY ( )
inline

Definition at line 239 of file RegistryKey.h.

239{return m_hKey;};

◆ QueryInterface()

NTSTATUS NTAPI CRegistryKey::QueryInterface ( REFIID  InterfaceId,
PVOID Interface 
)

Definition at line 50 of file registry.cpp.

53{
55
56 DPRINT("CRegistryKey::QueryInterface entered\n");
57 if (IsEqualGUIDAligned(refiid, IID_IRegistryKey) ||
59 {
60 *Output = PVOID(PREGISTRYKEY(this));
61 PUNKNOWN(*Output)->AddRef();
62 return STATUS_SUCCESS;
63 }
64
66 {
67 DPRINT1("CRegistryKey::QueryInterface no interface!!! iface %S\n", GuidString.Buffer);
69 }
70
72}
#define DPRINT1
Definition: precomp.h:8
const GUID IID_IUnknown
IUnknown * PUNKNOWN
Definition: com_apitest.h:45
NTSYSAPI NTSTATUS WINAPI RtlStringFromGUID(REFGUID, PUNICODE_STRING)
ULONG AddRef()
void * PVOID
Definition: retypes.h:9
static PWSTR GuidString
Definition: apphelp.c:93
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
IRegistryKey * PREGISTRYKEY
Definition: portcls.h:1009
@ Output
Definition: arc.h:85
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:235

Referenced by PcNewRegistryKey().

◆ SetValue()

LONG CRegistryKey::SetValue ( LPCTSTR  pszValueName,
DWORD  dwType,
BYTE lpData,
DWORD  dwDataSize 
)

Definition at line 567 of file RegistryKey.cpp.

568{
569 return RegSetValueEx(m_hKey,pszValueName,0,dwType,lpData,dwDataSize);
570}
#define RegSetValueEx
Definition: winreg.h:533

◆ Uninit()

HRESULT CRegistryKey::Uninit ( )

Definition at line 117 of file RegistryKey.cpp.

118{
119 if (m_pszKeyName)
120 {
121 delete [] m_pszKeyName;
123 }
124
126 {
127 delete [] m_pszMachineName;
129 }
130
131 LONG nError = ERROR_SUCCESS;
132 if((m_hKey != NULL)&&(!IsHive(m_hKey)))
133 nError = RegCloseKey(m_hKey);
134
135 m_hKey = NULL;
136
137 return (nError == ERROR_SUCCESS)?S_OK:E_FAIL;
138}
static BOOL IsHive(HKEY hKey)
#define E_FAIL
Definition: ddrawi.h:102

Referenced by Init(), and InitRoot().

Member Data Documentation

◆ IMP_IRegistryKey

CRegistryKey::IMP_IRegistryKey

Definition at line 22 of file registry.cpp.

◆ m_CanDelete

BOOL CRegistryKey::m_CanDelete
protected

Definition at line 35 of file registry.cpp.

◆ m_CurrentAccess

REGSAM CRegistryKey::m_CurrentAccess
private

Definition at line 255 of file RegistryKey.h.

Referenced by CRegistryKey(), Init(), and InitRoot().

◆ m_Deleted

BOOL CRegistryKey::m_Deleted
protected

Definition at line 34 of file registry.cpp.

Referenced by ~CRegistryKey().

◆ m_dwCurrentSubKeyIndex

DWORD CRegistryKey::m_dwCurrentSubKeyIndex
private

Definition at line 241 of file RegistryKey.h.

Referenced by GetNextSubkeyName(), and InitSubkeyEnumeration().

◆ m_dwCurrentValueIndex

DWORD CRegistryKey::m_dwCurrentValueIndex
private

Definition at line 245 of file RegistryKey.h.

Referenced by GetNextValue(), and InitValueEnumeration().

◆ m_dwSubkeyNameBufferSize

DWORD CRegistryKey::m_dwSubkeyNameBufferSize
private

Definition at line 243 of file RegistryKey.h.

Referenced by GetNextSubkeyName(), and InitSubkeyEnumeration().

◆ m_dwValueDataBufferSize

DWORD CRegistryKey::m_dwValueDataBufferSize
private

Definition at line 249 of file RegistryKey.h.

Referenced by GetNextValue(), and InitValueEnumeration().

◆ m_dwValueNameBufferSize

DWORD CRegistryKey::m_dwValueNameBufferSize
private

Definition at line 247 of file RegistryKey.h.

Referenced by GetNextValue(), and InitValueEnumeration().

◆ m_hKey [1/2]

◆ m_hKey [2/2]

HKEY CRegistryKey::m_hKey
private

Definition at line 252 of file RegistryKey.h.

◆ m_pbValueDataBuffer

BYTE* CRegistryKey::m_pbValueDataBuffer
private

Definition at line 248 of file RegistryKey.h.

Referenced by GetNextValue(), and InitValueEnumeration().

◆ m_pchSubkeyNameBuffer

TCHAR* CRegistryKey::m_pchSubkeyNameBuffer
private

Definition at line 242 of file RegistryKey.h.

Referenced by GetNextSubkeyName(), and InitSubkeyEnumeration().

◆ m_pdwType

DWORD* CRegistryKey::m_pdwType
private

Definition at line 250 of file RegistryKey.h.

Referenced by GetNextValue(), and InitValueEnumeration().

◆ m_pszKeyName

TCHAR* CRegistryKey::m_pszKeyName
private

Definition at line 253 of file RegistryKey.h.

Referenced by CRegistryKey(), GetKeyName(), Init(), InitRoot(), and Uninit().

◆ m_pszMachineName

TCHAR* CRegistryKey::m_pszMachineName
private

Definition at line 254 of file RegistryKey.h.

Referenced by CRegistryKey(), GetKeyName(), GetNextSubkeyName(), InitRoot(), OpenSubkey(), and Uninit().

◆ m_pszValueNameBuffer

TCHAR* CRegistryKey::m_pszValueNameBuffer
private

Definition at line 246 of file RegistryKey.h.

Referenced by GetNextValue(), and InitValueEnumeration().


The documentation for this class was generated from the following files: