Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions strings/base_reference_produce.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<GUID>
{
static auto make(GUID const& value) { return Windows::Foundation::PropertyValue::CreateGuid(value); }
};
#endif

template <>
struct reference_traits<Windows::Foundation::DateTime>
{
Expand Down Expand Up @@ -291,6 +299,12 @@ WINRT_EXPORT namespace winrt
return static_cast<T>(value.as<Windows::Foundation::IReference<std::underlying_type_t<T>>>().Value());
}
}
#ifdef __IUnknown_INTERFACE_DEFINED__
else if constexpr (std::is_same_v<T, GUID>)
{
return value.as<Windows::Foundation::IReference<guid>>().Value();
}
#endif
else
{
return value.as<Windows::Foundation::IReference<T>>().Value();
Expand Down Expand Up @@ -335,6 +349,15 @@ WINRT_EXPORT namespace winrt
return static_cast<T>(temp.Value());
}
}
#ifdef __IUnknown_INTERFACE_DEFINED__
else if constexpr (std::is_same_v<T, GUID>)
{
if (auto temp = value.try_as<Windows::Foundation::IReference<guid>>())
{
return temp.Value();
}
}
#endif
else
{
if (auto temp = value.try_as<Windows::Foundation::IReference<T>>())
Expand Down
22 changes: 22 additions & 0 deletions test/test/box_guid.cpp
Original file line number Diff line number Diff line change
@@ -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<winrt::guid>(box_a);
GUID unbox_b = winrt::unbox_value<GUID>(box_a);

REQUIRE(unbox_a == winrt_guid);
REQUIRE(unbox_b == sdk_guid);

unbox_a = winrt::unbox_value_or<winrt::guid>(box_a, winrt::guid{});
unbox_b = winrt::unbox_value_or<GUID>(box_a, GUID{});

REQUIRE(unbox_a == winrt_guid);
REQUIRE(unbox_b == sdk_guid);
}
1 change: 1 addition & 0 deletions test/test/test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
<ClCompile Include="async_auto_cancel.cpp" />
<ClCompile Include="async_cancel_callback.cpp" />
<ClCompile Include="async_check_cancel.cpp" />
<ClCompile Include="box_guid.cpp" />
<ClCompile Include="error_info.cpp" />
<ClCompile Include="event_deferral.cpp" />
<ClCompile Include="async_local.cpp" />
Expand Down