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.

58 lines
1.7 KiB

  1. #pragma once
  2. #include "atlbase.h"
  3. template <typename T> class CSxApwComPtr;
  4. /* like what FusionHandle does */
  5. template <typename T>
  6. class CSmartPointerPointerOrDumbPointerPointerOrVoidPointerPointer
  7. {
  8. public:
  9. CSmartPointerPointerOrDumbPointerPointerOrVoidPointerPointer(CSxApwComPtr<T>* p) : m(p) { }
  10. operator CSxApwComPtr<T>*() { return m; }
  11. operator T**() { return &(*m).p; }
  12. operator void**() { return reinterpret_cast<void**>(operator T**()); }
  13. CSxApwComPtr<T>* m;
  14. };
  15. template <typename T>
  16. class CSxApwComPtr : public ATL::CComQIPtr<T>
  17. {
  18. private:
  19. typedef ATL::CComQIPtr<T> Base;
  20. public:
  21. ~CSxApwComPtr() { }
  22. CSxApwComPtr(const CSxApwComPtr& that) : Base(that) { }
  23. CSxApwComPtr(T* pt = NULL) : Base(pt) { }
  24. void operator=(T* pt) { Base::operator=(pt); }
  25. CSxApwComPtr(IUnknown* pt) : Base(pt) { }
  26. void operator=(IUnknown* pt) { Base::operator=(pt); }
  27. T* operator->() const { return Base::operator->(); }
  28. CSmartPointerPointerOrDumbPointerPointerOrVoidPointerPointer<T> operator&()
  29. {
  30. return CSmartPointerPointerOrDumbPointerPointerOrVoidPointerPointer<T>(this);
  31. }
  32. };
  33. //Specialization to make it work
  34. template<>
  35. class CSxApwComPtr<IUnknown> : public ATL::CComQIPtr<IUnknown, &IID_IUnknown>
  36. {
  37. private:
  38. typedef T IUnknown;
  39. typedef ATL::CComQIPtr<IUnknown, &IID_IUnknown> Base;
  40. public:
  41. ~CSxApwComPtr() { }
  42. CSxApwComPtr(const CSxApwComPtr& that) : Base(that) { }
  43. CSxApwComPtr(T* pt = NULL) : Base(pt) { }
  44. void operator=(T* pt) { Base::operator=(pt); }
  45. T* operator->() const { return Base::operator->(); }
  46. CSmartPointerPointerOrDumbPointerPointerOrVoidPointerPointer<T> operator&()
  47. {
  48. return CSmartPointerPointerOrDumbPointerPointerOrVoidPointerPointer<T>(this);
  49. }
  50. };