ReactOS 0.4.15-dev-7677-g8209aa5
CRegPropertyBag Class Reference
Inheritance diagram for CRegPropertyBag:
Collaboration diagram for CRegPropertyBag:

Public Member Functions

 CRegPropertyBag (DWORD dwMode)
 
 ~CRegPropertyBag () override
 
HRESULT Init (HKEY hKey, LPCWSTR lpSubKey)
 
STDMETHODIMP Read (_In_z_ LPCWSTR pszPropName, _Inout_ VARIANT *pvari, _Inout_opt_ IErrorLog *pErrorLog) override
 
STDMETHODIMP Write (_In_z_ LPCWSTR pszPropName, _In_ VARIANT *pvari) override
 
- Public Member Functions inherited from CBasePropertyBag
 CBasePropertyBag (DWORD dwMode)
 
virtual ~CBasePropertyBag ()
 
STDMETHODIMP QueryInterface (REFIID riid, void **ppvObject) override
 
 STDMETHODIMP_ (ULONG) AddRef() override
 
 STDMETHODIMP_ (ULONG) Release() override
 
- Public Member Functions inherited from IPropertyBag
HRESULT Read ([in] LPCOLESTR pszPropName, [in, out] VARIANT *pVar, [in] IErrorLog *pErrorLog)
 
HRESULT RemoteRead ([in] LPCOLESTR pszPropName, [out] VARIANT *pVar, [in] IErrorLog *pErrorLog, [in] DWORD varType, [in] IUnknown *pUnkObj)
 
HRESULT Write ([in] LPCOLESTR pszPropName, [in] VARIANT *pVar)
 
- Public Member Functions inherited from IUnknown
HRESULT QueryInterface ([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
 
ULONG AddRef ()
 
ULONG Release ()
 

Protected Member Functions

HRESULT _ReadDword (LPCWSTR pszPropName, VARIANT *pvari)
 
HRESULT _ReadString (LPCWSTR pszPropName, VARIANTARG *pvarg, UINT len)
 
HRESULT _ReadBinary (LPCWSTR pszPropName, VARIANT *pvari, VARTYPE vt, DWORD uBytes)
 
HRESULT _ReadStream (VARIANT *pvari, BYTE *pInit, UINT cbInit)
 
HRESULT _CopyStreamIntoBuff (IStream *pStream, void *pv, ULONG cb)
 
HRESULT _GetStreamSize (IStream *pStream, LPDWORD pcbSize)
 
HRESULT _WriteStream (LPCWSTR pszPropName, IStream *pStream)
 

Protected Attributes

HKEY m_hKey
 
- Protected Attributes inherited from CBasePropertyBag
LONG m_cRefs
 
DWORD m_dwMode
 

Additional Inherited Members

- Public Types inherited from IPropertyBag
typedef IPropertyBagLPPROPERTYBAG
 
- Public Types inherited from IUnknown
typedef IUnknownLPUNKNOWN
 

Detailed Description

Definition at line 265 of file propbag.cpp.

Constructor & Destructor Documentation

◆ CRegPropertyBag()

CRegPropertyBag::CRegPropertyBag ( DWORD  dwMode)
inline

Definition at line 279 of file propbag.cpp.

280 : CBasePropertyBag(dwMode)
281 , m_hKey(NULL)
282 {
283 }
#define NULL
Definition: types.h:112

◆ ~CRegPropertyBag()

CRegPropertyBag::~CRegPropertyBag ( )
inlineoverride

Definition at line 285 of file propbag.cpp.

286 {
287 if (m_hKey)
289 }
#define RegCloseKey(hKey)
Definition: registry.h:49

Member Function Documentation

◆ _CopyStreamIntoBuff()

HRESULT CRegPropertyBag::_CopyStreamIntoBuff ( IStream pStream,
void pv,
ULONG  cb 
)
protected

Definition at line 386 of file propbag.cpp.

387{
389 li.QuadPart = 0;
390 HRESULT hr = pStream->Seek(li, 0, NULL);
391 if (FAILED(hr))
392 return hr;
393 return pStream->Read(pv, cb, NULL);
394}
LARGE_INTEGER li
Definition: fxtimerapi.cpp:235
HRESULT Read([out, size_is(cb), length_is(*pcbRead)] void *pv, [in] ULONG cb, [out] ULONG *pcbRead)
HRESULT Seek([in] LARGE_INTEGER dlibMove, [in] DWORD dwOrigin, [out] ULARGE_INTEGER *plibNewPosition)
#define FAILED(hr)
Definition: intsafe.h:51
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
HRESULT hr
Definition: shlfolder.c:183
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by _WriteStream().

◆ _GetStreamSize()

HRESULT CRegPropertyBag::_GetStreamSize ( IStream pStream,
LPDWORD  pcbSize 
)
protected

Definition at line 396 of file propbag.cpp.

397{
398 *pcbSize = 0;
399
401 HRESULT hr = IStream_Size(pStream, &ui);
402 if (FAILED(hr))
403 return hr;
404
405 if (ui.DUMMYSTRUCTNAME.HighPart)
406 return E_FAIL; /* 64-bit value is not supported */
407
408 *pcbSize = ui.DUMMYSTRUCTNAME.LowPart;
409 return hr;
410}
#define E_FAIL
Definition: ddrawi.h:102
HRESULT WINAPI IStream_Size(IStream *lpStream, ULARGE_INTEGER *lpulSize)
Definition: istream.c:661
UINT ui
Definition: oleauto.h:49

Referenced by _WriteStream().

◆ _ReadBinary()

HRESULT CRegPropertyBag::_ReadBinary ( LPCWSTR  pszPropName,
VARIANT pvari,
VARTYPE  vt,
DWORD  uBytes 
)
protected

Definition at line 361 of file propbag.cpp.

366{
367 HRESULT hr = E_FAIL;
368 if (vt != VT_UNKNOWN || uBytes < sizeof(GUID))
369 return hr;
370
372 if (!pbData)
373 return hr;
374
375 if (!SHGetValueW(m_hKey, NULL, pszPropName, NULL, pbData, &uBytes) &&
376 memcmp(&GUID_NULL, pbData, sizeof(GUID)) == 0)
377 {
378 hr = _ReadStream(pvari, pbData + sizeof(GUID), uBytes - sizeof(GUID));
379 }
380
382
383 return hr;
384}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
HRESULT _ReadStream(VARIANT *pvari, BYTE *pInit, UINT cbInit)
Definition: propbag.cpp:350
@ VT_UNKNOWN
Definition: compat.h:2308
static REFPROPVARIANT PROPVAR_CHANGE_FLAGS VARTYPE vt
Definition: suminfo.c:86
DWORD WINAPI SHGetValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue, LPDWORD pwType, LPVOID pvData, LPDWORD pcbData)
Definition: reg.c:1236
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define GUID_NULL
Definition: ks.h:106
unsigned char * LPBYTE
Definition: typedefs.h:53
#define LMEM_ZEROINIT
Definition: winbase.h:375
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201

Referenced by Read().

◆ _ReadDword()

HRESULT CRegPropertyBag::_ReadDword ( LPCWSTR  pszPropName,
VARIANT pvari 
)
protected

Definition at line 321 of file propbag.cpp.

322{
323 DWORD cbData = sizeof(DWORD);
324 LONG error = SHGetValueW(m_hKey, NULL, pszPropName, NULL, &V_UI4(pvari), &cbData);
325 if (error)
326 return E_FAIL;
327
328 V_VT(pvari) = VT_UI4;
329 return S_OK;
330}
@ VT_UI4
Definition: compat.h:2313
unsigned long DWORD
Definition: ntddk_ex.h:95
#define S_OK
Definition: intsafe.h:52
#define error(str)
Definition: mkdosfs.c:1605
#define DWORD
Definition: nt_native.h:44
#define V_VT(A)
Definition: oleauto.h:211
#define V_UI4(A)
Definition: oleauto.h:270
long LONG
Definition: pedump.c:60

Referenced by Read().

◆ _ReadStream()

HRESULT CRegPropertyBag::_ReadStream ( VARIANT pvari,
BYTE pInit,
UINT  cbInit 
)
protected

Definition at line 350 of file propbag.cpp.

351{
352 IStream *pStream = SHCreateMemStream(pInit, cbInit);
353 V_UNKNOWN(pvari) = pStream;
354 if (!pStream)
355 return E_OUTOFMEMORY;
356 V_VT(pvari) = VT_UNKNOWN;
357 return S_OK;
358}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
PWDFDEVICE_INIT pInit
#define V_UNKNOWN(A)
Definition: oleauto.h:281
IStream *WINAPI SHCreateMemStream(const BYTE *lpbData, UINT dwDataLen)
Definition: regstream.c:652

Referenced by _ReadBinary().

◆ _ReadString()

HRESULT CRegPropertyBag::_ReadString ( LPCWSTR  pszPropName,
VARIANTARG pvarg,
UINT  len 
)
protected

Definition at line 332 of file propbag.cpp.

333{
335 V_BSTR(pvarg) = bstr;
336 if (!bstr)
337 return E_OUTOFMEMORY;
338
339 V_VT(pvarg) = VT_BSTR;
340 LONG error = SHGetValueW(m_hKey, NULL, pszPropName, NULL, bstr, (LPDWORD)&len);
341 if (error)
342 {
343 ::VariantClear(pvarg);
344 return E_FAIL;
345 }
346
347 return S_OK;
348}
OLECHAR * BSTR
Definition: compat.h:2293
@ VT_BSTR
Definition: compat.h:2303
GLenum GLsizei len
Definition: glext.h:6722
BSTR WINAPI DECLSPEC_HOTPATCH SysAllocStringByteLen(LPCSTR str, UINT len)
Definition: oleaut.c:428
#define V_BSTR(A)
Definition: oleauto.h:226
uint32_t * LPDWORD
Definition: typedefs.h:59
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648

Referenced by Read().

◆ _WriteStream()

HRESULT CRegPropertyBag::_WriteStream ( LPCWSTR  pszPropName,
IStream pStream 
)
protected

Definition at line 464 of file propbag.cpp.

465{
466 DWORD cbData;
467 HRESULT hr = _GetStreamSize(pStream, &cbData);
468 if (FAILED(hr) || !cbData)
469 return hr;
470
471 DWORD cbBinary = cbData + sizeof(GUID);
473 if (!pbBinary)
474 return E_OUTOFMEMORY;
475
476 hr = _CopyStreamIntoBuff(pStream, pbBinary + sizeof(GUID), cbData);
477 if (SUCCEEDED(hr))
478 {
479 if (SHSetValueW(m_hKey, NULL, pszPropName, REG_BINARY, pbBinary, cbBinary))
480 hr = E_FAIL;
481 }
482
483 ::LocalFree(pbBinary);
484 return hr;
485}
HRESULT _CopyStreamIntoBuff(IStream *pStream, void *pv, ULONG cb)
Definition: propbag.cpp:386
HRESULT _GetStreamSize(IStream *pStream, LPDWORD pcbSize)
Definition: propbag.cpp:396
DWORD WINAPI SHSetValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue, DWORD dwType, LPCVOID pvData, DWORD cbData)
Definition: reg.c:1306
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define REG_BINARY
Definition: nt_native.h:1496
_In_ DWORD cbBinary
Definition: wincrypt.h:4503

Referenced by Write().

◆ Init()

HRESULT CRegPropertyBag::Init ( HKEY  hKey,
LPCWSTR  lpSubKey 
)

Definition at line 298 of file propbag.cpp.

299{
300 REGSAM nAccess = 0;
302 nAccess |= KEY_READ;
304 nAccess |= KEY_WRITE;
305
306 LONG error;
307 if (m_dwMode & STGM_CREATE)
308 error = ::RegCreateKeyExW(hKey, lpSubKey, 0, NULL, 0, nAccess, NULL, &m_hKey, NULL);
309 else
310 error = ::RegOpenKeyExW(hKey, lpSubKey, 0, nAccess, &m_hKey);
311
312 if (error != ERROR_SUCCESS)
313 {
314 ERR("%p %s 0x%08X\n", hKey, debugstr_w(lpSubKey), error);
316 }
317
318 return S_OK;
319}
#define ERR(fmt,...)
Definition: debug.h:110
#define ERROR_SUCCESS
Definition: deptool.c:10
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:3362
FxAutoRegKey hKey
#define debugstr_w
Definition: kernel32.h:32
#define KEY_READ
Definition: nt_native.h:1023
#define KEY_WRITE
Definition: nt_native.h:1031
#define STGM_CREATE
Definition: objbase.h:926
#define MODE_CAN_WRITE(dwMode)
Definition: propbag.cpp:24
#define MODE_CAN_READ(dwMode)
Definition: propbag.cpp:22
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
ACCESS_MASK REGSAM
Definition: winreg.h:69

◆ Read()

STDMETHODIMP CRegPropertyBag::Read ( _In_z_ LPCWSTR  pszPropName,
_Inout_ VARIANT pvari,
_Inout_opt_ IErrorLog pErrorLog 
)
override

Definition at line 413 of file propbag.cpp.

417{
418 UNREFERENCED_PARAMETER(pErrorLog);
419
420 TRACE("%p: %s %p %p\n", this, debugstr_w(pszPropName), pvari, pErrorLog);
421
423 {
424 ERR("%p: 0x%X\n", this, m_dwMode);
425 ::VariantInit(pvari);
426 return E_ACCESSDENIED;
427 }
428
429 VARTYPE vt = V_VT(pvari);
430 VariantInit(pvari);
431
432 HRESULT hr;
433 DWORD dwType, cbValue;
434 LONG error = SHGetValueW(m_hKey, NULL, pszPropName, &dwType, NULL, &cbValue);
435 if (error != ERROR_SUCCESS)
436 hr = E_FAIL;
437 else if (dwType == REG_SZ)
438 hr = _ReadString(pszPropName, pvari, cbValue);
439 else if (dwType == REG_BINARY)
440 hr = _ReadBinary(pszPropName, pvari, vt, cbValue);
441 else if (dwType == REG_DWORD)
442 hr = _ReadDword(pszPropName, pvari);
443 else
444 hr = E_FAIL;
445
446 if (FAILED(hr))
447 {
448 ERR("%p: 0x%08X %ld: %s %p\n", this, hr, dwType, debugstr_w(pszPropName), pvari);
449 ::VariantInit(pvari);
450 return hr;
451 }
452
453 hr = ::VariantChangeTypeForRead(pvari, vt);
454 if (FAILED(hr))
455 {
456 ERR("%p: 0x%08X %ld: %s %p\n", this, hr, dwType, debugstr_w(pszPropName), pvari);
457 ::VariantInit(pvari);
458 }
459
460 return hr;
461}
HRESULT _ReadDword(LPCWSTR pszPropName, VARIANT *pvari)
Definition: propbag.cpp:321
HRESULT _ReadBinary(LPCWSTR pszPropName, VARIANT *pvari, VARTYPE vt, DWORD uBytes)
Definition: propbag.cpp:361
HRESULT _ReadString(LPCWSTR pszPropName, VARIANTARG *pvarg, UINT len)
Definition: propbag.cpp:332
unsigned short VARTYPE
Definition: compat.h:2254
#define REG_SZ
Definition: layer.c:22
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define REG_DWORD
Definition: sdbapi.c:596
#define TRACE(s)
Definition: solgame.cpp:4
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:568
#define E_ACCESSDENIED
Definition: winerror.h:2849

◆ Write()

STDMETHODIMP CRegPropertyBag::Write ( _In_z_ LPCWSTR  pszPropName,
_In_ VARIANT pvari 
)
override

Definition at line 488 of file propbag.cpp.

489{
490 TRACE("%p: %s %p\n", this, debugstr_w(pszPropName), pvari);
491
493 {
494 ERR("%p: 0x%X\n", this, m_dwMode);
495 return E_ACCESSDENIED;
496 }
497
498 HRESULT hr;
499 LONG error;
500 VARIANTARG vargTemp = { 0 };
501 switch (V_VT(pvari))
502 {
503 case VT_EMPTY:
504 SHDeleteValueW(m_hKey, NULL, pszPropName);
505 hr = S_OK;
506 break;
507
508 case VT_BOOL:
509 case VT_I1:
510 case VT_I2:
511 case VT_I4:
512 case VT_UI1:
513 case VT_UI2:
514 case VT_UI4:
515 case VT_INT:
516 case VT_UINT:
517 {
518 hr = ::VariantChangeType(&vargTemp, pvari, 0, VT_UI4);
519 if (FAILED(hr))
520 return hr;
521
522 error = SHSetValueW(m_hKey, NULL, pszPropName, REG_DWORD, &V_UI4(&vargTemp), sizeof(DWORD));
523 if (error)
524 hr = E_FAIL;
525
526 ::VariantClear(&vargTemp);
527 break;
528 }
529
530 case VT_UNKNOWN:
531 {
532 CComPtr<IStream> pStream;
533 hr = V_UNKNOWN(pvari)->QueryInterface(IID_IStream, (void **)&pStream);
534 if (FAILED(hr))
535 return hr;
536
537 hr = _WriteStream(pszPropName, pStream);
538 break;
539 }
540
541 default:
542 {
543 hr = ::VariantChangeType(&vargTemp, pvari, 0, VT_BSTR);
544 if (FAILED(hr))
545 return hr;
546
547 int cch = lstrlenW(V_BSTR(&vargTemp));
548 DWORD cb = (cch + 1) * sizeof(WCHAR);
549 error = SHSetValueW(m_hKey, NULL, pszPropName, REG_SZ, V_BSTR(&vargTemp), cb);
550 if (error)
551 hr = E_FAIL;
552
553 ::VariantClear(&vargTemp);
554 break;
555 }
556 }
557
558 return hr;
559}
HRESULT _WriteStream(LPCWSTR pszPropName, IStream *pStream)
Definition: propbag.cpp:464
@ VT_INT
Definition: compat.h:2316
@ VT_UI2
Definition: compat.h:2312
@ VT_I1
Definition: compat.h:2310
@ VT_I4
Definition: compat.h:2298
@ VT_BOOL
Definition: compat.h:2306
@ VT_I2
Definition: compat.h:2297
@ VT_UINT
Definition: compat.h:2317
@ VT_EMPTY
Definition: compat.h:2295
@ VT_UI1
Definition: compat.h:2311
#define lstrlenW
Definition: compat.h:750
DWORD WINAPI SHDeleteValueW(HKEY hKey, LPCWSTR lpszSubKey, LPCWSTR lpszValue)
Definition: reg.c:1762
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
HRESULT WINAPI DECLSPEC_HOTPATCH VariantChangeType(VARIANTARG *pvargDest, VARIANTARG *pvargSrc, USHORT wFlags, VARTYPE vt)
Definition: variant.c:962
__wchar_t WCHAR
Definition: xmlstorage.h:180

Member Data Documentation

◆ m_hKey

HKEY CRegPropertyBag::m_hKey
protected

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