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.

61 lines
1.4 KiB

  1. #ifndef __ATLPOOL_H_
  2. #define __ATLPOOL_H_
  3. #include <atlbase.h>
  4. #include <atlcom.h>
  5. #include "PassportObjectPool.hpp"
  6. //Base is the user's class that derives from CComObjectRoot and whatever
  7. //interfaces the user wants to support on the object
  8. template <class Base>
  9. class CComObjectPooled : public Base
  10. {
  11. public:
  12. typedef Base _BaseClass;
  13. CComObjectPooled(void* = NULL) : m_Pool(NULL)
  14. {
  15. _Module.Lock();
  16. }
  17. // Set refcount to 1 to protect destruction
  18. ~CComObjectPooled()
  19. {
  20. m_dwRef = 1L;
  21. FinalRelease();
  22. #ifdef _ATL_DEBUG_INTERFACES
  23. _Module.DeleteNonAddRefThunk(_GetRawUnknown());
  24. #endif
  25. _Module.Unlock();
  26. }
  27. //If InternalAddRef or InternalRelease is undefined then your class
  28. //doesn't derive from CComObjectRoot
  29. STDMETHOD_(ULONG, AddRef)() {return InternalAddRef();}
  30. STDMETHOD_(ULONG, Release)()
  31. {
  32. ULONG l = InternalRelease();
  33. if (l == 0 && m_Pool)
  34. m_Pool->checkin(this);
  35. return l;
  36. }
  37. //if _InternalQueryInterface is undefined then you forgot BEGIN_COM_MAP
  38. STDMETHOD(QueryInterface)(REFIID iid, void ** ppvObject)
  39. {return _InternalQueryInterface(iid, ppvObject);}
  40. template <class Q>
  41. HRESULT STDMETHODCALLTYPE QueryInterface(Q** pp)
  42. {
  43. return QueryInterface(__uuidof(Q), (void**)pp);
  44. }
  45. void SetPool(PassportObjectPool< CComObjectPooled<Base> >* pPool)
  46. {
  47. m_Pool = pPool;
  48. }
  49. private:
  50. void* m_Releaser;
  51. PassportObjectPool< CComObjectPooled<Base> > *m_Pool;
  52. };
  53. #endif