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.

142 lines
2.9 KiB

  1. /*
  2. * EnumCP.cxx
  3. *
  4. * CEnumConnectionPoints - class to implement IEnumConnectionPoints
  5. *
  6. * Copyright (C) 2001 Microsoft Corporation. All rights reserved.
  7. *
  8. */
  9. #include <wininetp.h>
  10. #include "EnumCP.hxx"
  11. CEnumConnectionPoints::CEnumConnectionPoints(IConnectionPoint* pCP, DWORD cCurPos)
  12. : m_ulRefCount(1), m_dwCurrentIndex(cCurPos), m_pCP(pCP)
  13. {
  14. INET_ASSERT(m_pCP);
  15. m_pCP->AddRef();
  16. }
  17. CEnumConnectionPoints::~CEnumConnectionPoints()
  18. {
  19. m_pCP->Release();
  20. }
  21. //
  22. // IUnknown QueryInterface
  23. //
  24. STDMETHODIMP CEnumConnectionPoints::QueryInterface(REFIID riid, void ** ppvObject)
  25. {
  26. HRESULT hr = NOERROR;
  27. if (ppvObject == NULL)
  28. {
  29. hr = E_INVALIDARG;
  30. }
  31. else if (riid == IID_IUnknown)
  32. {
  33. *ppvObject = static_cast<IUnknown*>(this);
  34. AddRef();
  35. }
  36. else if (riid == IID_IEnumConnectionPoints)
  37. {
  38. *ppvObject = static_cast<IEnumConnectionPoints*>(this);
  39. AddRef();
  40. }
  41. else
  42. hr = E_NOINTERFACE;
  43. return hr;
  44. }
  45. //
  46. // IUnknown AddRef
  47. //
  48. ULONG CEnumConnectionPoints::AddRef()
  49. {
  50. return ++m_ulRefCount;
  51. }
  52. //
  53. // IUnknown Release
  54. //
  55. ULONG CEnumConnectionPoints::Release()
  56. {
  57. if (--m_ulRefCount == 0)
  58. {
  59. delete this;
  60. return 0;
  61. }
  62. else
  63. return m_ulRefCount;
  64. }
  65. //
  66. // IEnumConnectionPoints Next
  67. //
  68. STDMETHODIMP CEnumConnectionPoints::Next(
  69. ULONG cConnections, //[in]Number of IConnectionPoint values
  70. // returned in rgpcn array
  71. IConnectionPoint **rgpcn, //[out]Array to receive enumerated connection
  72. // points
  73. ULONG *pcFetched //[out]Pointer to the actual number of
  74. // connection points returned in rgpcn array
  75. )
  76. {
  77. if (pcFetched == NULL && cConnections > 1)
  78. return E_POINTER;
  79. if (pcFetched)
  80. *pcFetched = 0;
  81. if (cConnections == 0)
  82. return S_OK;
  83. if (rgpcn == 0)
  84. return E_POINTER;
  85. if (m_dwCurrentIndex == 0)
  86. {
  87. m_dwCurrentIndex = 1;
  88. if (pcFetched)
  89. *pcFetched = 1;
  90. *rgpcn = m_pCP;
  91. m_pCP->AddRef();
  92. return (cConnections == 1) ? S_OK : S_FALSE;
  93. }
  94. else
  95. return S_FALSE;
  96. }
  97. //
  98. // IEnumConnectionPoints Skip
  99. //
  100. STDMETHODIMP CEnumConnectionPoints::Skip(ULONG cConnections)
  101. {
  102. m_dwCurrentIndex += cConnections;
  103. return (m_dwCurrentIndex <= 1) ? S_OK : S_FALSE;
  104. }
  105. //
  106. // IEnumConnectionPoints Reset
  107. //
  108. STDMETHODIMP CEnumConnectionPoints::Reset()
  109. {
  110. m_dwCurrentIndex = 0;
  111. return S_OK;
  112. }
  113. //
  114. // IEnumConnectionPoints Clone
  115. //
  116. STDMETHODIMP CEnumConnectionPoints::Clone(IEnumConnectionPoints** ppEnum)
  117. {
  118. if (ppEnum == NULL)
  119. return E_POINTER;
  120. *ppEnum = static_cast<IEnumConnectionPoints*>(new CEnumConnectionPoints(m_pCP, m_dwCurrentIndex));
  121. return (*ppEnum) ? S_OK : E_OUTOFMEMORY;
  122. }