diff options
Diffstat (limited to 'plugins/Toaster/src/string_reference_wrapper.h')
-rw-r--r-- | plugins/Toaster/src/string_reference_wrapper.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/plugins/Toaster/src/string_reference_wrapper.h b/plugins/Toaster/src/string_reference_wrapper.h new file mode 100644 index 0000000000..ca0f8afd9f --- /dev/null +++ b/plugins/Toaster/src/string_reference_wrapper.h @@ -0,0 +1,54 @@ +#ifndef _STRING_WRAPPER_H_
+#define _STRING_WRAPPER_H_
+
+class StringReferenceWrapper
+{
+public:
+ StringReferenceWrapper(_In_reads_(length) PCWSTR stringRef, _In_ UINT32 length) throw()
+ {
+ HRESULT hr = WindowsCreateStringReference(stringRef, length, &_header, &_hstring);
+
+ if (FAILED(hr))
+ RaiseException(static_cast<DWORD>(STATUS_INVALID_PARAMETER), EXCEPTION_NONCONTINUABLE, 0, nullptr);
+ }
+
+ template <size_t N>
+ StringReferenceWrapper(_In_reads_(N) wchar_t const (&stringRef)[N]) throw()
+ {
+ UINT32 length = N - 1;
+ HRESULT hr = WindowsCreateStringReference(stringRef, length, &_header, &_hstring);
+
+ if (FAILED(hr))
+ RaiseException(static_cast<DWORD>(STATUS_INVALID_PARAMETER), EXCEPTION_NONCONTINUABLE, 0, nullptr);
+ }
+
+ template <size_t _>
+ StringReferenceWrapper(_In_reads_(_) wchar_t(&stringRef)[_]) throw()
+ {
+ UINT32 length;
+ HRESULT hr = SizeTToUInt32(wcslen(stringRef), &length);
+
+ if (FAILED(hr))
+ {
+ RaiseException(static_cast<DWORD>(STATUS_INVALID_PARAMETER), EXCEPTION_NONCONTINUABLE, 0, nullptr);
+ }
+
+ WindowsCreateStringReference(stringRef, length, &_header, &_hstring);
+ }
+
+ ~StringReferenceWrapper()
+ {
+ WindowsDeleteString(_hstring);
+ }
+
+ HSTRING Get() const throw()
+ {
+ return _hstring;
+ }
+
+private:
+ HSTRING _hstring;
+ HSTRING_HEADER _header;
+};
+
+#endif //_STRING_WRAPPER_H_
\ No newline at end of file |