ReactOS 0.4.17-dev-357-ga8f14ff
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
 
STDMETHODIMP SetKey (HKEY hKey) override
 
STDMETHODIMP GetKey (HKEY *phKey) override
 

Private Attributes

LONG m_cRefs = 1
 
HKEY m_hKey = NULL
 

Detailed Description

Definition at line 91 of file querysrc.cpp.

Constructor & Destructor Documentation

◆ ~CRegistrySource()

CRegistrySource::~CRegistrySource ( )
virtual

Definition at line 254 of file querysrc.cpp.

255{
256 if (m_hKey)
258}
#define RegCloseKey(hKey)
Definition: registry.h:49

Member Function Documentation

◆ EnumSources()

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

Definition at line 322 of file querysrc.cpp.

323{
324 CRegistryEnumKeys* pEnum = new(std::nothrow) CRegistryEnumKeys();
325 if (!pEnum)
326 return E_OUTOFMEMORY;
327 HRESULT hr = pEnum->Init(m_hKey, this);
328 if (FAILED(hr))
329 {
330 pEnum->Release();
331 pEnum = NULL;
332 }
333 *ppEnum = pEnum;
334 return pEnum ? S_OK : E_OUTOFMEMORY;
335}
HRESULT Init(HKEY hKey, CRegistrySource *pSource)
Definition: querysrc.cpp:133
#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 307 of file querysrc.cpp.

308{
309 CRegistryEnumValues* pEnum = new(std::nothrow) CRegistryEnumValues();
310 if (!pEnum)
311 return E_OUTOFMEMORY;
312 HRESULT hr = pEnum->Init(m_hKey, this);
313 if (FAILED(hr))
314 {
315 pEnum->Release();
316 pEnum = NULL;
317 }
318 *ppEnum = pEnum;
319 return pEnum ? S_OK : E_OUTOFMEMORY;
320}

◆ GetKey()

STDMETHODIMP CRegistrySource::GetKey ( HKEY phKey)
override

Definition at line 480 of file querysrc.cpp.

481{
482 if (!m_hKey)
483 return E_UNEXPECTED;
484
485 *phKey = SHRegDuplicateHKey(m_hKey);
486 if (!*phKey)
487 return E_UNEXPECTED;
488
489 return S_OK;
490}
HKEY WINAPI SHRegDuplicateHKey(HKEY hKey)
Definition: main.c:1828
#define E_UNEXPECTED
Definition: winerror.h:3528

◆ Init()

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

Definition at line 260 of file querysrc.cpp.

261{
263 if (bCreate)
265 else
267
269}
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
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
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:1527
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210

Referenced by QuerySourceCreateFromKey().

◆ OpenSource()

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

Definition at line 453 of file querysrc.cpp.

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

◆ QueryInterface()

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

Definition at line 271 of file querysrc.cpp.

272{
273 if (!ppvObject)
274 return E_POINTER;
275
276 if (riid == IID_IQuerySourceOld)
277 {
278 *ppvObject = static_cast<IQuerySourceOld*>(this);
279 AddRef();
280 return S_OK;
281 }
282
283 if (riid == IID_IObjectWithRegistryKeyOld)
284 {
285 *ppvObject = static_cast<IObjectWithRegistryKeyOld*>(this);
286 AddRef();
287 return S_OK;
288 }
289
290 *ppvObject = NULL;
291 return E_NOINTERFACE;
292}
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 401 of file querysrc.cpp.

405{
406 HRESULT hr = E_FAIL;
407 HKEY hKey = m_hKey;
408 DWORD dwType = REG_NONE;
409 DWORD cbData = 256;
410 BYTE abData[256];
411
412 *ppBlob = NULL;
413
414 if (keyName && *keyName &&
416 {
417 return E_FAIL;
418 }
419
420 LSTATUS error = RegQueryValueExW(hKey, valueName, NULL, &dwType, abData, &cbData);
421 if (error == ERROR_SUCCESS)
422 {
423 hr = SHAllocBlob(cbData, abData, ppBlob);
424 }
425 else if (error == ERROR_MORE_DATA)
426 {
427 hr = SHAllocBlob(cbData, NULL, ppBlob);
428 if (SUCCEEDED(hr))
429 {
430 error = RegQueryValueExW(hKey, valueName, NULL, &dwType, (*ppBlob)->abData, &cbData);
431 if (error != ERROR_SUCCESS)
432 {
433 CoTaskMemFree(*ppBlob);
434 *ppBlob = NULL;
436 }
437 }
438 }
439 else
440 {
442 }
443
444 if (hKey != m_hKey)
446
447 if (SUCCEEDED(hr))
448 (*ppBlob)->fFlags = dwType;
449
450 return hr;
451}
#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
unsigned long DWORD
Definition: ntddk_ex.h:95
#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:17
unsigned char BYTE
Definition: xxhash.c:193

◆ QueryValueDword()

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

Definition at line 382 of file querysrc.cpp.

383{
384 DWORD dwType, cbValue = sizeof(*pdwValue);
385 LSTATUS error = SHGetValueW(m_hKey, keyName, valueName, &dwType, pdwValue, &cbValue);
386 if (error)
388 if (dwType != REG_DWORD)
389 return E_DATATYPE_MISMATCH;
390 return S_OK;
391}
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 393 of file querysrc.cpp.

394{
395 LSTATUS error = SHGetValueW(m_hKey, keyName, valueName, NULL, NULL, NULL);
396 if (error)
398 return S_OK;
399}

◆ QueryValueString()

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

Definition at line 337 of file querysrc.cpp.

341{
342 *ppszValue = NULL;
343
344 WCHAR szData[128];
345 DWORD dwType = REG_NONE, cbData = sizeof(szData);
346 LSTATUS error = SHGetValueW(m_hKey, keyName, valueName, &dwType, szData, &cbData);
347 if (error == ERROR_SUCCESS)
348 {
349 if (dwType != REG_SZ)
350 return E_DATATYPE_MISMATCH;
351 if (!valueName && !szData[0])
353 return SHStrDupW(szData, ppszValue);
354 }
355
356 if (error != ERROR_MORE_DATA)
358
359 *ppszValue = (PWSTR)CoTaskMemAlloc(cbData);
360 if (!*ppszValue)
361 return E_OUTOFMEMORY;
362
363 HRESULT hr = S_OK;
364 error = SHGetValueW(m_hKey, keyName, valueName, &dwType, *ppszValue, &cbData);
365 if (error)
366 {
367 CoTaskMemFree(*ppszValue);
368 *ppszValue = NULL;
370 }
371
372 if (SUCCEEDED(hr) && dwType != REG_SZ)
373 {
374 CoTaskMemFree(*ppszValue);
375 *ppszValue = NULL;
377 }
378
379 return hr;
380}
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
uint16_t * PWSTR
Definition: typedefs.h:56

◆ SetKey()

STDMETHODIMP CRegistrySource::SetKey ( HKEY  hKey)
override

Definition at line 471 of file querysrc.cpp.

472{
473 if (m_hKey)
474 return E_UNEXPECTED;
475
477 return m_hKey ? S_OK : E_UNEXPECTED;
478}

◆ SetValueDirect()

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

Definition at line 458 of file querysrc.cpp.

464{
465 LSTATUS error = SHSetValueW(m_hKey, keyName, valueName, dwType, pvData, cbData);
466 if (error)
468 return S_OK;
469}
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 95 of file querysrc.cpp.

◆ m_hKey


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