#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(STATUS_INVALID_PARAMETER), EXCEPTION_NONCONTINUABLE, 0, nullptr); } template 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(STATUS_INVALID_PARAMETER), EXCEPTION_NONCONTINUABLE, 0, nullptr); } template StringReferenceWrapper(_In_reads_(_) wchar_t(&stringRef)[_]) throw() { UINT32 length; HRESULT hr = SizeTToUInt32(wcslen(stringRef), &length); if (FAILED(hr)) { RaiseException(static_cast(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_