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.

56 lines
1.5 KiB

  1. /*==========================================================================*\
  2. Module: baseobj.h
  3. Copyright Microsoft Corporation 1996, All Rights Reserved.
  4. Owner: mikepurt
  5. Descriptions: Provide OLE COM consistent reference counting.
  6. \*==========================================================================*/
  7. #ifndef __BASEOBJ_H__
  8. #define __BASEOBJ_H__
  9. #include "dbgtrace.h" //make sure we get _ASSERT
  10. class CBaseObject {
  11. public:
  12. CBaseObject()
  13. { m_lReferences = 1; }; // consistent with OLE COM
  14. virtual ~CBaseObject() {};
  15. // Included so the vtable is in a standard format ...
  16. virtual HRESULT STDMETHODCALLTYPE QueryInterface(
  17. IID FAR& riid,
  18. LPVOID FAR* ppvObj) { return E_NOTIMPL; }
  19. ULONG AddRef()
  20. { return (ULONG)(InterlockedExchangeAdd(&m_lReferences, 1) + 1); };
  21. ULONG Release()
  22. {
  23. LONG lRef;
  24. lRef = InterlockedExchangeAdd(&m_lReferences, -1) - 1;
  25. _ASSERT(lRef >= 0);
  26. _ASSERT(lRef < 0x00100000); // Sanity check against freed memory.
  27. if (0 == lRef)
  28. delete this; // Don't touch any member vars after this.
  29. return (ULONG)lRef;
  30. };
  31. protected:
  32. LONG m_lReferences;
  33. CBaseObject(CBaseObject&); // Force an error in instances where a copy constructor
  34. // was needed, but none was provided.
  35. };
  36. #endif // __BASEOBJ_H__