summaryrefslogtreecommitdiff
path: root/plugins/Toaster/src/string_reference_wrapper.h
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-07-31 22:48:44 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-07-31 22:48:44 +0000
commita08e1cf9777b4a3766c91be2685aaf37c24fbd4e (patch)
tree76f00a6a8c26c04d84f1e259fcf4bdf4b984a0d1 /plugins/Toaster/src/string_reference_wrapper.h
parentaa7b69500fc5ce34840076de537dbfab2c31ab81 (diff)
Toaster: initial commit
git-svn-id: http://svn.miranda-ng.org/main/trunk@14775 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Toaster/src/string_reference_wrapper.h')
-rw-r--r--plugins/Toaster/src/string_reference_wrapper.h54
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