diff --git a/cppwinrt/code_writers.h b/cppwinrt/code_writers.h index fc5081bef..2956a42b7 100644 --- a/cppwinrt/code_writers.h +++ b/cppwinrt/code_writers.h @@ -642,7 +642,7 @@ namespace cppwinrt { case param_category::object_type: case param_category::string_type: - w.write("*(void**)(&%)", param_name); + w.write("*impl::abi_cast(%)", param_name); break; case param_category::generic_type: case param_category::struct_type: @@ -2664,7 +2664,7 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable } template <%> auto %<%>::operator()(%) const {% - check_hresult((*(impl::abi_t<%<%>>**)this)->Invoke(%));% + check_hresult((*impl::abi_t_abi_cast(*this))->Invoke(%));% } )"; @@ -2713,8 +2713,6 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable bind_list(", ", generics), bind(signature), bind(signature, true), - type_name, - bind_list(", ", generics), bind(signature, false), bind(signature)); } @@ -2756,7 +2754,7 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable } inline auto %::operator()(%) const {% - check_hresult((*(impl::abi_t<%>**)this)->Invoke(%));% + check_hresult((*impl::abi_t_abi_cast(*this))->Invoke(%));% } )"; @@ -2786,7 +2784,6 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable type_name, bind(signature), bind(signature, true), - type_name, bind(signature, false), bind(signature)); } @@ -3032,7 +3029,7 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable { auto format = R"( inline %::operator impl::producer_ref<%> const() const noexcept { - return { (*(impl::abi_t<%>**)this)->base_%() }; + return { (*impl::abi_t_abi_cast(*static_cast<% const*>(this)))->base_%() }; } )"; diff --git a/strings/base_activation.h b/strings/base_activation.h index 1a195d865..4913f1109 100644 --- a/strings/base_activation.h +++ b/strings/base_activation.h @@ -23,10 +23,10 @@ namespace winrt::impl { if (winrt_activation_handler) { - return winrt_activation_handler(*(void**)(&name), guid, result); + return winrt_activation_handler(*impl::abi_cast(name), guid, result); } - hresult hr = WINRT_IMPL_RoGetActivationFactory(*(void**)(&name), guid, result); + hresult hr = WINRT_IMPL_RoGetActivationFactory(*impl::abi_cast(name), guid, result); if (hr == impl::error_not_initialized) { @@ -39,7 +39,7 @@ namespace winrt::impl void* cookie; usage(&cookie); - hr = WINRT_IMPL_RoGetActivationFactory(*(void**)(&name), guid, result); + hr = WINRT_IMPL_RoGetActivationFactory(*impl::abi_cast(name), guid, result); } if (hr == 0) @@ -74,7 +74,7 @@ namespace winrt::impl com_ptr> library_factory; - if (0 != library_call(*(void**)(&name), library_factory.put_void())) + if (0 != library_call(*impl::abi_cast(name), library_factory.put_void())) { continue; } @@ -114,75 +114,43 @@ WINRT_EXPORT namespace winrt } } +namespace winrt::impl +{ + #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" #endif -#if defined(__GNUC__) && defined(__aarch64__) -#define WINRT_IMPL_INTERLOCKED_READ_MEMORY_BARRIER __asm__ __volatile__ ("dmb ish"); -#elif defined _M_ARM64 -#define WINRT_IMPL_INTERLOCKED_READ_MEMORY_BARRIER (__dmb(_ARM64_BARRIER_ISH)); -#endif - -namespace winrt::impl -{ - inline std::int32_t interlocked_read_32(std::int32_t const volatile* target) noexcept + template + T* interlocked_read_pointer(T* const volatile* target) noexcept { -#if defined _M_IX86 || defined _M_X64 - std::int32_t const result = *target; +#if defined(_M_IX86) || defined(_M_X64) + auto const result = *reinterpret_cast(target); _ReadWriteBarrier(); - return result; -#elif defined _M_ARM64 + return reinterpret_cast(result); +#elif defined(_M_ARM64) #if defined(__GNUC__) - std::int32_t const result = *target; + auto const result = *reinterpret_cast(target); #else - std::int32_t const result = __iso_volatile_load32(reinterpret_cast(target)); + auto const result = static_cast( + __iso_volatile_load64(reinterpret_cast(target))); #endif - WINRT_IMPL_INTERLOCKED_READ_MEMORY_BARRIER - return result; -#else -#error Unsupported architecture -#endif - } - -#if defined _WIN64 - inline std::int64_t interlocked_read_64(std::int64_t const volatile* target) noexcept - { -#if defined _M_X64 - std::int64_t const result = *target; - _ReadWriteBarrier(); - return result; -#elif defined _M_ARM64 -#if defined(__GNUC__) - std::int64_t const result = *target; -#else - std::int64_t const result = __iso_volatile_load64(target); +#if defined(__GNUC__) && defined(__aarch64__) + __asm__ __volatile__ ("dmb ish"); +#elif defined(_M_ARM64) + (__dmb(_ARM64_BARRIER_ISH)); #endif - WINRT_IMPL_INTERLOCKED_READ_MEMORY_BARRIER - return result; + return reinterpret_cast(result); #else #error Unsupported architecture #endif } -#endif - -#undef WINRT_IMPL_INTERLOCKED_READ_MEMORY_BARRIER #ifdef __clang__ #pragma clang diagnostic pop #endif - template - T* interlocked_read_pointer(T* const volatile* target) noexcept - { -#ifdef _WIN64 - return (T*)interlocked_read_64((std::int64_t*)target); -#else - return (T*)interlocked_read_32((std::int32_t*)target); -#endif - } - #ifdef _WIN64 inline constexpr std::uint32_t memory_allocation_alignment{ 16 }; #ifdef _MSC_VER @@ -282,20 +250,20 @@ namespace winrt::impl object_and_count current_value{ pointer_value, 0 }; -#if defined _WIN64 +#if defined(_WIN64) #if defined(__GNUC__) - bool exchanged = __sync_bool_compare_and_swap((__int128*)this, *(__int128*)¤t_value, (__int128)0); + bool exchanged = __sync_bool_compare_and_swap(reinterpret_cast<__int128*>(this), __builtin_bit_cast(__int128, current_value), (__int128)0); #else - bool exchanged = 1 == _InterlockedCompareExchange128((std::int64_t*)this, 0, 0, (std::int64_t*)¤t_value); + bool exchanged = 1 == _InterlockedCompareExchange128(reinterpret_cast(this), 0, 0, reinterpret_cast(¤t_value)); #endif if (exchanged) { pointer_value->Release(); } #else - std::int64_t const result = _InterlockedCompareExchange64((std::int64_t*)this, 0, *(std::int64_t*)¤t_value); + std::int64_t const result = _InterlockedCompareExchange64(reinterpret_cast(this), 0, __builtin_bit_cast(std::int64_t, current_value)); - if (result == *(std::int64_t*)¤t_value) + if (result == __builtin_bit_cast(std::int64_t, current_value)) { pointer_value->Release(); } @@ -305,7 +273,7 @@ namespace winrt::impl static_assert(std::is_standard_layout_v); -#if !defined _M_IX86 && !defined _M_X64 && !defined _M_ARM64 +#if !defined(_M_IX86) && !defined(_M_X64) && !defined(_M_ARM64) #error Unsupported architecture: verify that zero-initialization of SLIST_HEADER is still safe #endif @@ -370,9 +338,9 @@ namespace winrt::impl { factory_count_guard const guard(m_value.count); - if (nullptr == _InterlockedCompareExchangePointer(reinterpret_cast(&m_value.object), *reinterpret_cast(&object), nullptr)) + if (nullptr == _InterlockedCompareExchangePointer(abi_cast(m_value.object), *abi_cast(object), nullptr)) { - *reinterpret_cast(&object) = nullptr; + *abi_cast(object) = nullptr; #ifndef WINRT_NO_MODULE_LOCK get_factory_cache().add(this); #endif @@ -541,7 +509,7 @@ WINRT_EXPORT namespace winrt T ActivateInstance() const { IInspectable instance; - check_hresult((*(impl::abi_t**)this)->ActivateInstance(put_abi(instance))); + check_hresult((*impl::abi_t_abi_cast(this))->ActivateInstance(put_abi(instance))); return instance.try_as(); } }; @@ -554,7 +522,7 @@ namespace winrt::impl T fast_activate(Windows::Foundation::IActivationFactory const& factory) { void* result{}; - check_hresult((*(impl::abi_t**)&factory)->ActivateInstance(&result)); + check_hresult((*impl::abi_t_abi_cast(factory))->ActivateInstance(&result)); return{ result, take_ownership_from_abi }; } } diff --git a/strings/base_agile_ref.h b/strings/base_agile_ref.h index 88fbea065..28ac91bd1 100644 --- a/strings/base_agile_ref.h +++ b/strings/base_agile_ref.h @@ -1,7 +1,7 @@ WINRT_EXPORT namespace winrt { -#if defined (WINRT_NO_MODULE_LOCK) +#if defined(WINRT_NO_MODULE_LOCK) // Defining WINRT_NO_MODULE_LOCK is appropriate for apps (executables) or pinned DLLs (that don't support unloading) // and can thus avoid the synchronization overhead imposed by the default module lock. @@ -29,7 +29,7 @@ WINRT_EXPORT namespace winrt return lock{}; } -#elif defined (WINRT_CUSTOM_MODULE_LOCK) +#elif defined(WINRT_CUSTOM_MODULE_LOCK) // When WINRT_CUSTOM_MODULE_LOCK is defined, you must provide an implementation of winrt::get_module_lock() // that returns an object that implements operator++ and operator--. diff --git a/strings/base_array.h b/strings/base_array.h index 9544dcf8c..74dac44a8 100644 --- a/strings/base_array.h +++ b/strings/base_array.h @@ -440,15 +440,17 @@ WINRT_EXPORT namespace winrt template auto get_abi(array_view object) noexcept { - auto data = object.size() ? object.data() : (T*)alignof(T); + using U = std::remove_const_t; + + auto data = object.size() ? const_cast(object.data()) : reinterpret_cast(alignof(U)); if constexpr (std::is_base_of_v) { - return (void**)data; + return impl::abi_cast(*data); } else { - return reinterpret_cast>>(const_cast*>(data)); + return reinterpret_cast>(data); } } @@ -562,21 +564,21 @@ WINRT_EXPORT namespace winrt inline hstring get_class_name(Windows::Foundation::IInspectable const& object) { void* value{}; - check_hresult((*(impl::inspectable_abi**)&object)->GetRuntimeClassName(&value)); + check_hresult(static_cast(*impl::abi_cast(object))->GetRuntimeClassName(&value)); return { value, take_ownership_from_abi }; } inline com_array get_interfaces(Windows::Foundation::IInspectable const& object) { com_array value; - check_hresult((*(impl::inspectable_abi**)&object)->GetIids(impl::put_size_abi(value), put_abi(value))); + check_hresult(static_cast(*impl::abi_cast(object))->GetIids(impl::put_size_abi(value), put_abi(value))); return value; } inline Windows::Foundation::TrustLevel get_trust_level(Windows::Foundation::IInspectable const& object) { Windows::Foundation::TrustLevel value{}; - check_hresult((*(impl::inspectable_abi**)&object)->GetTrustLevel(&value)); + check_hresult(static_cast(*impl::abi_cast(object))->GetTrustLevel(&value)); return value; } } diff --git a/strings/base_collections_input_iterable.h b/strings/base_collections_input_iterable.h index e75211c30..a8eb6bef6 100644 --- a/strings/base_collections_input_iterable.h +++ b/strings/base_collections_input_iterable.h @@ -226,7 +226,7 @@ WINRT_EXPORT namespace winrt::param template auto get_abi(iterable const& object) noexcept { - return *(void**)(&object); + return *impl::abi_cast(object); } template @@ -346,6 +346,6 @@ WINRT_EXPORT namespace winrt::param template auto get_abi(async_iterable const& object) noexcept { - return *(void**)(&object); + return *impl::abi_cast(object); } } diff --git a/strings/base_collections_input_map.h b/strings/base_collections_input_map.h index b33975fe6..936071921 100644 --- a/strings/base_collections_input_map.h +++ b/strings/base_collections_input_map.h @@ -106,6 +106,6 @@ WINRT_EXPORT namespace winrt::param template auto get_abi(map const& object) noexcept { - return *(void**)(&object); + return *impl::abi_cast(object); } } diff --git a/strings/base_collections_input_map_view.h b/strings/base_collections_input_map_view.h index bfd8d82a9..22ec84364 100644 --- a/strings/base_collections_input_map_view.h +++ b/strings/base_collections_input_map_view.h @@ -148,7 +148,7 @@ WINRT_EXPORT namespace winrt::param template auto get_abi(map_view const& object) noexcept { - return *(void**)(&object); + return *impl::abi_cast(object); } template @@ -214,6 +214,6 @@ WINRT_EXPORT namespace winrt::param template auto get_abi(async_map_view const& object) noexcept { - return *(void**)(&object); + return *impl::abi_cast(object); } } diff --git a/strings/base_collections_input_vector.h b/strings/base_collections_input_vector.h index b5b76de38..c2cdf2fcb 100644 --- a/strings/base_collections_input_vector.h +++ b/strings/base_collections_input_vector.h @@ -94,6 +94,6 @@ WINRT_EXPORT namespace winrt::param template auto get_abi(vector const& object) noexcept { - return *(void**)(&object); + return *impl::abi_cast(object); } } diff --git a/strings/base_collections_input_vector_view.h b/strings/base_collections_input_vector_view.h index 3793e239a..40bafacad 100644 --- a/strings/base_collections_input_vector_view.h +++ b/strings/base_collections_input_vector_view.h @@ -143,7 +143,7 @@ WINRT_EXPORT namespace winrt::param template auto get_abi(vector_view const& object) noexcept { - return *(void**)(&object); + return *impl::abi_cast(object); } template @@ -203,6 +203,6 @@ WINRT_EXPORT namespace winrt::param template auto get_abi(async_vector_view const& object) noexcept { - return *(void**)(&object); + return *impl::abi_cast(object); } } diff --git a/strings/base_coroutine_foundation.h b/strings/base_coroutine_foundation.h index 4f1c8d0b6..df4666856 100644 --- a/strings/base_coroutine_foundation.h +++ b/strings/base_coroutine_foundation.h @@ -860,9 +860,9 @@ WINRT_EXPORT namespace winrt void operator()(T const& sender, Windows::Foundation::AsyncStatus operation_status) noexcept { - auto sender_abi = *(impl::unknown_abi**)&sender; + auto sender_abi = static_cast(*impl::abi_cast(sender)); - if (nullptr == _InterlockedCompareExchangePointer(reinterpret_cast(&result), sender_abi, nullptr)) + if (nullptr == _InterlockedCompareExchangePointer(impl::abi_cast(result), sender_abi, nullptr)) { sender_abi->AddRef(); status = operation_status; diff --git a/strings/base_delegate.h b/strings/base_delegate.h index 1cfe58710..fbaa89e6f 100644 --- a/strings/base_delegate.h +++ b/strings/base_delegate.h @@ -203,7 +203,7 @@ namespace winrt::impl auto operator()(Args const& ... args) const { - return (*(variadic_delegate_abi * *)this)->invoke(args...); + return (*reinterpret_cast **>(const_cast*>(this)))->invoke(args...); } private: diff --git a/strings/base_events.h b/strings/base_events.h index f7e2e6976..30c56824a 100644 --- a/strings/base_events.h +++ b/strings/base_events.h @@ -58,7 +58,7 @@ WINRT_EXPORT namespace winrt { if (I object = std::exchange(m_object, {}).get()) { - ((*reinterpret_cast**>(&object))->*(m_method))(m_token); + ((*impl::abi_t_abi_cast(object))->*(m_method))(m_token); } } @@ -113,7 +113,7 @@ WINRT_EXPORT namespace winrt { if (auto object = std::exchange(m_object, {})) { - ((*reinterpret_cast**>(&object))->*(m_method))(m_token); + ((*impl::abi_t_abi_cast(object))->*(m_method))(m_token); } } @@ -185,7 +185,7 @@ namespace winrt::impl { if (object) { - ((*reinterpret_cast**>(&object))->*(Method))(m_token); + ((*impl::abi_t_abi_cast(object))->*(Method))(m_token); } } @@ -245,7 +245,7 @@ namespace winrt::impl { if (object) { - ((*reinterpret_cast**>(&object))->*(Method))(m_token); + ((*impl::abi_t_abi_cast(object))->*(Method))(m_token); } } private: diff --git a/strings/base_implements.h b/strings/base_implements.h index 7edf32149..5434d8b3f 100644 --- a/strings/base_implements.h +++ b/strings/base_implements.h @@ -120,19 +120,19 @@ namespace winrt::impl operator I() const noexcept { I result{ nullptr }; - copy_from_abi(result, (produce::type>*)this); + copy_from_abi(result, reinterpret_cast::type>*>(const_cast(this))); return result; } #else operator producer_ref const() const noexcept { - return { (produce::type>*)this }; + return { reinterpret_cast::type>*>(const_cast(this)) }; } #endif operator producer_vtable const() const noexcept { - return { (void*)this }; + return { reinterpret_cast(const_cast(this)) }; } }; @@ -263,7 +263,7 @@ WINRT_EXPORT namespace winrt template impl::abi_t* to_abi(impl::producer_convert const* from) noexcept { - return reinterpret_cast*>((impl::producer>*)from); + return reinterpret_cast*>(const_cast*>(from)); } } diff --git a/strings/base_macros.h b/strings/base_macros.h index 3dc01fa2d..7e888859d 100644 --- a/strings/base_macros.h +++ b/strings/base_macros.h @@ -13,7 +13,7 @@ #endif -#define WINRT_IMPL_SHIM(...) (*(abi_t<__VA_ARGS__>**)&static_cast<__VA_ARGS__ const&>(static_cast(*this))) +#define WINRT_IMPL_SHIM(...) (*impl::abi_t_abi_cast(static_cast<__VA_ARGS__ const&>(static_cast(*this)))) #ifdef _MSC_VER // Note: this is a workaround for a false-positive warning produced by the Visual C++ 15.9 compiler. diff --git a/strings/base_meta.h b/strings/base_meta.h index 7dbb4c386..078b5fa74 100644 --- a/strings/base_meta.h +++ b/strings/base_meta.h @@ -76,6 +76,12 @@ namespace winrt::impl template using abi_t = typename abi::type; + template + auto abi_t_abi_cast(T const& value) noexcept + { + return reinterpret_cast**>(const_cast(&value)); + } + template struct consume; diff --git a/strings/base_natvis.h b/strings/base_natvis.h index 60c5f5548..aaebf2f98 100644 --- a/strings/base_natvis.h +++ b/strings/base_natvis.h @@ -55,10 +55,10 @@ namespace winrt::impl if ((WINRT_IMPL_VirtualQuery(object, &info, sizeof(info)) != 0) && ((info.protect & 0xEE) != 0)) { inspectable_abi* pinsp; - if (((unknown_abi*)object)->QueryInterface(iid, reinterpret_cast(&pinsp)) == 0) + if ((reinterpret_cast(object))->QueryInterface(iid, reinterpret_cast(&pinsp)) == 0) { static const int IInspectable_vtbl_size = 6; - auto vtbl = *(void***)pinsp; + auto vtbl = *reinterpret_cast(pinsp); // validate vtbl pointer is readable if ((WINRT_IMPL_VirtualQuery(vtbl, &info, sizeof(info)) != 0) && ((info.protect & 0xEE) != 0)) { diff --git a/strings/base_reference_produce.h b/strings/base_reference_produce.h index 2820aff50..b6f854c9a 100644 --- a/strings/base_reference_produce.h +++ b/strings/base_reference_produce.h @@ -552,7 +552,7 @@ WINRT_EXPORT namespace winrt } } - return *(hstring*)(&default_value); + return *reinterpret_cast(&default_value); } template , int> = 0> diff --git a/strings/base_string.h b/strings/base_string.h index c2ba6c742..77a66cab2 100644 --- a/strings/base_string.h +++ b/strings/base_string.h @@ -388,13 +388,13 @@ WINRT_EXPORT namespace winrt inline void* get_abi(hstring const& object) noexcept { - return *(void**)(&object); + return *impl::abi_cast(object); } inline void** put_abi(hstring& object) noexcept { object.clear(); - return reinterpret_cast(&object); + return impl::abi_cast(object); } inline void attach_abi(hstring& object, void* value) noexcept @@ -406,7 +406,7 @@ WINRT_EXPORT namespace winrt inline void* detach_abi(hstring& object) noexcept { void* temp = get_abi(object); - *reinterpret_cast(&object) = nullptr; + *impl::abi_cast(object) = nullptr; return temp; } @@ -527,7 +527,7 @@ namespace winrt::impl object = nullptr; } - return (void**)(&object); + return impl::abi_cast(object); } template diff --git a/strings/base_string_input.h b/strings/base_string_input.h index 5ac0221f6..f1c8b912d 100644 --- a/strings/base_string_input.h +++ b/strings/base_string_input.h @@ -61,7 +61,7 @@ WINRT_EXPORT namespace winrt::param inline void* get_abi(hstring const& object) noexcept { - return *(void**)(&object); + return *impl::abi_cast(object); } } diff --git a/strings/base_windows.h b/strings/base_windows.h index 21c4163e5..2bc5f23cc 100644 --- a/strings/base_windows.h +++ b/strings/base_windows.h @@ -294,6 +294,15 @@ WINRT_EXPORT namespace winrt::Windows::Foundation }; } +namespace winrt::impl +{ + template + void** abi_cast(T const& object) noexcept + { + return reinterpret_cast(const_cast(&object)); + } +} + WINRT_EXPORT namespace winrt { template , int> = 0> @@ -335,13 +344,13 @@ WINRT_EXPORT namespace winrt inline void* get_abi(Windows::Foundation::IUnknown const& object) noexcept { - return *(void**)(&object); + return *impl::abi_cast(object); } inline void** put_abi(Windows::Foundation::IUnknown& object) noexcept { object = nullptr; - return reinterpret_cast(&object); + return impl::abi_cast(object); } inline void attach_abi(Windows::Foundation::IUnknown& object, void* value) noexcept @@ -353,14 +362,14 @@ WINRT_EXPORT namespace winrt inline void* detach_abi(Windows::Foundation::IUnknown& object) noexcept { void* temp = get_abi(object); - *reinterpret_cast(&object) = nullptr; + *impl::abi_cast(object) = nullptr; return temp; } inline void* detach_abi(Windows::Foundation::IUnknown&& object) noexcept { void* temp = get_abi(object); - *reinterpret_cast(&object) = nullptr; + *impl::abi_cast(object) = nullptr; return temp; } @@ -459,16 +468,16 @@ WINRT_EXPORT namespace winrt::impl { if constexpr (!std::is_same_v) { - winrt::hresult _winrt_cast_result_code; - auto const _winrt_casted_result = try_as_with_reason(d, _winrt_cast_result_code); - check_hresult(_winrt_cast_result_code); - auto const _winrt_abi_type = *(abi_t**)&_winrt_casted_result; - (_winrt_abi_type->*mptr)(std::forward(args)...); + winrt::hresult winrt_cast_result_code; + auto const winrt_casted_result = try_as_with_reason(d, winrt_cast_result_code); + check_hresult(winrt_cast_result_code); + auto const winrt_abi_type = *abi_t_abi_cast(static_cast(winrt_casted_result)); + (winrt_abi_type->*mptr)(std::forward(args)...); } else { - auto const _winrt_abi_type = *(abi_t**)d; - (_winrt_abi_type->*mptr)(std::forward(args)...); + auto const winrt_abi_type = *abi_t_abi_cast(static_cast(d)); + (winrt_abi_type->*mptr)(std::forward(args)...); } } @@ -477,16 +486,16 @@ WINRT_EXPORT namespace winrt::impl { if constexpr (!std::is_same_v) { - winrt::hresult _winrt_cast_result_code; - auto const _winrt_casted_result = try_as_with_reason(d, _winrt_cast_result_code); - check_hresult(_winrt_cast_result_code); - auto const _winrt_abi_type = *(abi_t**)&_winrt_casted_result; - WINRT_VERIFY_(0, (_winrt_abi_type->*mptr)(std::forward(args)...)); + winrt::hresult winrt_cast_result_code; + auto const winrt_casted_result = try_as_with_reason(d, winrt_cast_result_code); + check_hresult(winrt_cast_result_code); + auto const winrt_abi_type = *abi_t_abi_cast(static_cast(winrt_casted_result)); + WINRT_VERIFY_(0, (winrt_abi_type->*mptr)(std::forward(args)...)); } else { - auto const _winrt_abi_type = *(abi_t**)d; - WINRT_VERIFY_(0, (_winrt_abi_type->*mptr)(std::forward(args)...)); + auto const winrt_abi_type = *abi_t_abi_cast(static_cast(d)); + WINRT_VERIFY_(0, (winrt_abi_type->*mptr)(std::forward(args)...)); } } @@ -495,16 +504,16 @@ WINRT_EXPORT namespace winrt::impl { if constexpr (!std::is_same_v) { - winrt::hresult _winrt_cast_result_code; - auto const _winrt_casted_result = try_as_with_reason(d, _winrt_cast_result_code); - check_hresult(_winrt_cast_result_code); - auto const _winrt_abi_type = *(abi_t**)&_winrt_casted_result; - check_hresult((_winrt_abi_type->*mptr)(std::forward(args)...)); + winrt::hresult winrt_cast_result_code; + auto const winrt_casted_result = try_as_with_reason(d, winrt_cast_result_code); + check_hresult(winrt_cast_result_code); + auto const winrt_abi_type = *abi_t_abi_cast(static_cast(winrt_casted_result)); + check_hresult((winrt_abi_type->*mptr)(std::forward(args)...)); } else { - auto const _winrt_abi_type = *(abi_t**)d; - check_hresult((_winrt_abi_type->*mptr)(std::forward(args)...)); + auto const winrt_abi_type = *abi_t_abi_cast(static_cast(d)); + check_hresult((winrt_abi_type->*mptr)(std::forward(args)...)); } } }