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.

172 lines
3.4 KiB

  1. /*++=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. iunknown.cxx
  5. Abstract:
  6. Implements the W3Spoof object's IUnknown & IExternalConnection interfaces.
  7. Author:
  8. Paul M Midgen (pmidge) 08-January-2001
  9. Revision History:
  10. 08-January-2001 pmidge
  11. Created
  12. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--*/
  13. #include "common.h"
  14. //-----------------------------------------------------------------------------
  15. // IUnknown
  16. //-----------------------------------------------------------------------------
  17. HRESULT
  18. __stdcall
  19. CW3Spoof::QueryInterface(REFIID riid, void** ppv)
  20. {
  21. DEBUG_ENTER((
  22. DBG_REFCOUNT,
  23. rt_hresult,
  24. "CW3Spoof::QueryInterface",
  25. "this=%#x; riid=%s; ppv=%#x",
  26. this,
  27. MapIIDToString(riid),
  28. ppv
  29. ));
  30. HRESULT hr = S_OK;
  31. if( !ppv )
  32. {
  33. hr = E_POINTER;
  34. goto quit;
  35. }
  36. if( m_state != ST_OPEN )
  37. {
  38. DEBUG_TRACE(W3SOBJ, ("invalid state!"));
  39. *ppv = NULL;
  40. hr = E_FAIL;
  41. goto quit;
  42. }
  43. else
  44. {
  45. if(
  46. IsEqualIID(riid, IID_IUnknown) ||
  47. IsEqualIID(riid, IID_IW3Spoof) ||
  48. IsEqualIID(riid, IID_IConfig)
  49. )
  50. {
  51. *ppv = static_cast<IW3Spoof*>(this);
  52. }
  53. else if( IsEqualIID(riid, IID_IDispatch) )
  54. {
  55. *ppv = static_cast<IDispatch*>(this);
  56. }
  57. else if( IsEqualIID(riid, IID_IThreadPool) )
  58. {
  59. *ppv = static_cast<IThreadPool*>(this);
  60. }
  61. else if( IsEqualIID(riid, IID_IW3SpoofClientSupport) )
  62. {
  63. *ppv = static_cast<IW3SpoofClientSupport*>(this);
  64. }
  65. else if( IsEqualIID(riid, IID_IExternalConnection) )
  66. {
  67. *ppv = static_cast<IExternalConnection*>(this);
  68. }
  69. else if( IsEqualIID(riid, IID_IConnectionPointContainer) )
  70. {
  71. *ppv = static_cast<IConnectionPointContainer*>(this);
  72. }
  73. else
  74. {
  75. *ppv = NULL;
  76. hr = E_NOINTERFACE;
  77. }
  78. if( SUCCEEDED(hr) )
  79. reinterpret_cast<IUnknown*>(*ppv)->AddRef();
  80. }
  81. quit:
  82. DEBUG_LEAVE(hr);
  83. return hr;
  84. }
  85. ULONG
  86. __stdcall
  87. CW3Spoof::AddRef(void)
  88. {
  89. InterlockedIncrement(&m_cRefs);
  90. DEBUG_ADDREF("CW3Spoof", m_cRefs);
  91. return m_cRefs;
  92. }
  93. ULONG
  94. __stdcall
  95. CW3Spoof::Release(void)
  96. {
  97. InterlockedDecrement(&m_cRefs);
  98. DEBUG_RELEASE("CW3Spoof", m_cRefs);
  99. if( m_cRefs == 0 )
  100. {
  101. DEBUG_FINALRELEASE("CW3Spoof");
  102. delete this;
  103. return 0;
  104. }
  105. return m_cRefs;
  106. }
  107. //-----------------------------------------------------------------------------
  108. // IExternalConnection
  109. //-----------------------------------------------------------------------------
  110. DWORD
  111. __stdcall
  112. CW3Spoof::AddConnection(DWORD type, DWORD reserved)
  113. {
  114. DWORD ret = 0L;
  115. if( type & EXTCONN_STRONG )
  116. {
  117. ret = (DWORD) InterlockedIncrement(&m_cExtRefs);
  118. }
  119. DEBUG_TRACE(W3SOBJ, ("external refcount: %d", m_cExtRefs));
  120. return ret;
  121. }
  122. DWORD
  123. __stdcall
  124. CW3Spoof::ReleaseConnection(DWORD type, DWORD reserved, BOOL bCloseIfLast)
  125. {
  126. DWORD ret = 0L;
  127. if( type & EXTCONN_STRONG )
  128. {
  129. ret = (DWORD) InterlockedDecrement(&m_cExtRefs);
  130. if( (ret == 0) && bCloseIfLast )
  131. {
  132. SetEvent(m_evtServerUnload);
  133. }
  134. }
  135. DEBUG_TRACE(W3SOBJ, ("external refcount: %d", m_cExtRefs));
  136. return ret;
  137. }