Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // sdoattribute.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the class SdoAttribute.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 03/01/1999 Original version.
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include <stdafx.h>
  19. #include <memory>
  20. #include <attrdef.h>
  21. #include <sdoattribute.h>
  22. inline SdoAttribute::SdoAttribute(
  23. const AttributeDefinition* definition
  24. ) throw ()
  25. : def(definition), refCount(0)
  26. {
  27. def->AddRef();
  28. VariantInit(&value);
  29. }
  30. inline SdoAttribute::~SdoAttribute() throw ()
  31. {
  32. VariantClear(&value);
  33. def->Release();
  34. }
  35. HRESULT SdoAttribute::createInstance(
  36. const AttributeDefinition* definition,
  37. SdoAttribute** newAttr
  38. ) throw ()
  39. {
  40. // Check the arguments.
  41. if (definition == NULL || newAttr == NULL) { return E_INVALIDARG; }
  42. // Create a new SdoAttribute.
  43. *newAttr = new (std::nothrow) SdoAttribute(definition);
  44. if (!*newAttr) { return E_OUTOFMEMORY; }
  45. // Set the reference count to one.
  46. (*newAttr)->refCount = 1;
  47. return S_OK;
  48. }
  49. STDMETHODIMP_(ULONG) SdoAttribute::AddRef()
  50. {
  51. return InterlockedIncrement(&refCount);
  52. }
  53. STDMETHODIMP_(ULONG) SdoAttribute::Release()
  54. {
  55. ULONG l = InterlockedDecrement(&refCount);
  56. if (l == 0) { delete this; }
  57. return l;
  58. }
  59. STDMETHODIMP SdoAttribute::QueryInterface(REFIID iid, void ** ppvObject)
  60. {
  61. if (ppvObject == NULL) { return E_POINTER; }
  62. if (iid == __uuidof(ISdo) ||
  63. iid == __uuidof(IUnknown) ||
  64. iid == __uuidof(IDispatch))
  65. {
  66. *ppvObject = this;
  67. }
  68. else
  69. {
  70. return E_NOINTERFACE;
  71. }
  72. InterlockedIncrement(&refCount);
  73. return S_OK;
  74. }
  75. STDMETHODIMP SdoAttribute::GetPropertyInfo(LONG Id, IUnknown** ppPropertyInfo)
  76. { return E_NOTIMPL; }
  77. STDMETHODIMP SdoAttribute::GetProperty(LONG Id, VARIANT* pValue)
  78. {
  79. if (Id != PROPERTY_ATTRIBUTE_VALUE)
  80. {
  81. // Everything but the value comes from the attribute definition.
  82. return def->getProperty(Id, pValue);
  83. }
  84. if (pValue == NULL) { return E_INVALIDARG; }
  85. VariantInit(pValue);
  86. return VariantCopy(pValue, &value);
  87. }
  88. STDMETHODIMP SdoAttribute::PutProperty(LONG Id, VARIANT* pValue)
  89. {
  90. if (Id == PROPERTY_ATTRIBUTE_VALUE)
  91. {
  92. // Make a copy of the supplied value.
  93. VARIANT tmp;
  94. VariantInit(&tmp);
  95. HRESULT hr = VariantCopy(&tmp, pValue);
  96. if (SUCCEEDED(hr))
  97. {
  98. // Replace our current value with the new one.
  99. VariantClear(&value);
  100. value = tmp;
  101. }
  102. return hr;
  103. }
  104. // All other properties are read-only.
  105. return E_ACCESSDENIED;
  106. }
  107. STDMETHODIMP SdoAttribute::ResetProperty(LONG Id)
  108. { return S_OK; }
  109. STDMETHODIMP SdoAttribute::Apply()
  110. { return S_OK; }
  111. STDMETHODIMP SdoAttribute::Restore()
  112. { return S_OK; }
  113. STDMETHODIMP SdoAttribute::get__NewEnum(IUnknown** ppEnumVARIANT)
  114. { return E_NOTIMPL; }