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.

68 lines
2.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1994-1998, Microsoft Corporation
  4. //
  5. // File: impiunk.hxx
  6. //
  7. // Contents: Inner IUnknown template.
  8. //
  9. // Templates: CImpIUnknown
  10. //
  11. // History: 22-May-97 emilyb created
  12. //
  13. //----------------------------------------------------------------------------
  14. #pragma once
  15. // NOTE: if IUnknown & _rControllingQuery is ever added to this
  16. // general case, then update CRowset to use this class.
  17. template <class T> class CImpIUnknown : public IUnknown
  18. {
  19. friend class T;
  20. public:
  21. CImpIUnknown( T * p) :
  22. _ref(0), _p(p)
  23. {};
  24. ~CImpIUnknown() {};
  25. //
  26. // IUnknown methods.
  27. //
  28. STDMETHOD(QueryInterface) ( THIS_ REFIID riid,
  29. LPVOID *ppiuk )
  30. {
  31. SCODE sc= S_OK;
  32. if (IID_IUnknown == riid)
  33. *ppiuk = this;
  34. else
  35. sc = _p->RealQueryInterface(riid, ppiuk);
  36. if ( SUCCEEDED( sc) )
  37. ((IUnknown *) *ppiuk)->AddRef();
  38. return sc;
  39. }
  40. STDMETHOD_(ULONG, AddRef) (THIS)
  41. {
  42. return InterlockedIncrement( (long *)&_ref );
  43. }
  44. STDMETHOD_(ULONG, Release) (THIS)
  45. {
  46. long l = InterlockedDecrement( (long *)&_ref );
  47. if ( l <= 0 )
  48. {
  49. delete _p;
  50. return 0;
  51. }
  52. return l;
  53. }
  54. private:
  55. long _ref; // OLE reference count
  56. T * _p;
  57. };