diff --git a/strings/base_activation.h b/strings/base_activation.h index bb6be5ca1..6a44a2e2f 100644 --- a/strings/base_activation.h +++ b/strings/base_activation.h @@ -30,69 +30,63 @@ namespace winrt::impl if (hr == impl::error_not_initialized) { - auto usage = reinterpret_cast(WINRT_IMPL_GetProcAddress(load_library(L"combase.dll"), "CoIncrementMTAUsage")); - - if (!usage) - { - return hr; - } - void* cookie; - usage(&cookie); + WINRT_IMPL_CoIncrementMTAUsage(&cookie); hr = WINRT_IMPL_RoGetActivationFactory(*(void**)(&name), guid, result); } - if (hr == 0) +#ifdef WINRT_REG_FREE + if (hr != 0) { - return 0; - } + com_ptr error_info; + WINRT_IMPL_GetErrorInfo(0, error_info.put_void()); - com_ptr error_info; - WINRT_IMPL_GetErrorInfo(0, error_info.put_void()); + std::wstring path{ static_cast(name) }; + std::size_t count{}; - std::wstring path{ static_cast(name) }; - std::size_t count{}; + while (std::wstring::npos != (count = path.rfind('.'))) + { + path.resize(count); + path += L".dll"; + library_handle library(load_library(path.c_str())); + path.resize(path.size() - 4); - while (std::wstring::npos != (count = path.rfind('.'))) - { - path.resize(count); - path += L".dll"; - library_handle library(load_library(path.c_str())); - path.resize(path.size() - 4); + if (!library) + { + continue; + } - if (!library) - { - continue; - } + auto library_call = reinterpret_cast(WINRT_IMPL_GetProcAddress(library.get(), "DllGetActivationFactory")); - auto library_call = reinterpret_cast(WINRT_IMPL_GetProcAddress(library.get(), "DllGetActivationFactory")); + if (!library_call) + { + continue; + } - if (!library_call) - { - continue; - } + com_ptr> library_factory; - com_ptr> library_factory; + if (0 != library_call(*(void**)(&name), library_factory.put_void())) + { + continue; + } - if (0 != library_call(*(void**)(&name), library_factory.put_void())) - { - continue; + if constexpr (isSameInterfaceAsIActivationFactory) + { + *result = library_factory.detach(); + library.detach(); + return 0; + } + else if (0 == library_factory.as(guid, result)) + { + library.detach(); + return 0; + } } - if constexpr (isSameInterfaceAsIActivationFactory) - { - *result = library_factory.detach(); - library.detach(); - return 0; - } - else if (0 == library_factory.as(guid, result)) - { - library.detach(); - return 0; - } + WINRT_IMPL_SetErrorInfo(0, error_info.get()); } +#endif - WINRT_IMPL_SetErrorInfo(0, error_info.get()); return hr; } diff --git a/strings/base_extern.h b/strings/base_extern.h index 92872d416..dfd879c3f 100644 --- a/strings/base_extern.h +++ b/strings/base_extern.h @@ -40,6 +40,7 @@ extern "C" int32_t __stdcall WINRT_IMPL_GetErrorInfo(uint32_t reserved, void** info) noexcept WINRT_IMPL_LINK(GetErrorInfo, 8); int32_t __stdcall WINRT_IMPL_CoInitializeEx(void*, uint32_t type) noexcept WINRT_IMPL_LINK(CoInitializeEx, 8); void __stdcall WINRT_IMPL_CoUninitialize() noexcept WINRT_IMPL_LINK(CoUninitialize, 0); + int32_t __stdcall WINRT_IMPL_CoIncrementMTAUsage(void** cookie) noexcept WINRT_IMPL_LINK(CoIncrementMTAUsage, 4); int32_t __stdcall WINRT_IMPL_CoCreateFreeThreadedMarshaler(void* outer, void** marshaler) noexcept WINRT_IMPL_LINK(CoCreateFreeThreadedMarshaler, 8); int32_t __stdcall WINRT_IMPL_CoCreateInstance(winrt::guid const& clsid, void* outer, uint32_t context, winrt::guid const& iid, void** object) noexcept WINRT_IMPL_LINK(CoCreateInstance, 20); diff --git a/test/old_tests/UnitTests/pch.h b/test/old_tests/UnitTests/pch.h index 4b940b552..6b146a3bc 100644 --- a/test/old_tests/UnitTests/pch.h +++ b/test/old_tests/UnitTests/pch.h @@ -1,6 +1,7 @@ #pragma once -#define WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#define WINRT_REG_FREE #define WINRT_NATVIS #define _SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING diff --git a/test/test/pch.h b/test/test/pch.h index 24d65c225..b2392e14a 100644 --- a/test/test/pch.h +++ b/test/test/pch.h @@ -5,6 +5,7 @@ #include "mingw_com_support.h" #define WINRT_LEAN_AND_MEAN +#define WINRT_REG_FREE #include #include "winrt/Windows.Foundation.Collections.h" #include "winrt/Windows.Foundation.Numerics.h" diff --git a/test/test_fast/pch.h b/test/test_fast/pch.h index 97769b358..11dbff990 100644 --- a/test/test_fast/pch.h +++ b/test/test_fast/pch.h @@ -1,5 +1,6 @@ #pragma once +#define WINRT_REG_FREE #include "catch.hpp" #include "winrt/Windows.Foundation.Collections.h" diff --git a/test/test_slow/pch.h b/test/test_slow/pch.h index 97769b358..11dbff990 100644 --- a/test/test_slow/pch.h +++ b/test/test_slow/pch.h @@ -1,5 +1,6 @@ #pragma once +#define WINRT_REG_FREE #include "catch.hpp" #include "winrt/Windows.Foundation.Collections.h"