scoped_hstring.h 1016 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) 2015 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-CHROMIUM file.
  4. #ifndef SHELL_BROWSER_WIN_SCOPED_HSTRING_H_
  5. #define SHELL_BROWSER_WIN_SCOPED_HSTRING_H_
  6. #include <hstring.h>
  7. #include <windows.h>
  8. #include <string>
  9. #include "base/macros.h"
  10. namespace electron {
  11. class ScopedHString {
  12. public:
  13. // Copy from |source|.
  14. explicit ScopedHString(const wchar_t* source);
  15. explicit ScopedHString(const std::wstring& source);
  16. // Create empty string.
  17. ScopedHString();
  18. ~ScopedHString();
  19. // Sets to |source|.
  20. void Reset();
  21. void Reset(const wchar_t* source);
  22. void Reset(const std::wstring& source);
  23. // Returns string.
  24. operator HSTRING() const { return str_; }
  25. // Whether there is a string created.
  26. bool success() const { return str_; }
  27. private:
  28. HSTRING str_;
  29. DISALLOW_COPY_AND_ASSIGN(ScopedHString);
  30. };
  31. } // namespace electron
  32. #endif // SHELL_BROWSER_WIN_SCOPED_HSTRING_H_