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.

82 lines
1.2 KiB

  1. /*++
  2. Copyright Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. autobstr.H
  5. Author:
  6. dpravat
  7. History:
  8. --*/
  9. #ifndef _AUTOBSTR_H_
  10. #define _AUTOBSTR_H_
  11. #include <algorithm>
  12. #include <corex.h>
  13. class auto_bstr
  14. {
  15. public:
  16. explicit auto_bstr (BSTR str = 0) ;
  17. auto_bstr (auto_bstr& ) ;
  18. ~auto_bstr();
  19. BSTR release();
  20. BSTR get() const ;
  21. size_t len() const { return SysStringLen (bstr_);};
  22. auto_bstr& operator=(auto_bstr&);
  23. private:
  24. BSTR bstr_;
  25. };
  26. inline
  27. auto_bstr::auto_bstr (auto_bstr& other)
  28. {
  29. bstr_ = other.release();
  30. };
  31. inline
  32. auto_bstr::auto_bstr (BSTR str)
  33. {
  34. bstr_ = str;
  35. };
  36. inline
  37. auto_bstr::~auto_bstr()
  38. { SysFreeString (bstr_);};
  39. inline BSTR
  40. auto_bstr::release()
  41. { BSTR _tmp = bstr_;
  42. bstr_ = 0;
  43. return _tmp; };
  44. inline BSTR
  45. auto_bstr::get() const
  46. { return bstr_; };
  47. inline
  48. auto_bstr& auto_bstr::operator=(auto_bstr& src)
  49. {
  50. auto_bstr tmp(src);
  51. std::swap(bstr_, tmp.bstr_);
  52. return *this;
  53. };
  54. inline auto_bstr clone(LPCWSTR str = NULL)
  55. {
  56. BSTR bstr = SysAllocString(str);
  57. if (bstr == 0 && str != 0)
  58. throw CX_MemoryException();
  59. return auto_bstr (bstr);
  60. }
  61. #endif /*_AUTOBSTR_H_*/