Source code of Windows XP (NT5)
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.

168 lines
4.1 KiB

  1. /*
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. */
  4. #include "sdppch.h"
  5. #include <afxdisp.h>
  6. #include <winerror.h>
  7. #include <oleauto.h>
  8. #include "sdpsadj.h"
  9. #include "sdptime.h"
  10. SDP_ADJUSTMENT_SAFEARRAY::SDP_ADJUSTMENT_SAFEARRAY(
  11. IN SDP_ADJUSTMENT &SdpAdjustment
  12. )
  13. : SDP_TIME_PERIOD_SAFEARRAY(SdpAdjustment.GetOffsets()),
  14. SDP_ULONG_SAFEARRAY(SdpAdjustment.GetAdjustmentTimes())
  15. {
  16. m_VarType[0] = VT_UI4;
  17. m_VarType[1] = VT_BOOL;
  18. m_VarType[2] = VT_I1;
  19. m_VarType[3] = VT_I4;
  20. m_VarType[4] = VT_I4;
  21. }
  22. HRESULT
  23. SDP_ADJUSTMENT_SAFEARRAY::GetSafeArray(
  24. OUT VARIANT *AdjustmentTimesVariant,
  25. OUT VARIANT *IsCompactVariant,
  26. OUT VARIANT *UnitVariant,
  27. OUT VARIANT *CompactValueVariant,
  28. OUT VARIANT *PeriodValueVariant
  29. )
  30. {
  31. ASSERT(SDP_ULONG_SAFEARRAY::m_TList.GetSize() == SDP_TIME_PERIOD_SAFEARRAY::m_TList.GetSize());
  32. VARIANT *VariantArray[] = {
  33. AdjustmentTimesVariant,
  34. IsCompactVariant, UnitVariant,
  35. CompactValueVariant, PeriodValueVariant
  36. };
  37. // SDP_ULONG_SAFEARRAY:: prefix merely resolves the GetSafeArrays method
  38. // the get and set methods are over-ridden to account for the adjustment as well as the other
  39. // time period elements
  40. return SDP_ULONG_SAFEARRAY::GetSafeArrays(
  41. (DWORD)SDP_ULONG_SAFEARRAY::m_TList.GetSize(),
  42. sizeof(VariantArray)/sizeof(VARIANT *),
  43. m_VarType,
  44. VariantArray
  45. );
  46. }
  47. BOOL
  48. SDP_ADJUSTMENT_SAFEARRAY::GetElement(
  49. IN ULONG Index,
  50. IN ULONG NumEntries,
  51. IN void **Element,
  52. OUT HRESULT &HResult
  53. )
  54. {
  55. ASSERT(5 == NumEntries);
  56. SDP_ULONG *AdjustmentTime = SDP_ULONG_SAFEARRAY::GetListMember(Index, HResult);
  57. if ( NULL == AdjustmentTime )
  58. {
  59. return FALSE;
  60. }
  61. SDP_TIME_PERIOD *Offset = SDP_TIME_PERIOD_SAFEARRAY::GetListMember(Index, HResult);
  62. if ( NULL == Offset )
  63. {
  64. return FALSE;
  65. }
  66. ASSERT(AdjustmentTime->IsValid());
  67. ASSERT(Offset->IsValid());
  68. if ( !SDP_ULONG_SAFEARRAY::Get(*AdjustmentTime, 1, Element, HResult) ||
  69. !SDP_TIME_PERIOD_SAFEARRAY::Get(*Offset, 4, &Element[1], HResult) )
  70. {
  71. return FALSE;
  72. }
  73. return TRUE;
  74. }
  75. BOOL
  76. SDP_ADJUSTMENT_SAFEARRAY::SetElement(
  77. IN ULONG Index,
  78. IN ULONG NumEntries,
  79. IN void ***Element,
  80. OUT HRESULT &HResult
  81. )
  82. {
  83. ASSERT(5 == NumEntries);
  84. SDP_ULONG *AdjustmentTime = SDP_ULONG_SAFEARRAY::CreateListMemberIfRequired(Index, HResult);
  85. if ( NULL == AdjustmentTime )
  86. {
  87. return FALSE;
  88. }
  89. SDP_TIME_PERIOD *Offset = SDP_TIME_PERIOD_SAFEARRAY::CreateListMemberIfRequired(Index, HResult);
  90. if ( NULL == Offset )
  91. {
  92. return FALSE;
  93. }
  94. VERIFY(SDP_ULONG_SAFEARRAY::Set(*AdjustmentTime, 1, Element, HResult));
  95. VERIFY(SDP_TIME_PERIOD_SAFEARRAY::Set(*Offset, 4, &Element[1], HResult));
  96. ASSERT(AdjustmentTime->IsValid());
  97. ASSERT(Offset->IsValid());
  98. // if its a newly created instance, make it valid and add it to the list at the appropriate
  99. // index
  100. ASSERT(SDP_ULONG_SAFEARRAY::m_TList.GetSize() == SDP_TIME_PERIOD_SAFEARRAY::m_TList.GetSize());
  101. if ( Index >= (ULONG)SDP_ULONG_SAFEARRAY::m_TList.GetSize() )
  102. {
  103. try
  104. {
  105. SDP_ULONG_SAFEARRAY::m_TList.SetAtGrow(Index, AdjustmentTime);
  106. }
  107. catch(...)
  108. {
  109. delete AdjustmentTime;
  110. delete Offset;
  111. SetLastError(ERROR_OUTOFMEMORY);
  112. return FALSE;
  113. }
  114. try
  115. {
  116. SDP_TIME_PERIOD_SAFEARRAY::m_TList.SetAtGrow(Index, Offset);
  117. }
  118. catch(...)
  119. {
  120. SDP_ULONG_SAFEARRAY::m_TList.RemoveAt(Index);
  121. delete AdjustmentTime;
  122. delete Offset;
  123. SetLastError(ERROR_OUTOFMEMORY);
  124. return FALSE;
  125. }
  126. }
  127. return TRUE;
  128. }
  129. void
  130. SDP_ADJUSTMENT_SAFEARRAY::RemoveExcessElements(
  131. IN ULONG StartIndex
  132. )
  133. {
  134. SDP_ULONG_SAFEARRAY::RemoveExcessElements(StartIndex);
  135. SDP_TIME_PERIOD_SAFEARRAY::RemoveExcessElements(StartIndex);
  136. }