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.

52 lines
1.0 KiB

  1. // File: refcount.h
  2. #ifndef _REFCOUNT_H_
  3. #define _REFCOUNT_H_
  4. // RefCount destructor callback function
  5. typedef void (*OBJECTDESTROYEDPROC)(void);
  6. VOID STDMETHODCALLTYPE DLLObjectDestroyed(void);
  7. VOID DllLock(void);
  8. //////////////////////////////////////////////////////////////////////////
  9. class RefCount
  10. {
  11. private:
  12. ULONG m_ulcRef;
  13. OBJECTDESTROYEDPROC m_ObjectDestroyed;
  14. #ifdef DEBUG
  15. BOOL m_fTrack;
  16. #endif
  17. void Init(OBJECTDESTROYEDPROC ObjectDestroyed);
  18. public:
  19. RefCount();
  20. RefCount(OBJECTDESTROYEDPROC ObjectDestroyed);
  21. // Virtual destructor defers to destructor of derived class.
  22. virtual ~RefCount(void);
  23. // IUnknown
  24. ULONG STDMETHODCALLTYPE AddRef(void);
  25. ULONG STDMETHODCALLTYPE Release(void);
  26. #ifdef DEBUG
  27. VOID SetTrack(BOOL fTrack) {m_fTrack = fTrack;}
  28. #endif
  29. };
  30. DECLARE_STANDARD_TYPES(RefCount);
  31. // Special version of the above that calls our standard Dll locking functions
  32. class DllRefCount : public RefCount
  33. {
  34. public:
  35. DllRefCount() : RefCount(&DLLObjectDestroyed) {DllLock();}
  36. ~DllRefCount(void) {};
  37. };
  38. #endif /* _REFCOUNT_H_ */