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.

170 lines
3.8 KiB

  1. //+----------------------------------------------------------------------------
  2. // File: basecom.cxx
  3. //
  4. // Synopsis: This file contains implementations of the root COM objects
  5. //
  6. //-----------------------------------------------------------------------------
  7. // Includes -------------------------------------------------------------------
  8. #include <core.hxx>
  9. //+----------------------------------------------------------------------------
  10. // Function: SRelease, SClear
  11. //
  12. // Synopsis:
  13. //
  14. //-----------------------------------------------------------------------------
  15. void
  16. SRelease(
  17. IUnknown * pUnk)
  18. {
  19. if (pUnk)
  20. {
  21. pUnk->Release();
  22. }
  23. }
  24. void
  25. SClear(
  26. IUnknown ** ppUnk)
  27. {
  28. Assert(ppUnk);
  29. if (*ppUnk)
  30. {
  31. (*ppUnk)->Release();
  32. *ppUnk = NULL;
  33. }
  34. }
  35. //+----------------------------------------------------------------------------
  36. // Function: PublicQueryInterface
  37. //
  38. // Synopsis:
  39. //
  40. //-----------------------------------------------------------------------------
  41. STDMETHODIMP
  42. CComponent::PublicQueryInterface(
  43. REFIID riid,
  44. void ** ppvObj)
  45. {
  46. return _pUnkOuter->QueryInterface(riid, ppvObj);
  47. }
  48. //+----------------------------------------------------------------------------
  49. // Function: PublicAddRef
  50. //
  51. // Synopsis:
  52. //
  53. //-----------------------------------------------------------------------------
  54. STDMETHODIMP_(ULONG)
  55. CComponent::PublicAddRef()
  56. {
  57. return _pUnkOuter->AddRef();
  58. }
  59. //+----------------------------------------------------------------------------
  60. // Function: PublicRelease
  61. //
  62. // Synopsis:
  63. //
  64. //-----------------------------------------------------------------------------
  65. STDMETHODIMP_(ULONG)
  66. CComponent::PublicRelease()
  67. {
  68. return _pUnkOuter->Release();
  69. }
  70. //+----------------------------------------------------------------------------
  71. // Function: PrivateQueryInterface
  72. //
  73. // Synopsis:
  74. //
  75. //-----------------------------------------------------------------------------
  76. HRESULT
  77. CComponent::PrivateQueryInterface(
  78. REFIID riid,
  79. void ** ppvObj)
  80. {
  81. if (riid == IID_IUnknown)
  82. {
  83. *ppvObj = (void *)(IUnknown *)&_Unk;
  84. return S_OK;
  85. }
  86. return E_NOINTERFACE;
  87. }
  88. //+----------------------------------------------------------------------------
  89. // Function: CUnknown::QueryInterface
  90. //
  91. // Synopsis:
  92. //
  93. //-----------------------------------------------------------------------------
  94. STDMETHODIMP
  95. CComponent::CUnknown::QueryInterface(
  96. REFIID riid,
  97. void ** ppvObj)
  98. {
  99. HRESULT hr;
  100. Assert(ppvObj);
  101. if (!ppvObj)
  102. return E_INVALIDARG;
  103. *ppvObj = NULL;
  104. hr = OWNING_CLASS(CComponent, _Unk)->PrivateQueryInterface(riid, ppvObj);
  105. if (!hr)
  106. {
  107. Assert(*ppvObj);
  108. ((IUnknown *)*ppvObj)->AddRef();
  109. hr = S_OK;
  110. }
  111. return hr;
  112. }
  113. //+----------------------------------------------------------------------------
  114. // Function: CUnknown::AddRef
  115. //
  116. // Synopsis:
  117. //
  118. //-----------------------------------------------------------------------------
  119. STDMETHODIMP_(ULONG)
  120. CComponent::CUnknown::AddRef()
  121. {
  122. return ++(OWNING_CLASS(CComponent, _Unk)->_cRefs);
  123. }
  124. //+----------------------------------------------------------------------------
  125. // Function: CUnknown::Release
  126. //
  127. // Synopsis:
  128. //
  129. //-----------------------------------------------------------------------------
  130. STDMETHODIMP_(ULONG)
  131. CComponent::CUnknown::Release()
  132. {
  133. CComponent * pComp = OWNING_CLASS(CComponent, _Unk);
  134. Assert(OWNING_CLASS(CComponent, _Unk)->_cRefs);
  135. if (!--pComp->_cRefs)
  136. {
  137. pComp->_cRefs += REF_GUARD;
  138. delete pComp;
  139. return 0;
  140. }
  141. return pComp->_cRefs;
  142. }