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.

93 lines
2.2 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. LUNKNOWN.H
  5. History:
  6. --*/
  7. #if !defined (EspUtil_LUnknown_h)
  8. #define EspUtil_LUnknown_h
  9. ////////////////////////////////////////////////////////////////////////////////
  10. // CLUnknown
  11. //
  12. // A abstract base class that is designed to help when creating child classes
  13. // that depend on a parent class. These classes can not exist by themselves,
  14. // but instead mearly export different interfaces to the parent class.
  15. //
  16. // Rules:
  17. // 1. All classes must have a valid, non-NULL parent pointer.
  18. // 2. The parent class is responsible for AddRef()'ing itself during
  19. // QueryInterface().
  20. //
  21. ////////////////////////////////////////////////////////////////////////////////
  22. class LTAPIENTRY CLUnknown
  23. {
  24. // Construction
  25. public:
  26. CLUnknown(IUnknown * pParent);
  27. protected: // Don't allow stack objects
  28. virtual ~CLUnknown() = 0;
  29. // Data
  30. protected:
  31. ULONG m_ulRef; // Reference count
  32. IUnknown * m_pParent; // Parent of object
  33. // Operations
  34. public:
  35. ULONG AddRef();
  36. ULONG Release();
  37. HRESULT QueryInterface(REFIID iid, LPVOID * ppvObject);
  38. };
  39. ////////////////////////////////////////////////////////////////////////////////
  40. #include "LUnknown.inl"
  41. #if !defined(DECLARE_CLUNKNOWN)
  42. #define DECLARE_CLUNKNOWN() \
  43. public: \
  44. STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID FAR*ppvObj); \
  45. STDMETHOD_(ULONG, AddRef)(THIS); \
  46. STDMETHOD_(ULONG, Release)(THIS);
  47. #endif
  48. #if !defined(IMPLEMENT_CLUNKNOWN)
  49. #define IMPLEMENT_CLUNKNOWN_ADDREF(ObjectClass) \
  50. STDMETHODIMP_(ULONG) ObjectClass::AddRef(void) \
  51. { \
  52. return CLUnknown::AddRef(); \
  53. }
  54. #define IMPLEMENT_CLUNKNOWN_RELEASE(ObjectClass) \
  55. STDMETHODIMP_(ULONG) ObjectClass::Release(void) \
  56. { \
  57. return CLUnknown::Release(); \
  58. }
  59. #define IMPLEMENT_CLUNKNOWN_QUERYINTERFACE(ObjectClass) \
  60. STDMETHODIMP ObjectClass::QueryInterface(REFIID riid, LPVOID *ppVoid) \
  61. { \
  62. return (HRESULT) CLUnknown::QueryInterface(riid, ppVoid); \
  63. }
  64. #define IMPLEMENT_CLUNKNOWN(ObjectClass) \
  65. IMPLEMENT_CLUNKNOWN_ADDREF(ObjectClass) \
  66. IMPLEMENT_CLUNKNOWN_RELEASE(ObjectClass) \
  67. IMPLEMENT_CLUNKNOWN_QUERYINTERFACE(ObjectClass)
  68. #endif
  69. #endif