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.

103 lines
3.2 KiB

  1. // Copyright (C) 1996-1997 Microsoft Corporation. All rights reserved.
  2. #include "header.h"
  3. #include "Unknown.H"
  4. #include <stddef.h>
  5. //=--------------------------------------------------------------------------=
  6. // CUnknownObject::CPrivateUnknownObject::m_pMainUnknown
  7. //=--------------------------------------------------------------------------=
  8. // this method is used when we're sitting in the private unknown object,
  9. // and we need to get at the pointer for the main unknown. basically, it's
  10. // a little better to do this pointer arithmetic than have to store a pointer
  11. // to the parent, etc.
  12. inline CUnknownObject *CUnknownObject::CPrivateUnknownObject::m_pMainUnknown
  13. (
  14. void
  15. )
  16. {
  17. return (CUnknownObject *)((LPBYTE)this - offsetof(CUnknownObject, m_UnkPrivate));
  18. }
  19. //=--------------------------------------------------------------------------=
  20. // CUnknownObject::CPrivateUnknownObject::QueryInterface
  21. //=--------------------------------------------------------------------------=
  22. // this is the non-delegating internal QI routine.
  23. //
  24. // Parameters:
  25. // REFIID - [in] interface they want
  26. // void ** - [out] where they want to put the resulting object ptr.
  27. //
  28. // Output:
  29. // HRESULT - S_OK, E_NOINTERFACE
  30. STDMETHODIMP CUnknownObject::CPrivateUnknownObject::QueryInterface(REFIID riid, void **ppvObjOut)
  31. {
  32. CHECK_POINTER(ppvObjOut);
  33. // if they're asking for IUnknown, then we have to pass them ourselves.
  34. // otherwise defer to the inheriting object's InternalQueryInterface
  35. //
  36. if (DO_GUIDS_MATCH(riid, IID_IUnknown)) {
  37. m_cRef++;
  38. *ppvObjOut = (IUnknown *)this;
  39. return S_OK;
  40. } else
  41. return m_pMainUnknown()->InternalQueryInterface(riid, ppvObjOut);
  42. // dead code
  43. }
  44. //=--------------------------------------------------------------------------=
  45. // CUnknownObject::CPrivateUnknownObject::AddRef
  46. //=--------------------------------------------------------------------------=
  47. // adds a tick to the current reference count.
  48. //
  49. // Output:
  50. // ULONG - the new reference count
  51. ULONG CUnknownObject::CPrivateUnknownObject::AddRef(void)
  52. {
  53. return ++m_cRef;
  54. }
  55. //=--------------------------------------------------------------------------=
  56. // CUnknownObject::CPrivateUnknownObject::Release
  57. //=--------------------------------------------------------------------------=
  58. // removes a tick from the count, and delets the object if necessary
  59. //
  60. // Output:
  61. // ULONG - remaining refs
  62. ULONG CUnknownObject::CPrivateUnknownObject::Release (void)
  63. {
  64. ULONG cRef = --m_cRef;
  65. if (!m_cRef)
  66. delete m_pMainUnknown();
  67. return cRef;
  68. }
  69. //=--------------------------------------------------------------------------=
  70. // CUnknownObject::InternalQueryInterface
  71. //=--------------------------------------------------------------------------=
  72. // objects that are aggregated use this to support additional interfaces.
  73. // they should call this method on their parent so that any of it's interfaces
  74. // are queried.
  75. //
  76. // Parameters:
  77. // REFIID - [in] interface they want
  78. // void ** - [out] where they want to put the resulting object ptr.
  79. //
  80. // Output:
  81. // HRESULT - S_OK, E_NOINTERFACE
  82. HRESULT CUnknownObject::InternalQueryInterface(REFIID riid, void **ppvObjOut)
  83. {
  84. *ppvObjOut = NULL;
  85. return E_NOINTERFACE;
  86. }