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.

95 lines
2.4 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // dsproperty.h
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file defines the class DSProperty.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 04/13/2000 Original version.
  16. // 04/13/2000 Port to ATL 3.0
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <ias.h>
  20. #include <iasutil.h>
  21. #include <dsproperty.h>
  22. #include <varvec.h>
  23. #include <memory>
  24. DSProperty* DSProperty::createInstance(
  25. const _bstr_t& propName,
  26. const _variant_t& propValue,
  27. IDataStoreObject* memberOf
  28. )
  29. {
  30. // Create a new CComObject.
  31. CComObject<DSProperty>* newObj;
  32. _com_util::CheckError(CComObject<DSProperty>::CreateInstance(&newObj));
  33. // Cast to a DBObject and store it in an auto_ptr in case we throw an
  34. // exception.
  35. std::auto_ptr<DSProperty> prop(newObj);
  36. // Set the members.
  37. prop->name = propName;
  38. prop->value = propValue;
  39. prop->owner = memberOf;
  40. // Release and return.
  41. return prop.release();
  42. }
  43. STDMETHODIMP DSProperty::get_Name(BSTR* pVal)
  44. {
  45. if (pVal == NULL) { return E_INVALIDARG; }
  46. *pVal = SysAllocString(name);
  47. return *pVal ? S_OK : E_OUTOFMEMORY;
  48. }
  49. STDMETHODIMP DSProperty::get_Value(VARIANT* pVal)
  50. {
  51. if (pVal == NULL) { return E_INVALIDARG; }
  52. return VariantCopy(pVal, &value);
  53. }
  54. STDMETHODIMP DSProperty::get_ValueEx(VARIANT* pVal)
  55. {
  56. if (pVal == NULL) { return E_INVALIDARG; }
  57. // Is the value an array ?
  58. if (V_VT(&value) != (VT_VARIANT | VT_ARRAY))
  59. {
  60. // No, so we have to convert it to one.
  61. try
  62. {
  63. // Make sure we can sucessfully copy the VARIANT, ...
  64. _variant_t tmp(value);
  65. // ... then allocate a SAFEARRAY with a single element.
  66. CVariantVector<VARIANT> multi(pVal, 1);
  67. // Load the single value in.
  68. multi[0] = tmp.Detach();
  69. }
  70. CATCH_AND_RETURN()
  71. return S_OK;
  72. }
  73. return VariantCopy(pVal, &value);
  74. }
  75. STDMETHODIMP DSProperty::get_Owner(IDataStoreObject** pVal)
  76. {
  77. if (pVal == NULL) { return E_INVALIDARG; }
  78. if (*pVal = owner) { (*pVal)->AddRef(); }
  79. return S_OK;
  80. }