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.

189 lines
4.1 KiB

  1. ///////////////////////////////////////////////////////////
  2. //
  3. // CConnectionPoint
  4. //
  5. // Defines the connection point object used by CTangramModel.
  6. //
  7. //
  8. #include <windows.h>
  9. #include <olectl.h>
  10. #include <assert.h>
  11. #include "CntPoint.h"
  12. //#include "EnumCon.h"
  13. ///////////////////////////////////////////////////////////
  14. //
  15. // Construction
  16. CConnectionPoint::CConnectionPoint(IConnectionPointContainer* pIConnectionPointContainer, const IID* piid)
  17. : m_dwNextCookie(0)
  18. {
  19. assert(piid != NULL) ;
  20. assert(pIConnectionPointContainer != NULL) ;
  21. m_pIConnectionPointContainer = pIConnectionPointContainer ; // AddRef is not needed.
  22. m_piid = piid ;
  23. }
  24. ///////////////////////////////////////////////////////////
  25. //
  26. // Destruction
  27. CConnectionPoint::~CConnectionPoint()
  28. {
  29. // The array should be empty before this is called.
  30. }
  31. ///////////////////////////////////////////////////////////
  32. //
  33. // Interface IUnknown Methods
  34. //
  35. ///////////////////////////////////////////////////////////
  36. //
  37. // QueryInterface
  38. //
  39. HRESULT __stdcall
  40. CConnectionPoint::QueryInterface(const IID& iid, void** ppv)
  41. {
  42. if ((iid == IID_IUnknown) ||(iid == IID_IConnectionPoint))
  43. {
  44. *ppv = static_cast<IConnectionPoint*>(this) ;
  45. }
  46. else
  47. {
  48. *ppv = NULL;
  49. return E_NOINTERFACE;
  50. }
  51. (reinterpret_cast<IUnknown*>(*ppv))->AddRef() ;
  52. return S_OK ;
  53. }
  54. ///////////////////////////////////////////////////////////
  55. //
  56. // AddRef
  57. //
  58. ULONG __stdcall CConnectionPoint::AddRef()
  59. {
  60. // Delegate AddRefss
  61. return m_pIConnectionPointContainer->AddRef() ;
  62. }
  63. ///////////////////////////////////////////////////////////
  64. //
  65. // Release
  66. //
  67. ULONG __stdcall CConnectionPoint::Release()
  68. {
  69. // Delegate Releases
  70. return m_pIConnectionPointContainer->Release() ;
  71. }
  72. ///////////////////////////////////////////////////////////
  73. //
  74. // Interface IConnectionPoint Methods
  75. //
  76. ///////////////////////////////////////////////////////////
  77. //
  78. // GetConnectionInterface
  79. //
  80. HRESULT __stdcall
  81. CConnectionPoint::GetConnectionInterface(IID* piid)
  82. {
  83. assert( m_piid != NULL);
  84. if (piid == NULL)
  85. {
  86. return E_POINTER ;
  87. }
  88. // Cast away Cast away Cast away Const!
  89. *piid = *(const_cast<IID*>(m_piid)) ;
  90. return S_OK ;
  91. }
  92. ///////////////////////////////////////////////////////////
  93. //
  94. // GetConnectionPointContainer
  95. //
  96. HRESULT __stdcall
  97. CConnectionPoint::GetConnectionPointContainer(IConnectionPointContainer** ppIConnectionPointContainer)
  98. {
  99. assert( m_pIConnectionPointContainer != NULL);
  100. if (ppIConnectionPointContainer == NULL)
  101. {
  102. return E_POINTER ;
  103. }
  104. *ppIConnectionPointContainer = m_pIConnectionPointContainer ;
  105. m_pIConnectionPointContainer->AddRef() ;
  106. return S_OK ;
  107. }
  108. ///////////////////////////////////////////////////////////
  109. //
  110. // Advise
  111. //
  112. HRESULT __stdcall
  113. CConnectionPoint::Advise(IUnknown* pIUnknownSink, DWORD* pdwCookie )
  114. {
  115. if (pIUnknownSink == NULL || pdwCookie == NULL)
  116. {
  117. *pdwCookie = 0;
  118. return E_POINTER;
  119. }
  120. IUnknown* pI = NULL ;
  121. HRESULT hr = pIUnknownSink->QueryInterface(*m_piid, (void**)&pI) ;
  122. if (SUCCEEDED(hr))
  123. {
  124. m_Cd.dwCookie = ++m_dwNextCookie ;
  125. m_Cd.pUnk = pI ;
  126. if (pI)
  127. pI->Release();
  128. // Return cookie
  129. *pdwCookie = m_Cd.dwCookie ;
  130. return S_OK ;
  131. }
  132. else
  133. {
  134. return CONNECT_E_CANNOTCONNECT ;
  135. }
  136. }
  137. ///////////////////////////////////////////////////////////
  138. //
  139. // Unadvise
  140. //
  141. HRESULT __stdcall
  142. CConnectionPoint::Unadvise(DWORD dwCookie)
  143. {
  144. if (m_Cd.dwCookie == dwCookie)
  145. {
  146. // Found sink point.
  147. IUnknown* pSink = m_Cd.pUnk;
  148. // Release the interface pointer.
  149. pSink->Release() ;
  150. return S_OK ;
  151. }
  152. return CONNECT_E_NOCONNECTION;;
  153. }
  154. ///////////////////////////////////////////////////////////
  155. //
  156. // EnumConnections
  157. //
  158. HRESULT __stdcall
  159. CConnectionPoint::EnumConnections(IEnumConnections** ppIEnum)
  160. {
  161. //if (ppIEnum == NULL)
  162. {
  163. // return E_POINTER ;
  164. }
  165. // Construct the enumerator object.
  166. //IEnumConnections* pIEnum = new CEnumConnections(m_SinkList) ;
  167. // The contructor AddRefs for us.
  168. //*ppIEnum = pIEnum ;
  169. return S_OK ;
  170. }