ReactOS 0.4.17-dev-683-g0dafdc5
CRegistrySource Class Reference
Inheritance diagram for CRegistrySource:
Collaboration diagram for CRegistrySource:

Public Member Functions

virtual ~CRegistrySource ()
 
HRESULT Init (HKEY hKey, PCWSTR pszSubKey, BOOL bCreate)
 
STDMETHODIMP QueryInterface (REFIID riid, void **ppvObject) override
 
 STDMETHODIMP_ (ULONG) AddRef() override
 
 STDMETHODIMP_ (ULONG) Release() override
 
STDMETHODIMP EnumValues (IEnumString **ppEnum) override
 
STDMETHODIMP EnumSources (IEnumString **ppEnum) override
 
STDMETHODIMP QueryValueString (PCWSTR keyName, PCWSTR valueName, PWSTR *ppszValue) override
 
STDMETHODIMP QueryValueDword (PCWSTR keyName, PCWSTR valueName, DWORD *pdwValue) override
 
STDMETHODIMP QueryValueExists (PCWSTR keyName, PCWSTR valueName) override
 
STDMETHODIMP QueryValueDirect (PCWSTR keyName, PCWSTR valueName, FLAGGED_BYTE_BLOB **ppBlob) override
 
STDMETHODIMP OpenSource (PCWSTR keyName, BOOL bCreate, IQuerySourceOld **ppSource) override
 
STDMETHODIMP SetValueDirect (PCWSTR keyName, PCWSTR valueName, DWORD dwType, DWORD cbData, LPCVOID pvData) override
 
STDMETHOD() QueryValueGuid (PCWSTR keyName, PCWSTR valueName, GUID *guid) override
 
STDMETHOD() OpenSource (PCWSTR keyName, IQuerySource **ppSource) override
 
STDMETHODIMP SetKey (HKEY hKey) override
 
STDMETHODIMP GetKey (HKEY *phKey) override
 
STDMETHODIMP GetKey (REGSAM samDesired, HKEY *phKey) override
 

Static Private Member Functions

template<WORD Ver>
static bool ExposeFeature ()
 

Private Attributes

LONG m_cRefs = 1
 
HKEY m_hKey = NULL
 

Detailed Description

Definition at line 94 of file querysrc.cpp.

Constructor & Destructor Documentation

◆ ~CRegistrySource()

CRegistrySource::~CRegistrySource ( )
virtual

Definition at line 280 of file querysrc.cpp.

281{
282 if (m_hKey)
284}
#define RegCloseKey(hKey)
Definition: registry.h:49

Member Function Documentation

◆ EnumSources()

STDMETHODIMP CRegistrySource::EnumSources ( IEnumString **  ppEnum)
override

Definition at line 375 of file querysrc.cpp.

376{
377 CRegistryEnumKeys* pEnum = new(std::nothrow) CRegistryEnumKeys();
378 if (!pEnum)
379 return E_OUTOFMEMORY;
380 HRESULT hr = pEnum->Init(m_hKey, this);
381 if (FAILED(hr))
382 {
383 pEnum->Release();
384 pEnum = NULL;
385 }
386 *ppEnum = pEnum;
387 return pEnum ? S_OK : E_OUTOFMEMORY;
388}
HRESULT Init(HKEY hKey, CRegistrySource *pSource)
Definition: querysrc.cpp:159
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
ULONG Release()
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51

◆ EnumValues()

STDMETHODIMP CRegistrySource::EnumValues ( IEnumString **  ppEnum)
override

Definition at line 360 of file querysrc.cpp.

361{
362 CRegistryEnumValues* pEnum = new(std::nothrow) CRegistryEnumValues();
363 if (!pEnum)
364 return E_OUTOFMEMORY;
365 HRESULT hr = pEnum->Init(m_hKey, this);
366 if (FAILED(hr))
367 {
368 pEnum->Release();
369 pEnum = NULL;
370 }
371 *ppEnum = pEnum;
372 return pEnum ? S_OK : E_OUTOFMEMORY;
373}

◆ ExposeFeature()

template<WORD Ver>
static bool CRegistrySource::ExposeFeature ( )
inlinestaticprivate

Definition at line 101 of file querysrc.cpp.

102 {
104 return true;
106 return true;
107
110 if (Ver >= _WIN32_WINNT_VISTA)
111 return W32Nt >= _WIN32_WINNT_VISTA;
112#if 0
113 if (Ver < _WIN32_WINNT_VISTA)
114 return W32Nt < _WIN32_WINNT_VISTA;
115 return false;
116#else
117 return Ver < _WIN32_WINNT_VISTA; // FIXME: The apitest currently only uses the NT5 interface
118#endif
119 }
DWORD WINAPI GetVersion(void)
Definition: version.c:1458
#define SHELL32_CAssocElement_Version
Definition: evalcmd.h:23
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLenum GLsizei GLsizei GLint GLint GLboolean packed
Definition: glext.h:9271
#define LOBYTE(W)
Definition: jmemdos.c:487
#define HIBYTE(W)
Definition: jmemdos.c:486
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
#define MAKEWORD(a, b)
Definition: typedefs.h:248

◆ GetKey() [1/2]

STDMETHODIMP CRegistrySource::GetKey ( HKEY phKey)
override

Definition at line 549 of file querysrc.cpp.

550{
551 if (!m_hKey)
552 return E_UNEXPECTED;
553
554 *phKey = SHRegDuplicateHKey(m_hKey);
555 if (!*phKey)
556 return E_UNEXPECTED;
557
558 return S_OK;
559}
HKEY WINAPI SHRegDuplicateHKey(HKEY hKey)
Definition: main.c:1828
#define E_UNEXPECTED
Definition: winerror.h:3528

◆ GetKey() [2/2]

STDMETHODIMP CRegistrySource::GetKey ( REGSAM  samDesired,
HKEY phKey 
)
override

Definition at line 561 of file querysrc.cpp.

562{
563 if (!m_hKey || !*phKey)
564 return E_UNEXPECTED;
565
566 LONG err = RegOpenKeyExW(m_hKey, NULL, 0, samDesired, phKey);
567 return HRESULT_FROM_WIN32(err);
568}
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
long LONG
Definition: pedump.c:60
#define err(...)
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210

◆ Init()

HRESULT CRegistrySource::Init ( HKEY  hKey,
PCWSTR  pszSubKey,
BOOL  bCreate 
)

Definition at line 286 of file querysrc.cpp.

287{
289 if (bCreate)
291 else
293
295}
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
FxAutoRegKey hKey
#define error(str)
Definition: mkdosfs.c:1605
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
_In_opt_ LPCSTR pszSubKey
Definition: shlwapi.h:783
_In_ int _In_ BOOL bCreate
Definition: shlobj.h:1536

Referenced by QuerySourceCreateFromKey().

◆ OpenSource() [1/2]

STDMETHODIMP CRegistrySource::OpenSource ( PCWSTR  keyName,
BOOL  bCreate,
IQuerySourceOld **  ppSource 
)
override

Definition at line 517 of file querysrc.cpp.

518{
519 return QuerySourceCreateFromKey(m_hKey, keyName, bCreate, IID_IQuerySourceOld, (PVOID*)ppSource);
520}
EXTERN_C HRESULT WINAPI QuerySourceCreateFromKey(_In_ HKEY hKey, _In_opt_ PCWSTR lpSubKey, _In_ BOOL bCreate, _In_ REFIID riid, _Outptr_ PVOID *ppv)
Definition: querysrc.cpp:577

◆ OpenSource() [2/2]

STDMETHODIMP CRegistrySource::OpenSource ( PCWSTR  keyName,
IQuerySource **  ppSource 
)
override

Definition at line 522 of file querysrc.cpp.

523{
524 return QuerySourceCreateFromKey(m_hKey, keyName, TRUE, IID_IQuerySource, (PVOID*)ppSource);
525}
#define TRUE
Definition: types.h:120

◆ QueryInterface()

STDMETHODIMP CRegistrySource::QueryInterface ( REFIID  riid,
void **  ppvObject 
)
override

Definition at line 297 of file querysrc.cpp.

298{
299 if (!ppvObject)
300 return E_POINTER;
301
302 if (riid == IID_IUnknown)
303 {
304 *ppvObject = static_cast<IQuerySourceOld*>(this);
305 AddRef();
306 return S_OK;
307 }
308
309 if (ExposeFeature<_WIN32_WINNT_WINXP>())
310 {
311 if (riid == IID_IQuerySourceOld)
312 {
313 *ppvObject = static_cast<IQuerySourceOld*>(this);
314 AddRef();
315 return S_OK;
316 }
317
318 if (riid == IID_IObjectWithRegistryKeyOld)
319 {
320 *ppvObject = static_cast<IObjectWithRegistryKeyOld*>(this);
321 AddRef();
322 return S_OK;
323 }
324 }
325
326 if (ExposeFeature<_WIN32_WINNT_VISTA>())
327 {
328 if (riid == IID_IQuerySource)
329 {
330 *ppvObject = static_cast<IQuerySource*>(this);
331 AddRef();
332 return S_OK;
333 }
334
335 if (riid == IID_IObjectWithRegistryKey)
336 {
337 *ppvObject = static_cast<IObjectWithRegistryKey*>(this);
338 AddRef();
339 return S_OK;
340 }
341 }
342
343 *ppvObject = NULL;
344 return E_NOINTERFACE;
345}
const GUID IID_IUnknown
REFIID riid
Definition: atlbase.h:39
static ULONG WINAPI AddRef(IStream *iface)
Definition: clist.c:83
#define E_NOINTERFACE
Definition: winerror.h:3479
#define E_POINTER
Definition: winerror.h:3480

Referenced by QuerySourceCreateFromKey().

◆ QueryValueDirect()

STDMETHODIMP CRegistrySource::QueryValueDirect ( PCWSTR  keyName,
PCWSTR  valueName,
FLAGGED_BYTE_BLOB **  ppBlob 
)
override

Definition at line 465 of file querysrc.cpp.

469{
470 HRESULT hr = E_FAIL;
471 HKEY hKey = m_hKey;
472 DWORD dwType = REG_NONE;
473 DWORD cbData = 256;
474 BYTE abData[256];
475
476 *ppBlob = NULL;
477
478 if (keyName && *keyName &&
480 {
481 return E_FAIL;
482 }
483
484 LSTATUS error = RegQueryValueExW(hKey, valueName, NULL, &dwType, abData, &cbData);
485 if (error == ERROR_SUCCESS)
486 {
487 hr = SHAllocBlob(cbData, abData, ppBlob);
488 }
489 else if (error == ERROR_MORE_DATA)
490 {
491 hr = SHAllocBlob(cbData, NULL, ppBlob);
492 if (SUCCEEDED(hr))
493 {
494 error = RegQueryValueExW(hKey, valueName, NULL, &dwType, (*ppBlob)->abData, &cbData);
495 if (error != ERROR_SUCCESS)
496 {
497 CoTaskMemFree(*ppBlob);
498 *ppBlob = NULL;
500 }
501 }
502 }
503 else
504 {
506 }
507
508 if (hKey != m_hKey)
510
511 if (SUCCEEDED(hr))
512 (*ppBlob)->fFlags = dwType;
513
514 return hr;
515}
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define E_FAIL
Definition: ddrawi.h:102
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
void WINAPI CoTaskMemFree(void *ptr)
Definition: malloc.c:389
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define KEY_READ
Definition: nt_native.h:1026
#define REG_NONE
Definition: nt_native.h:1495
_In_opt_ _In_opt_ _In_ _In_ DWORD cbData
Definition: shlwapi.h:761
static HRESULT SHAllocBlob(ULONG cbData, const BYTE *pbData, FLAGGED_BYTE_BLOB **ppBlob)
Definition: querysrc.cpp:20
unsigned char BYTE
Definition: xxhash.c:193

◆ QueryValueDword()

STDMETHODIMP CRegistrySource::QueryValueDword ( PCWSTR  keyName,
PCWSTR  valueName,
DWORD pdwValue 
)
override

Definition at line 435 of file querysrc.cpp.

436{
437 DWORD dwType, cbValue = sizeof(*pdwValue);
438 LSTATUS error = SHGetValueW(m_hKey, keyName, valueName, &dwType, pdwValue, &cbValue);
439 if (error)
441 if (dwType != REG_DWORD)
442 return E_DATATYPE_MISMATCH;
443 return S_OK;
444}
DWORD WINAPI SHGetValueW(HKEY hkey, const WCHAR *subkey, const WCHAR *value, DWORD *type, void *data, DWORD *data_len)
Definition: main.c:2222
#define REG_DWORD
Definition: sdbapi.c:615
#define E_DATATYPE_MISMATCH

◆ QueryValueExists()

STDMETHODIMP CRegistrySource::QueryValueExists ( PCWSTR  keyName,
PCWSTR  valueName 
)
override

Definition at line 457 of file querysrc.cpp.

458{
459 LSTATUS error = SHGetValueW(m_hKey, keyName, valueName, NULL, NULL, NULL);
460 if (error)
462 return S_OK;
463}

◆ QueryValueGuid()

STDMETHODIMP CRegistrySource::QueryValueGuid ( PCWSTR  keyName,
PCWSTR  valueName,
GUID guid 
)
override

Definition at line 446 of file querysrc.cpp.

447{
448 PWSTR str;
449 HRESULT hr = QueryValueString(keyName, valueName, &str);
450 if (FAILED(hr))
451 return hr;
454 return hr;
455}
STDMETHODIMP QueryValueString(PCWSTR keyName, PCWSTR valueName, PWSTR *ppszValue) override
Definition: querysrc.cpp:390
#define E_INVALIDARG
Definition: ddrawi.h:101
GUID guid
Definition: version.c:147
EXTERN_C BOOL WINAPI GUIDFromStringW(LPCWSTR idstr, CLSID *id)
Definition: ordinal.c:2542
const WCHAR * str
uint16_t * PWSTR
Definition: typedefs.h:56

◆ QueryValueString()

STDMETHODIMP CRegistrySource::QueryValueString ( PCWSTR  keyName,
PCWSTR  valueName,
PWSTR ppszValue 
)
override

Definition at line 390 of file querysrc.cpp.

394{
395 *ppszValue = NULL;
396
397 WCHAR szData[128];
398 DWORD dwType = REG_NONE, cbData = sizeof(szData);
399 LSTATUS error = SHGetValueW(m_hKey, keyName, valueName, &dwType, szData, &cbData);
400 if (error == ERROR_SUCCESS)
401 {
402 if (dwType != REG_SZ)
403 return E_DATATYPE_MISMATCH;
404 if (!valueName && !szData[0])
406 return SHStrDupW(szData, ppszValue);
407 }
408
409 if (error != ERROR_MORE_DATA)
411
412 *ppszValue = (PWSTR)CoTaskMemAlloc(cbData);
413 if (!*ppszValue)
414 return E_OUTOFMEMORY;
415
416 HRESULT hr = S_OK;
417 error = SHGetValueW(m_hKey, keyName, valueName, &dwType, *ppszValue, &cbData);
418 if (error)
419 {
420 CoTaskMemFree(*ppszValue);
421 *ppszValue = NULL;
423 }
424
425 if (SUCCEEDED(hr) && dwType != REG_SZ)
426 {
427 CoTaskMemFree(*ppszValue);
428 *ppszValue = NULL;
430 }
431
432 return hr;
433}
void *WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: malloc.c:381
HRESULT WINAPI SHStrDupW(const WCHAR *src, WCHAR **dest)
Definition: main.c:1692
#define REG_SZ
Definition: layer.c:22
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
short WCHAR
Definition: pedump.c:58

Referenced by QueryValueGuid().

◆ SetKey()

STDMETHODIMP CRegistrySource::SetKey ( HKEY  hKey)
override

Definition at line 540 of file querysrc.cpp.

541{
542 if (m_hKey)
543 return E_UNEXPECTED;
544
546 return m_hKey ? S_OK : E_UNEXPECTED;
547}

◆ SetValueDirect()

STDMETHODIMP CRegistrySource::SetValueDirect ( PCWSTR  keyName,
PCWSTR  valueName,
DWORD  dwType,
DWORD  cbData,
LPCVOID  pvData 
)
override

Definition at line 527 of file querysrc.cpp.

533{
534 LSTATUS error = SHSetValueW(m_hKey, keyName, valueName, dwType, pvData, cbData);
535 if (error)
537 return S_OK;
538}
DWORD WINAPI SHSetValueW(HKEY hkey, const WCHAR *subkey, const WCHAR *value, DWORD type, const void *data, DWORD data_len)
Definition: main.c:2292
_In_ LPWSTR _In_ DWORD _In_ LPCVOID pvData
Definition: netsh.h:116

◆ STDMETHODIMP_() [1/2]

CRegistrySource::STDMETHODIMP_ ( ULONG  )
override

◆ STDMETHODIMP_() [2/2]

CRegistrySource::STDMETHODIMP_ ( ULONG  )
override

Member Data Documentation

◆ m_cRefs

LONG CRegistrySource::m_cRefs = 1
private

Definition at line 98 of file querysrc.cpp.

◆ m_hKey


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