From 80b827bfdf231bd49f9fe1d392b06a506a98a568 Mon Sep 17 00:00:00 2001
From: Biswapriyo Nath <nathbap...@gmail.com>
Date: Mon, 7 Oct 2024 08:03:43 +0000
Subject: [PATCH] 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 <nathbap...@gmail.com>
---
 .../include/wrl/wrappers/corewrappers.h       | 33 +++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/mingw-w64-headers/include/wrl/wrappers/corewrappers.h b/mingw-w64-headers/include/wrl/wrappers/corewrappers.h
index ca175f5..993acea 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 @@ namespace Microsoft {
                     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<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_) {
-- 
2.46.2

_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to