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.

82 lines
1.3 KiB

  1. #pragma once
  2. //////////////////////////////////////////////////////////////////////////////////////////
  3. //////////////////////////////////////////////////////////////////////////////////////////
  4. // auto_pv- auto PROPVARIANT releaser.
  5. //
  6. // pretty minimal functionality, designed to provide auto release only
  7. //
  8. class auto_pv : public ::tagPROPVARIANT {
  9. public:
  10. // Constructors
  11. //
  12. auto_pv() throw();
  13. // Destructor
  14. //
  15. ~auto_pv() throw();
  16. // Low-level operations
  17. //
  18. void Clear() throw();
  19. void Attach(PROPVARIANT& varSrc) throw();
  20. PROPVARIANT Detach() throw();
  21. bool Ownership(bool fOwns)
  22. { return _Owns = fOwns; }
  23. protected:
  24. bool _Owns;
  25. };
  26. // Default constructor
  27. //
  28. inline auto_pv::auto_pv() throw()
  29. : _Owns(true)
  30. {
  31. ::PropVariantInit(this);
  32. }
  33. // destructor
  34. inline auto_pv::~auto_pv() throw()
  35. {
  36. if(_Owns)
  37. ::PropVariantClear(this);
  38. else
  39. ::PropVariantInit(this);
  40. }
  41. // Clear the auto_var
  42. //
  43. inline void auto_pv::Clear() throw()
  44. {
  45. if(_Owns)
  46. ::PropVariantClear(this);
  47. else
  48. ::PropVariantInit(this);
  49. }
  50. inline void auto_pv::Attach(PROPVARIANT& varSrc) throw()
  51. {
  52. //
  53. // Free up previous VARIANT
  54. //
  55. Clear();
  56. //
  57. // Give control of data to auto_var
  58. //
  59. memcpy(this, &varSrc, sizeof(varSrc));
  60. varSrc.vt = VT_EMPTY;
  61. }
  62. inline PROPVARIANT auto_pv::Detach() throw()
  63. {
  64. PROPVARIANT varResult = *this;
  65. this->vt = VT_EMPTY;
  66. return varResult;
  67. }