1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_WIN_SCOPED_PROPVARIANT_H_ 6 #define BASE_WIN_SCOPED_PROPVARIANT_H_ 7 8 #include <propidl.h> 9 10 #include "base/check_op.h" 11 #include "base/macros.h" 12 13 namespace base { 14 namespace win { 15 16 // A PROPVARIANT that is automatically initialized and cleared upon respective 17 // construction and destruction of this class. 18 class ScopedPropVariant { 19 public: ScopedPropVariant()20 ScopedPropVariant() { PropVariantInit(&pv_); } 21 ~ScopedPropVariant()22 ~ScopedPropVariant() { Reset(); } 23 24 // Returns a pointer to the underlying PROPVARIANT for use as an out param in 25 // a function call. Receive()26 PROPVARIANT* Receive() { 27 DCHECK_EQ(pv_.vt, VT_EMPTY); 28 return &pv_; 29 } 30 31 // Clears the instance to prepare it for re-use (e.g., via Receive). Reset()32 void Reset() { 33 if (pv_.vt != VT_EMPTY) { 34 HRESULT result = PropVariantClear(&pv_); 35 DCHECK_EQ(result, S_OK); 36 } 37 } 38 get()39 const PROPVARIANT& get() const { return pv_; } ptr()40 const PROPVARIANT* ptr() const { return &pv_; } 41 42 private: 43 PROPVARIANT pv_; 44 45 // Comparison operators for ScopedPropVariant are not supported at this point. 46 bool operator==(const ScopedPropVariant&) const; 47 bool operator!=(const ScopedPropVariant&) const; 48 DISALLOW_COPY_AND_ASSIGN(ScopedPropVariant); 49 }; 50 51 } // namespace win 52 } // namespace base 53 54 #endif // BASE_WIN_SCOPED_PROPVARIANT_H_ 55