headers: Add more Set member template in HString class
This fixes the following compiler error with gecko.
mozilla-unified/widget/windows/ToastNotification.cpp:832:14: error: no matching member function for call to 'Set'
832 | hr = aumid.Set(mAumid.ref().get());
| ~~~~~~^~~
corewrappers.h:58:25: note: candidate function not viable: no known conversion from
'typename raw_type<char16_t, int>::type' (aka 'char16ptr_t') to 'const HSTRING' (aka 'HSTRING__ *const') for 1st argument
corewrappers.h:53:25: note: candidate function not viable: requires 2 arguments, but 1 was provided
Signed-off-by: Biswapriyo Nath <nathbappai@gmail.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-headers/include/wrl/wrappers/corewrappers.h b/mingw-w64-headers/include/wrl/wrappers/corewrappers.h
index ca175f5..182d4b0 100644
--- a/mingw-w64-headers/include/wrl/wrappers/corewrappers.h
+++ b/mingw-w64-headers/include/wrl/wrappers/corewrappers.h
@@ -7,6 +7,8 @@
#ifndef _WRL_COREWRAPPERS_H_
#define _WRL_COREWRAPPERS_H_
+#include <type_traits>
+
#include <windows.h>
#include <intsafe.h>
#include <winstring.h>
@@ -55,6 +57,37 @@
return ::WindowsCreateString(s, l, &hstr_);
}
+ template <size_t s>
+ HRESULT Set(const wchar_t (&str)[s]) throw() {
+ static_assert(static_cast<size_t>(static_cast<UINT32>(s - 1)) == s - 1, "mismatch string length");
+ return Set(str, s - 1);
+ }
+
+ template <size_t s>
+ HRESULT Set(wchar_t (&strRef)[s]) throw() {
+ const wchar_t *str = static_cast<const wchar_t *>(strRef);
+ unsigned int l;
+ HRESULT hr = SizeTToUInt32(::wcslen(str), &l);
+ if (SUCCEEDED(hr))
+ hr = Set(str, l);
+ return hr;
+ }
+
+ template <typename T>
+ HRESULT Set(const T& s, typename ::std::enable_if<::std::is_convertible<const T&, const wchar_t *>::value, ::Microsoft::WRL::Details::Dummy>::type = ::Microsoft::WRL::Details::Dummy()) throw() {
+ HRESULT hr = S_OK;
+ const wchar_t *str = static_cast<PCWSTR>(s);
+ if (str != nullptr) {
+ unsigned int l;
+ hr = SizeTToUInt32(::wcslen(str), &l);
+ if (SUCCEEDED(hr))
+ hr = Set(str, l);
+ }
+ else
+ hr = Set(L"", 0);
+ return hr;
+ }
+
HRESULT Set(const HSTRING& s) throw() {
HRESULT hr = S_OK;
if (s == nullptr || s != hstr_) {