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.

108 lines
2.8 KiB

  1. //+----------------------------------------------------------------------------
  2. // File: basecom.hxx
  3. //
  4. // Synopsis:
  5. //
  6. //-----------------------------------------------------------------------------
  7. #ifndef _BASECOM_HXX
  8. #define _BASECOM_HXX
  9. class CVoid;
  10. class CUnknown;
  11. class CComponent;
  12. // Types ----------------------------------------------------------------------
  13. #define DEFINE_IUNKNOWN_METHODS \
  14. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObj) \
  15. { return PublicQueryInterface(riid, ppvObj); } \
  16. STDMETHOD_(ULONG, AddRef)() \
  17. { return PublicAddRef(); } \
  18. STDMETHOD_(ULONG, Release)() \
  19. { return PublicRelease(); }
  20. #define OWNING_CLASS(parent, member) CONTAINING_RECORD(this, parent, member)
  21. // Prototypes -----------------------------------------------------------------
  22. template <class TYPE> TYPE * SAddRef(TYPE * pUnk)
  23. {
  24. if (pUnk)
  25. {
  26. pUnk->AddRef();
  27. }
  28. return pUnk;
  29. }
  30. void SClear(IUnknown ** ppUnk);
  31. void SRelease(IUnknown * pUnk);
  32. //+----------------------------------------------------------------------------
  33. // Class: CVoid
  34. //
  35. // Synopsis:
  36. //
  37. //-----------------------------------------------------------------------------
  38. class CVoid
  39. {
  40. public:
  41. };
  42. //+----------------------------------------------------------------------------
  43. // Class: CComponent
  44. //
  45. // Synopsis:
  46. //
  47. //-----------------------------------------------------------------------------
  48. class CComponent : public CVoid
  49. {
  50. // Private IUnknown
  51. class CUnknown : public IUnknown
  52. {
  53. public:
  54. STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObj);
  55. STDMETHOD_(ULONG, AddRef)();
  56. STDMETHOD_(ULONG, Release)();
  57. };
  58. friend class CUnknown;
  59. public:
  60. CComponent(IUnknown * pUnkOuter = NULL)
  61. {
  62. _cRefs = 1;
  63. _pUnkOuter = (pUnkOuter
  64. ? pUnkOuter
  65. : &_Unk);
  66. IncrementThreadUsage();
  67. }
  68. virtual ~CComponent()
  69. {
  70. DecrementThreadUsage();
  71. }
  72. // IUnknown helpers
  73. STDMETHOD(PublicQueryInterface)(REFIID riid, void ** ppvObj);
  74. STDMETHOD_(ULONG, PublicAddRef)();
  75. STDMETHOD_(ULONG, PublicRelease)();
  76. IUnknown * PrivateUnknown()
  77. {
  78. return &_Unk;
  79. }
  80. protected:
  81. ULONG _cRefs;
  82. IUnknown * _pUnkOuter;
  83. CUnknown _Unk;
  84. // Private QueryInterface (override to provide additional interfaces)
  85. virtual HRESULT PrivateQueryInterface(REFIID riid, void ** ppvObj);
  86. };
  87. #endif // _BASECOM_HXX