CPropertyBag.cxx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #if defined(_WIN32_WCE)
  2. //
  3. // Copyright (c) Microsoft Corporation.  All rights reserved.
  4. //
  5. //
  6. // Use of this source code is subject to the terms of the Microsoft end-user
  7. // license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
  8. // If you did not accept the terms of the EULA, you are not authorized to use
  9. // this source code. For a copy of the EULA, please see the LICENSE.RTF on your
  10. // install media.
  11. //
  12. #include <windows.h>
  13. #include <Ocidl.h>
  14. #include <oleauto.h>
  15. #include "internals/wince/CPropertyBag.h"
  16. CPropertyBag::CPropertyBag() : _refCount(1), pVar(0)
  17. {
  18. }
  19. CPropertyBag::~CPropertyBag()
  20. {
  21. VAR_LIST *pTemp = pVar;
  22. HRESULT hr = S_OK;
  23. while(pTemp) {
  24. VAR_LIST *pDel = pTemp;
  25. VariantClear(&pTemp->var);
  26. SysFreeString(pTemp->pBSTRName);
  27. pTemp = pTemp->pNext;
  28. delete pDel;
  29. }
  30. }
  31. HRESULT STDMETHODCALLTYPE
  32. CPropertyBag::Read(LPCOLESTR pszPropName,
  33. VARIANT *_pVar,
  34. IErrorLog *pErrorLog)
  35. {
  36. VAR_LIST *pTemp = pVar;
  37. HRESULT hr = S_OK;
  38. while (pTemp) {
  39. if (0 == wcscmp(pszPropName, pTemp->pBSTRName)) {
  40. hr = VariantCopy(_pVar, &pTemp->var);
  41. break;
  42. }
  43. pTemp = pTemp->pNext;
  44. }
  45. return hr;
  46. }
  47. HRESULT STDMETHODCALLTYPE
  48. CPropertyBag::Write(LPCOLESTR pszPropName,
  49. VARIANT *_pVar)
  50. {
  51. HRESULT hr = S_OK;
  52. VAR_LIST *pTemp = new VAR_LIST();
  53. ASSERT(pTemp);
  54. if ( !pTemp ) {
  55. return E_OUTOFMEMORY;
  56. }
  57. VariantInit(&pTemp->var);
  58. pTemp->pBSTRName = SysAllocString(pszPropName);
  59. pTemp->pNext = pVar;
  60. pVar = pTemp;
  61. return VariantCopy(&pTemp->var, _pVar);
  62. }
  63. ULONG STDMETHODCALLTYPE
  64. CPropertyBag::AddRef()
  65. {
  66. return InterlockedIncrement((LONG *)&_refCount);
  67. }
  68. ULONG STDMETHODCALLTYPE
  69. CPropertyBag::Release()
  70. {
  71. ASSERT(_refCount != 0xFFFFFFFF);
  72. ULONG ret = InterlockedDecrement((LONG *)&_refCount);
  73. if (!ret) {
  74. delete this;
  75. }
  76. return ret;
  77. }
  78. HRESULT STDMETHODCALLTYPE
  79. CPropertyBag::QueryInterface(REFIID riid, void** ppv)
  80. {
  81. if (!ppv) {
  82. return E_POINTER;
  83. }
  84. if (riid == IID_IPropertyBag) {
  85. *ppv = static_cast<IPropertyBag*>(this);
  86. }
  87. else {
  88. return *ppv = 0, E_NOINTERFACE;
  89. }
  90. return AddRef(), S_OK;
  91. }
  92. #endif /* _WIN32_WCE */