scoped_hstring.h 1.1 KB

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