@@ -20,10 +20,9 @@ namespace winrt::impl
2020
2121 // This function pointer will be null unless one or more translation units in a binary define WINRT_REG_FREE before
2222 // including winrt/base.h. If that is defined then the overall binary will support regfree COM activation.
23- inline hresult (*reg_free_factory_getter)(param::hstring const &, bool , guid const &, void **) = nullptr;
23+ inline hresult (*reg_free_factory_getter)(param::hstring const &, guid const &, void **) = nullptr;
2424
25- template <bool isSameInterfaceAsIActivationFactory>
26- WINRT_IMPL_NOINLINE hresult get_runtime_activation_factory_impl (param::hstring const & name, winrt::guid const & guid, void ** result) noexcept
25+ WINRT_IMPL_NOINLINE inline hresult get_runtime_activation_factory_impl (param::hstring const & name, winrt::guid const & guid, void ** result) noexcept
2726 {
2827 if (winrt_activation_handler)
2928 {
@@ -44,16 +43,20 @@ namespace winrt::impl
4443 return 0 ;
4544 }
4645
47- if (reg_free_factory_getter)
46+ // If the class is not registered, and regfree support is enabled, give that a chance to make the activation succeed.
47+ // We should not attempt to fallback to regfree for error codes besides class not registered. If the activation is out
48+ // of process then we could have RPC error codes. It would be bad if a class that should only ever be used out of proc
49+ // is erroneously activated inproc.
50+ if ((hr == error_class_not_registered) && reg_free_factory_getter)
4851 {
49- return reg_free_factory_getter (name, isSameInterfaceAsIActivationFactory, guid, result);
52+ return reg_free_factory_getter (name, guid, result);
5053 }
5154
5255 return hr;
5356 }
5457
5558#ifdef WINRT_REG_FREE
56- WINRT_IMPL_NOINLINE inline hresult reg_free_get_activation_factory (param::hstring const & name, bool isSameInterfaceAsIActivationFactory, winrt::guid const & guid, void ** result) noexcept
59+ WINRT_IMPL_NOINLINE inline hresult reg_free_get_activation_factory (param::hstring const & name, winrt::guid const & guid, void ** result) noexcept
5760 {
5861 com_ptr<IErrorInfo> error_info;
5962 WINRT_IMPL_GetErrorInfo (0 , error_info.put_void ());
@@ -87,13 +90,7 @@ namespace winrt::impl
8790 continue ;
8891 }
8992
90- if (isSameInterfaceAsIActivationFactory)
91- {
92- *result = library_factory.detach ();
93- library.detach ();
94- return 0 ;
95- }
96- else if (0 == library_factory.as (guid, result))
93+ if (0 == library_factory.as (guid, result))
9794 {
9895 library.detach ();
9996 return 0 ;
@@ -116,7 +113,7 @@ namespace winrt::impl
116113 template <typename Interface>
117114 hresult get_runtime_activation_factory (param::hstring const & name, void ** result) noexcept
118115 {
119- return get_runtime_activation_factory_impl<std::is_same_v<Interface, Windows::Foundation::IActivationFactory>> (name, guid_of<Interface>(), result);
116+ return get_runtime_activation_factory_impl (name, guid_of<Interface>(), result);
120117 }
121118}
122119
0 commit comments