diff --git a/strings/base_reference_produce.h b/strings/base_reference_produce.h index 3b0b9864b..b246f6823 100644 --- a/strings/base_reference_produce.h +++ b/strings/base_reference_produce.h @@ -197,6 +197,14 @@ namespace winrt::impl static auto make(guid const& value) { return Windows::Foundation::PropertyValue::CreateGuid(value); } }; +#ifdef __IUnknown_INTERFACE_DEFINED__ + template <> + struct reference_traits + { + static auto make(GUID const& value) { return Windows::Foundation::PropertyValue::CreateGuid(value); } + }; +#endif + template <> struct reference_traits { @@ -291,6 +299,12 @@ WINRT_EXPORT namespace winrt return static_cast(value.as>>().Value()); } } +#ifdef __IUnknown_INTERFACE_DEFINED__ + else if constexpr (std::is_same_v) + { + return value.as>().Value(); + } +#endif else { return value.as>().Value(); @@ -335,6 +349,15 @@ WINRT_EXPORT namespace winrt return static_cast(temp.Value()); } } +#ifdef __IUnknown_INTERFACE_DEFINED__ + else if constexpr (std::is_same_v) + { + if (auto temp = value.try_as>()) + { + return temp.Value(); + } + } +#endif else { if (auto temp = value.try_as>()) diff --git a/test/test/box_guid.cpp b/test/test/box_guid.cpp new file mode 100644 index 000000000..883c6e8e1 --- /dev/null +++ b/test/test/box_guid.cpp @@ -0,0 +1,22 @@ +#include "pch.h" + +TEST_CASE("box_guid") +{ + winrt::guid const winrt_guid = __uuidof(::IUnknown); + GUID const sdk_guid = winrt_guid; + + auto box_a = winrt::box_value(winrt_guid); + auto box_b = winrt::box_value(sdk_guid); + + winrt::guid unbox_a = winrt::unbox_value(box_a); + GUID unbox_b = winrt::unbox_value(box_a); + + REQUIRE(unbox_a == winrt_guid); + REQUIRE(unbox_b == sdk_guid); + + unbox_a = winrt::unbox_value_or(box_a, winrt::guid{}); + unbox_b = winrt::unbox_value_or(box_a, GUID{}); + + REQUIRE(unbox_a == winrt_guid); + REQUIRE(unbox_b == sdk_guid); +} diff --git a/test/test/test.vcxproj b/test/test/test.vcxproj index 2129464d5..89323600c 100644 --- a/test/test/test.vcxproj +++ b/test/test/test.vcxproj @@ -286,6 +286,7 @@ +