diff --git a/strings/base_activation.h b/strings/base_activation.h index e6bf74c74..543bbfb43 100644 --- a/strings/base_activation.h +++ b/strings/base_activation.h @@ -18,6 +18,12 @@ namespace winrt::impl using library_handle = handle_type; + inline int32_t __stdcall fallback_RoGetActivationFactory(void*, guid const&, void** factory) noexcept + { + *factory = nullptr; + return error_class_not_available; + } + template hresult get_runtime_activation_factory(param::hstring const& name, void** result) noexcept { @@ -27,14 +33,7 @@ namespace winrt::impl } static int32_t(__stdcall * handler)(void* classId, guid const& iid, void** factory) noexcept; - - impl::load_runtime_function("RoGetActivationFactory", handler, - [](void*, guid const&, void** factory) noexcept -> int32_t - { - *factory = nullptr; - return error_class_not_available; - }); - + impl::load_runtime_function("RoGetActivationFactory", handler, fallback_RoGetActivationFactory); hresult hr = handler(*(void**)(&name), guid_of(), result); if (hr == impl::error_not_initialized) diff --git a/strings/base_agile_ref.h b/strings/base_agile_ref.h index dc809e489..5411d42f3 100644 --- a/strings/base_agile_ref.h +++ b/strings/base_agile_ref.h @@ -119,36 +119,35 @@ namespace winrt::impl result = fallback; } - inline hresult get_agile_reference(winrt::guid const& iid, void* object, void** reference) noexcept + inline int32_t __stdcall fallback_RoGetAgileReference(uint32_t, winrt::guid const& iid, void* object, void** reference) noexcept { - static int32_t(__stdcall * handler)(uint32_t options, winrt::guid const& iid, void* object, void** reference) noexcept; - - load_runtime_function("RoGetAgileReference", handler, - [](uint32_t, winrt::guid const& iid, void* object, void** reference) noexcept -> int32_t - { - *reference = nullptr; - static constexpr guid git_clsid{ 0x00000323, 0x0000, 0x0000, { 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 } }; + *reference = nullptr; + static constexpr guid git_clsid{ 0x00000323, 0x0000, 0x0000, { 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 } }; - com_ptr git; - hresult hr = WINRT_IMPL_CoCreateInstance(git_clsid, nullptr, 1 /*CLSCTX_INPROC_SERVER*/, guid_of(), git.put_void()); + com_ptr git; + hresult hr = WINRT_IMPL_CoCreateInstance(git_clsid, nullptr, 1 /*CLSCTX_INPROC_SERVER*/, guid_of(), git.put_void()); - if (hr < 0) - { - return hr; - } + if (hr < 0) + { + return hr; + } - uint32_t cookie{}; - hr = git->RegisterInterfaceInGlobal(object, iid, &cookie); + uint32_t cookie{}; + hr = git->RegisterInterfaceInGlobal(object, iid, &cookie); - if (hr < 0) - { - return hr; - } + if (hr < 0) + { + return hr; + } - *reference = new agile_ref_fallback(std::move(git), cookie); - return 0; - }); + *reference = new agile_ref_fallback(std::move(git), cookie); + return 0; + } + inline hresult get_agile_reference(winrt::guid const& iid, void* object, void** reference) noexcept + { + static int32_t(__stdcall * handler)(uint32_t options, winrt::guid const& iid, void* object, void** reference) noexcept; + load_runtime_function("RoGetAgileReference", handler, fallback_RoGetAgileReference); return handler(0, iid, object, reference); } } diff --git a/strings/base_error.h b/strings/base_error.h index f75dbbdd1..e08075bf7 100644 --- a/strings/base_error.h +++ b/strings/base_error.h @@ -158,6 +158,11 @@ namespace winrt::impl hstring const m_message; atomic_ref_count m_references{ 1 }; }; + + [[noreturn]] inline void __stdcall fallback_RoFailFastWithErrorContext(int32_t) noexcept + { + std::terminate(); + } } WINRT_EXPORT namespace winrt @@ -289,19 +294,19 @@ WINRT_EXPORT namespace winrt private: + static int32_t __stdcall fallback_RoOriginateLanguageException(int32_t error, void* message, void*) noexcept + { + com_ptr info(new (std::nothrow) impl::error_info_fallback(error, message), take_ownership_from_abi); + WINRT_VERIFY_(0, WINRT_IMPL_SetErrorInfo(0, info.get())); + return 1; + } + void originate(hresult const code, void* message) noexcept { static int32_t(__stdcall* handler)(int32_t error, void* message, void* exception) noexcept; - - impl::load_runtime_function("RoOriginateLanguageException", handler, - [](int32_t error, void* message, void*) noexcept - { - com_ptr info(new (std::nothrow) impl::error_info_fallback(error, message), take_ownership_from_abi); - WINRT_VERIFY_(0, WINRT_IMPL_SetErrorInfo(0, info.get())); - return 1; - }); - + impl::load_runtime_function("RoOriginateLanguageException", handler, fallback_RoOriginateLanguageException); WINRT_VERIFY(handler(code, message, nullptr)); + com_ptr info; WINRT_VERIFY_(0, WINRT_IMPL_GetErrorInfo(0, info.put_void())); WINRT_VERIFY(info.try_as(m_info)); @@ -563,13 +568,7 @@ WINRT_EXPORT namespace winrt inline void terminate() noexcept { static void(__stdcall * handler)(int32_t) noexcept; - - impl::load_runtime_function("RoFailFastWithErrorContext", handler, - [](int32_t) noexcept - { - std::terminate(); - }); - + impl::load_runtime_function("RoFailFastWithErrorContext", handler, impl::fallback_RoFailFastWithErrorContext); handler(to_hresult()); } } diff --git a/strings/base_events.h b/strings/base_events.h index 6365933f4..b20dd4a24 100644 --- a/strings/base_events.h +++ b/strings/base_events.h @@ -335,6 +335,11 @@ namespace winrt::impl return { new(raw) event_array(capacity), take_ownership_from_abi }; } + inline int32_t __stdcall fallback_RoTransformError(int32_t, int32_t, void*) noexcept + { + return 1; + } + template bool invoke(Delegate const& delegate, Arg const&... args) noexcept { @@ -347,13 +352,7 @@ namespace winrt::impl int32_t const code = to_hresult(); static int32_t(__stdcall * handler)(int32_t, int32_t, void*) noexcept; - - impl::load_runtime_function("RoTransformError", handler, - [](int32_t, int32_t, void*) noexcept - { - return 1; - }); - + impl::load_runtime_function("RoTransformError", handler, fallback_RoTransformError); handler(code, 0, nullptr); if (code == static_cast(0x80010108) || // RPC_E_DISCONNECTED