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.

101 lines
3.2 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1999 **
  4. //*********************************************************************
  5. //
  6. // CUNKNOWN.H - Header file for IUnknown Implementation.
  7. //
  8. // HISTORY:
  9. //
  10. // 1/27/99 a-jaswed Created.
  11. //
  12. // IUnknown Implementation.
  13. #ifndef __CUnknown_h__
  14. #define __CUnknown_h__
  15. #include <objbase.h>
  16. ///////////////////////////////////////////////////////////
  17. // Nondelegating version of IUnknown.
  18. //
  19. struct INondelegatingUnknown
  20. {
  21. virtual HRESULT __stdcall
  22. NondelegatingQueryInterface(const IID& iid, void** ppv) = 0;
  23. virtual ULONG __stdcall NondelegatingAddRef() = 0;
  24. virtual ULONG __stdcall NondelegatingRelease() = 0;
  25. };
  26. /////////////////////////////////////////////////////////////////////
  27. // Declaration of CUnknown
  28. //
  29. // Base class for implementing IUnknown.
  30. //
  31. class CUnknown : public INondelegatingUnknown
  32. {
  33. public:
  34. // Internal IUnknown Implementation...
  35. virtual HRESULT __stdcall NondelegatingQueryInterface( const IID&,
  36. void**) ;
  37. virtual ULONG __stdcall NondelegatingAddRef() ;
  38. virtual ULONG __stdcall NondelegatingRelease();
  39. // Constructor
  40. CUnknown(IUnknown* pOuterUnknown) ;
  41. // Destructor
  42. virtual ~CUnknown() ;
  43. // Initialization (esp for aggregates)
  44. virtual HRESULT Init()
  45. {return S_OK;}
  46. // Notify derived classes that we are releasing.
  47. virtual void FinalRelease() ;
  48. // Support for delegation
  49. IUnknown* GetOuterUnknown() const
  50. { return m_pOuterUnknown; }
  51. // Count of currently active components.
  52. static long ActiveComponents()
  53. {return s_cActiveComponents;}
  54. // QueryInterface Helper Function
  55. HRESULT FinishQI(IUnknown* pI, void** ppv) ;
  56. private:
  57. // Reference Count for this object.
  58. long m_cRef;
  59. // Outer IUnknown pointer.
  60. IUnknown* m_pOuterUnknown;
  61. // Count of all active instances.
  62. static long s_cActiveComponents ;
  63. } ;
  64. ///////////////////////////////////////////////////////////
  65. // Delegating IUnknown -
  66. //
  67. // Delegates to the nondelegating IUnknown interface if
  68. // not aggregated. If aggregated, delegates to the outer unknown.
  69. //
  70. #define DECLARE_IUNKNOWN \
  71. virtual HRESULT __stdcall \
  72. QueryInterface(const IID& iid, void** ppv) \
  73. { \
  74. return GetOuterUnknown()->QueryInterface(iid,ppv); \
  75. }; \
  76. virtual ULONG __stdcall AddRef() \
  77. { \
  78. return GetOuterUnknown()->AddRef(); \
  79. }; \
  80. virtual ULONG __stdcall Release() \
  81. { \
  82. return GetOuterUnknown()->Release(); \
  83. };
  84. #endif