ReactOS  0.4.15-dev-489-g75a0787
CEnumRegKey Class Reference
Inheritance diagram for CEnumRegKey:
Collaboration diagram for CEnumRegKey:

Public Member Functions

 CEnumRegKey ()
 
 ~CEnumRegKey ()
 
HRESULT Initialize (PCWSTR path, HKEY root)
 
HRESULT NextKey (LPITEMIDLIST *ppidl)
 
HRESULT NextValue (LPITEMIDLIST *ppidl)
 
HRESULT EnumerateNext (LPITEMIDLIST *ppidl)
 
virtual HRESULT STDMETHODCALLTYPE Next (ULONG celt, LPITEMIDLIST *rgelt, ULONG *pceltFetched)
 
virtual HRESULT STDMETHODCALLTYPE Skip (ULONG celt)
 
virtual HRESULT STDMETHODCALLTYPE Reset ()
 
virtual HRESULT STDMETHODCALLTYPE Clone (IEnumIDList **ppenum)
 
- Public Member Functions inherited from ATL::CComObjectRootEx< CComMultiThreadModelNoCS >
 ~CComObjectRootEx ()
 
ULONG InternalAddRef ()
 
ULONG InternalRelease ()
 
void Lock ()
 
void Unlock ()
 
HRESULT _AtlInitialConstruct ()
 
- Public Member Functions inherited from ATL::CComObjectRootBase
 CComObjectRootBase ()
 
 ~CComObjectRootBase ()
 
void SetVoid (void *)
 
HRESULT _AtlFinalConstruct ()
 
HRESULT FinalConstruct ()
 
void InternalFinalConstructAddRef ()
 
void InternalFinalConstructRelease ()
 
void FinalRelease ()
 
- Public Member Functions inherited from IEnumIDList
HRESULT Next ([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] PITEMID_CHILD *rgelt, [out] ULONG *pceltFetched)
 
- Public Member Functions inherited from IUnknown
HRESULT QueryInterface ([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
 
ULONG AddRef ()
 
ULONG Release ()
 

Private Attributes

PCWSTR m_path
 
HKEY m_hkey
 
BOOL m_values
 
int m_idx
 

Additional Inherited Members

- Public Types inherited from IEnumIDList
typedef IEnumIDListLPENUMIDLIST
 
- Public Types inherited from IUnknown
typedef IUnknownLPUNKNOWN
 
- Static Public Member Functions inherited from ATL::CComObjectRootBase
static void WINAPI ObjectMain (bool)
 
static const struct _ATL_CATMAP_ENTRYGetCategoryMap ()
 
static HRESULT WINAPI InternalQueryInterface (void *pThis, const _ATL_INTMAP_ENTRY *pEntries, REFIID iid, void **ppvObject)
 
- Public Attributes inherited from ATL::CComObjectRootBase
LONG m_dwRef
 

Detailed Description

Definition at line 310 of file ntobjenum.cpp.

Constructor & Destructor Documentation

◆ CEnumRegKey()

CEnumRegKey::CEnumRegKey ( )
inline

Definition at line 320 of file ntobjenum.cpp.

322  {
323  }
smooth NULL
Definition: ftsmooth.c:416
PCWSTR m_path
Definition: ntobjenum.cpp:314

◆ ~CEnumRegKey()

CEnumRegKey::~CEnumRegKey ( )
inline

Definition at line 325 of file ntobjenum.cpp.

326  {
328  }
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423

Member Function Documentation

◆ Clone()

virtual HRESULT STDMETHODCALLTYPE CEnumRegKey::Clone ( IEnumIDList **  ppenum)
inlinevirtual

Implements IEnumIDList.

Definition at line 548 of file ntobjenum.cpp.

549  {
550  return E_NOTIMPL;
551  }
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ EnumerateNext()

HRESULT CEnumRegKey::EnumerateNext ( LPITEMIDLIST ppidl)
inline

Definition at line 493 of file ntobjenum.cpp.

494  {
495  if (!m_values)
496  {
497  HRESULT hr = NextKey(ppidl);
498  if (hr != S_FALSE)
499  return hr;
500 
501  // switch to values.
502  m_values = TRUE;
503  m_idx = 0;
504  }
505 
506  return NextValue(ppidl);
507  }
#define TRUE
Definition: types.h:120
HRESULT NextKey(LPITEMIDLIST *ppidl)
Definition: ntobjenum.cpp:352
HRESULT hr
Definition: shlfolder.c:183
#define S_FALSE
Definition: winerror.h:2357
LONG HRESULT
Definition: typedefs.h:78
HRESULT NextValue(LPITEMIDLIST *ppidl)
Definition: ntobjenum.cpp:417

◆ Initialize()

HRESULT CEnumRegKey::Initialize ( PCWSTR  path,
HKEY  root 
)
inline

Definition at line 330 of file ntobjenum.cpp.

331  {
332  m_path = path;
333 
334  DWORD res;
335  if (root)
336  {
338  }
339  else
340  {
342  }
343  if (!NT_SUCCESS(res))
344  {
345  ERR("RegOpenKeyExW failed for path %S with status=%x\n", path, res);
346  return HRESULT_FROM_NT(res);
347  }
348 
349  return S_OK;
350  }
GLsizei const GLchar ** path
Definition: glext.h:7234
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define HRESULT_FROM_NT(x)
Definition: winerror.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
PCWSTR m_path
Definition: ntobjenum.cpp:314
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:454
#define STANDARD_RIGHTS_READ
Definition: nt_native.h:65
#define ERR(fmt,...)
Definition: debug.h:110
#define S_OK
Definition: intsafe.h:59
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
GLuint res
Definition: glext.h:9613
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
static DWORD NtOpenObject(OBJECT_TYPE type, PHANDLE phandle, DWORD access, LPCWSTR path)
Definition: ntobjenum.cpp:61
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019

◆ Next()

virtual HRESULT STDMETHODCALLTYPE CEnumRegKey::Next ( ULONG  celt,
LPITEMIDLIST rgelt,
ULONG pceltFetched 
)
inlinevirtual

Definition at line 509 of file ntobjenum.cpp.

510  {
511  if (pceltFetched)
512  *pceltFetched = 0;
513 
514  while (celt-- > 0)
515  {
516  HRESULT hr = EnumerateNext(rgelt);
517  if (hr != S_OK)
518  return hr;
519 
520  if (pceltFetched)
521  (*pceltFetched)++;
522  if (rgelt)
523  rgelt++;
524  }
525 
526  return S_OK;
527  }
HRESULT hr
Definition: shlfolder.c:183
LONG HRESULT
Definition: typedefs.h:78
HRESULT EnumerateNext(LPITEMIDLIST *ppidl)
Definition: ntobjenum.cpp:493
#define S_OK
Definition: intsafe.h:59

◆ NextKey()

HRESULT CEnumRegKey::NextKey ( LPITEMIDLIST ppidl)
inline

Definition at line 352 of file ntobjenum.cpp.

353  {
356 
357  WCHAR className[MAX_PATH];
358  DWORD cchClass = _countof(className);
359 
360  if (RegEnumKeyExW(m_hkey, m_idx++, name, &cchName, 0, className, &cchClass, NULL))
361  return S_FALSE;
362 
363  name[cchName] = 0;
364  className[cchClass] = 0;
365 
367 
368  DWORD entryBufferLength = FIELD_OFFSET(RegPidlEntry, entryName) + sizeof(WCHAR) + cchName * sizeof(WCHAR);
369 
370  if (cchClass > 0)
371  {
372  entryBufferLength += sizeof(WCHAR) + cchClass * sizeof(WCHAR);
373  }
374 
375  // allocate space for the terminator
376  entryBufferLength += FIELD_OFFSET(SHITEMID, abID);
377 
378  RegPidlEntry* entry = (RegPidlEntry*) CoTaskMemAlloc(entryBufferLength);
379  if (!entry)
380  return E_OUTOFMEMORY;
381 
382  memset(entry, 0, entryBufferLength);
383 
384  entry->cb = FIELD_OFFSET(RegPidlEntry, entryName);
385  entry->magic = REGISTRY_PIDL_MAGIC;
386  entry->entryType = otype;
387 
388  if (cchName > 0)
389  {
390  entry->entryNameLength = cchName * sizeof(WCHAR);
391  StringCbCopyNW(entry->entryName, entryBufferLength, name, entry->entryNameLength);
392  entry->cb += entry->entryNameLength + sizeof(WCHAR);
393  }
394  else
395  {
396  entry->entryNameLength = 0;
397  entry->entryName[0] = 0;
398  entry->cb += sizeof(WCHAR);
399  }
400 
401  if (cchClass)
402  {
403  PWSTR contentData = (PWSTR) ((PBYTE) entry + entry->cb);
404  DWORD remainingSpace = entryBufferLength - entry->cb;
405 
406  entry->contentsLength = cchClass * sizeof(WCHAR);
407  StringCbCopyNW(contentData, remainingSpace, className, entry->contentsLength);
408 
409  entry->cb += entry->contentsLength + sizeof(WCHAR);
410  }
411 
412  if (ppidl)
413  *ppidl = (LPITEMIDLIST) entry;
414  return S_OK;
415  }
STRSAFEAPI StringCbCopyNW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc, size_t cbToCopy)
Definition: strsafe.h:255
uint16_t * PWSTR
Definition: typedefs.h:55
#define REGISTRY_PIDL_MAGIC
Definition: ntobjenum.h:36
REG_ENTRY_TYPE
Definition: ntobjenum.h:60
_In_ PSID _Out_writes_to_opt_ cchName LPSTR _Inout_ LPDWORD cchName
Definition: winbase.h:2729
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define S_FALSE
Definition: winerror.h:2357
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
uint32_t entry
Definition: isohybrid.c:63
#define S_OK
Definition: intsafe.h:59
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
Definition: name.c:38
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2527
#define memset(x, y, z)
Definition: compat.h:39
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
BYTE * PBYTE
Definition: pedump.c:66
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426

◆ NextValue()

HRESULT CEnumRegKey::NextValue ( LPITEMIDLIST ppidl)
inline

Definition at line 417 of file ntobjenum.cpp.

418  {
421  DWORD type = 0;
422  DWORD dataSize = 0;
423 
424  if (RegEnumValueW(m_hkey, m_idx++, name, &cchName, 0, &type, NULL, &dataSize))
425  return S_FALSE;
426 
428 
429  DWORD entryBufferLength = FIELD_OFFSET(RegPidlEntry, entryName) + sizeof(WCHAR) + cchName * sizeof(WCHAR);
430 
431 #define MAX_EMBEDDED_DATA 32
432  BOOL copyData = dataSize <= MAX_EMBEDDED_DATA;
433  if (copyData)
434  {
435  entryBufferLength += dataSize + sizeof(WCHAR);
436 
438  }
439 
440  // allocate space for the terminator
441  entryBufferLength += FIELD_OFFSET(SHITEMID, abID);
442 
443  RegPidlEntry* entry = (RegPidlEntry*) CoTaskMemAlloc(entryBufferLength);
444  if (!entry)
445  return E_OUTOFMEMORY;
446 
447  memset(entry, 0, entryBufferLength);
448 
449  entry->cb = FIELD_OFFSET(RegPidlEntry, entryName);
450  entry->magic = REGISTRY_PIDL_MAGIC;
451  entry->entryType = otype;
452  entry->contentType = type;
453 
454  if (cchName > 0)
455  {
456  entry->entryNameLength = cchName * sizeof(WCHAR);
457  StringCbCopyNW(entry->entryName, entryBufferLength, name, entry->entryNameLength);
458  entry->cb += entry->entryNameLength + sizeof(WCHAR);
459  }
460  else
461  {
462  entry->entryNameLength = 0;
463  entry->entryName[0] = 0;
464  entry->cb += sizeof(WCHAR);
465  }
466 
467  if (copyData)
468  {
469  PBYTE contentData = (PBYTE) ((PBYTE) entry + entry->cb);
470 
471  entry->contentsLength = dataSize;
472 
473  // In case it's an unterminated string, RegGetValue will add the NULL termination
474  dataSize += sizeof(WCHAR);
475 
476  if (!RegQueryValueExW(m_hkey, name, NULL, NULL, contentData, &dataSize))
477  {
478  entry->cb += entry->contentsLength + sizeof(WCHAR);
479  }
480  else
481  {
482  entry->contentsLength = 0;
483  entry->cb += sizeof(WCHAR);
484  }
485 
486  }
487 
488  if (ppidl)
489  *ppidl = (LPITEMIDLIST) entry;
490  return S_OK;
491  }
STRSAFEAPI StringCbCopyNW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc, size_t cbToCopy)
Definition: strsafe.h:255
#define REGISTRY_PIDL_MAGIC
Definition: ntobjenum.h:36
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
REG_ENTRY_TYPE
Definition: ntobjenum.h:60
#define MAX_EMBEDDED_DATA
_In_ PSID _Out_writes_to_opt_ cchName LPSTR _Inout_ LPDWORD cchName
Definition: winbase.h:2729
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
unsigned int BOOL
Definition: ntddk_ex.h:94
#define S_FALSE
Definition: winerror.h:2357
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2853
smooth NULL
Definition: ftsmooth.c:416
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
uint32_t entry
Definition: isohybrid.c:63
#define S_OK
Definition: intsafe.h:59
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
GLenum GLsizei dataSize
Definition: glext.h:11123
Definition: name.c:38
#define memset(x, y, z)
Definition: compat.h:39
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
BYTE * PBYTE
Definition: pedump.c:66
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426

◆ Reset()

virtual HRESULT STDMETHODCALLTYPE CEnumRegKey::Reset ( void  )
inlinevirtual

Implements IEnumIDList.

Definition at line 543 of file ntobjenum.cpp.

544  {
545  return E_NOTIMPL;
546  }
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ Skip()

virtual HRESULT STDMETHODCALLTYPE CEnumRegKey::Skip ( ULONG  celt)
inlinevirtual

Implements IEnumIDList.

Definition at line 529 of file ntobjenum.cpp.

530  {
531  while (celt > 0)
532  {
534  if (FAILED(hr))
535  return hr;
536  if (hr != S_OK)
537  break;
538  }
539 
540  return S_OK;
541  }
HRESULT hr
Definition: shlfolder.c:183
smooth NULL
Definition: ftsmooth.c:416
LONG HRESULT
Definition: typedefs.h:78
HRESULT EnumerateNext(LPITEMIDLIST *ppidl)
Definition: ntobjenum.cpp:493
#define S_OK
Definition: intsafe.h:59

Member Data Documentation

◆ m_hkey

HKEY CEnumRegKey::m_hkey
private

Definition at line 315 of file ntobjenum.cpp.

◆ m_idx

int CEnumRegKey::m_idx
private

Definition at line 317 of file ntobjenum.cpp.

◆ m_path

PCWSTR CEnumRegKey::m_path
private

Definition at line 314 of file ntobjenum.cpp.

◆ m_values

BOOL CEnumRegKey::m_values
private

Definition at line 316 of file ntobjenum.cpp.


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