Source code of Windows XP (NT5)
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.

140 lines
3.9 KiB

  1. //=--------------------------------------------------------------------------=
  2. // Unknown.Cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995-1996 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 "IPServer.H"
  16. #include "Unknown.H"
  17. #include <stddef.h>
  18. //=--------------------------------------------------------------------------=
  19. // CUnknownObject::CPrivateUnknownObject::m_pMainUnknown
  20. //=--------------------------------------------------------------------------=
  21. // this method is used when we're sitting in the private unknown object,
  22. // and we need to get at the pointer for the main unknown. basically, it's
  23. // a little better to do this pointer arithmetic than have to store a pointer
  24. // to the parent, etc.
  25. //
  26. inline CUnknownObject *CUnknownObject::CPrivateUnknownObject::m_pMainUnknown
  27. (
  28. void
  29. )
  30. {
  31. return (CUnknownObject *)((LPBYTE)this - offsetof(CUnknownObject, m_UnkPrivate));
  32. }
  33. //=--------------------------------------------------------------------------=
  34. // CUnknownObject::CPrivateUnknownObject::QueryInterface
  35. //=--------------------------------------------------------------------------=
  36. // this is the non-delegating internal QI routine.
  37. //
  38. // Parameters:
  39. // REFIID - [in] interface they want
  40. // void ** - [out] where they want to put the resulting object ptr.
  41. //
  42. // Output:
  43. // HRESULT - S_OK, E_NOINTERFACE
  44. //
  45. // Notes:
  46. //
  47. STDMETHODIMP CUnknownObject::CPrivateUnknownObject::QueryInterface
  48. (
  49. REFIID riid,
  50. void **ppvObjOut
  51. )
  52. {
  53. CHECK_POINTER(ppvObjOut);
  54. // if they're asking for IUnknown, then we have to pass them ourselves.
  55. // otherwise defer to the inheriting object's InternalQueryInterface
  56. //
  57. if (DO_GUIDS_MATCH(riid, IID_IUnknown)) {
  58. m_cRef++;
  59. *ppvObjOut = (IUnknown *)this;
  60. return S_OK;
  61. } else
  62. return m_pMainUnknown()->InternalQueryInterface(riid, ppvObjOut);
  63. // dead code
  64. }
  65. //=--------------------------------------------------------------------------=
  66. // CUnknownObject::CPrivateUnknownObject::AddRef
  67. //=--------------------------------------------------------------------------=
  68. // adds a tick to the current reference count.
  69. //
  70. // Output:
  71. // ULONG - the new reference count
  72. //
  73. // Notes:
  74. //
  75. ULONG CUnknownObject::CPrivateUnknownObject::AddRef
  76. (
  77. void
  78. )
  79. {
  80. return ++m_cRef;
  81. }
  82. //=--------------------------------------------------------------------------=
  83. // CUnknownObject::CPrivateUnknownObject::Release
  84. //=--------------------------------------------------------------------------=
  85. // removes a tick from the count, and delets the object if necessary
  86. //
  87. // Output:
  88. // ULONG - remaining refs
  89. //
  90. // Notes:
  91. //
  92. ULONG CUnknownObject::CPrivateUnknownObject::Release
  93. (
  94. void
  95. )
  96. {
  97. ULONG cRef = --m_cRef;
  98. if (!m_cRef)
  99. delete m_pMainUnknown();
  100. return cRef;
  101. }
  102. //=--------------------------------------------------------------------------=
  103. // CUnknownObject::InternalQueryInterface
  104. //=--------------------------------------------------------------------------=
  105. // objects that are aggregated use this to support additional interfaces.
  106. // they should call this method on their parent so that any of it's interfaces
  107. // are queried.
  108. //
  109. // Parameters:
  110. // REFIID - [in] interface they want
  111. // void ** - [out] where they want to put the resulting object ptr.
  112. //
  113. // Output:
  114. // HRESULT - S_OK, E_NOINTERFACE
  115. //
  116. // Notes:
  117. //
  118. HRESULT CUnknownObject::InternalQueryInterface
  119. (
  120. REFIID riid,
  121. void **ppvObjOut
  122. )
  123. {
  124. *ppvObjOut = NULL;
  125. return E_NOINTERFACE;
  126. }
  127.