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
5.0 KiB

  1. //=--------------------------------------------------------------------------=
  2. // Unknown.Cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // implementation for various things in the unknown object that supports
  13. // aggregation.
  14. //
  15. #include "pch.h"
  16. #include "Unknown.H"
  17. #include <stddef.h>
  18. // for ASSERT and FAIL
  19. //
  20. SZTHISFILE
  21. //=--------------------------------------------------------------------------=
  22. // CUnknownObject::CPrivateUnknownObject::m_pMainUnknown
  23. //=--------------------------------------------------------------------------=
  24. // this method is used when we're sitting in the private unknown object,
  25. // and we need to get at the pointer for the main unknown. basically, it's
  26. // a little better to do this pointer arithmetic than have to store a pointer
  27. // to the parent, etc.
  28. //
  29. inline CUnknownObject *CUnknownObject::CPrivateUnknownObject::m_pMainUnknown
  30. (
  31. void
  32. )
  33. {
  34. return (CUnknownObject *)((LPBYTE)this - offsetof(CUnknownObject, m_UnkPrivate));
  35. }
  36. //=--------------------------------------------------------------------------=
  37. // CUnknownObject::CPrivateUnknownObject::QueryInterface
  38. //=--------------------------------------------------------------------------=
  39. // this is the non-delegating internal QI routine.
  40. //
  41. // Parameters:
  42. // REFIID - [in] interface they want
  43. // void ** - [out] where they want to put the resulting object ptr.
  44. //
  45. // Output:
  46. // HRESULT - S_OK, E_NOINTERFACE
  47. //
  48. // Notes:
  49. //
  50. STDMETHODIMP CUnknownObject::CPrivateUnknownObject::QueryInterface
  51. (
  52. REFIID riid,
  53. void **ppvObjOut
  54. )
  55. {
  56. CHECK_POINTER(ppvObjOut);
  57. // if they're asking for IUnknown, then we have to pass them ourselves.
  58. // otherwise defer to the inheriting object's InternalQueryInterface
  59. //
  60. if (DO_GUIDS_MATCH(riid, IID_IUnknown)) {
  61. m_cRef++;
  62. *ppvObjOut = (IUnknown *)this;
  63. return S_OK;
  64. } else
  65. return m_pMainUnknown()->InternalQueryInterface(riid, ppvObjOut);
  66. // dead code
  67. }
  68. //=--------------------------------------------------------------------------=
  69. // CUnknownObject::CPrivateUnknownObject::AddRef
  70. //=--------------------------------------------------------------------------=
  71. // adds a tick to the current reference count.
  72. //
  73. // Output:
  74. // ULONG - the new reference count
  75. //
  76. // Notes:
  77. //
  78. ULONG CUnknownObject::CPrivateUnknownObject::AddRef
  79. (
  80. void
  81. )
  82. {
  83. return ++m_cRef;
  84. }
  85. //=--------------------------------------------------------------------------=
  86. // CUnknownObject::CPrivateUnknownObject::Release
  87. //=--------------------------------------------------------------------------=
  88. // removes a tick from the count, and delets the object if necessary
  89. //
  90. // Output:
  91. // ULONG - remaining refs
  92. //
  93. // Notes:
  94. //
  95. ULONG CUnknownObject::CPrivateUnknownObject::Release
  96. (
  97. void
  98. )
  99. {
  100. // are we just about to go away?
  101. //
  102. if (1 == m_cRef) {
  103. // if we are, then we want to let the user know about it, so they can
  104. // free things up before their vtables go away. the extra ref here
  105. // makes sure that if they addref/release something, they don't cause
  106. // the current code to get tripped again
  107. //
  108. m_cRef++;
  109. m_pMainUnknown()->BeforeDestroyObject();
  110. ASSERT(m_cRef == 2, "ctl has Ref Count problem!!");
  111. m_cRef = 0; // so people can be sure of this in the destructor
  112. delete m_pMainUnknown();
  113. return 0;
  114. }
  115. return --m_cRef;
  116. }
  117. //=--------------------------------------------------------------------------=
  118. // CUnknownObject::InternalQueryInterface
  119. //=--------------------------------------------------------------------------=
  120. // objects that are aggregated use this to support additional interfaces.
  121. // they should call this method on their parent so that any of it's interfaces
  122. // are queried.
  123. //
  124. // Parameters:
  125. // REFIID - [in] interface they want
  126. // void ** - [out] where they want to put the resulting object ptr.
  127. //
  128. // Output:
  129. // HRESULT - S_OK, E_NOINTERFACE
  130. //
  131. // Notes:
  132. //
  133. HRESULT CUnknownObject::InternalQueryInterface
  134. (
  135. REFIID riid,
  136. void **ppvObjOut
  137. )
  138. {
  139. *ppvObjOut = NULL;
  140. return E_NOINTERFACE;
  141. }
  142. //=--------------------------------------------------------------------------=
  143. // CUnknownObject::BeforeDestroyObject
  144. //=--------------------------------------------------------------------------=
  145. // called just as we are about to trash an object
  146. //
  147. // Notes:
  148. //
  149. void CUnknownObject::BeforeDestroyObject
  150. (
  151. void
  152. )
  153. {
  154. }