|
@@ -30,41 +30,72 @@ void HostFxrErrorRedirector::HostFxrErrorRedirectorCallback(const WCHAR* message
|
|
|
m_writeFunction->Append(std::wstring(message) + L"\r\n");
|
|
m_writeFunction->Append(std::wstring(message) + L"\r\n");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int HostFxr::Main(DWORD argc, const PCWSTR* argv) const noexcept(false)
|
|
|
|
|
-{
|
|
|
|
|
- return m_hostfxr_main_fn(argc, argv);
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
-int HostFxr::GetNativeSearchDirectories(INT argc, const PCWSTR* argv, PWSTR buffer, DWORD buffer_size, DWORD* required_buffer_size) const noexcept
|
|
|
|
|
|
|
+void HostFxr::Load()
|
|
|
{
|
|
{
|
|
|
- return m_hostfxr_get_native_search_directories_fn(argc, argv, buffer, buffer_size, required_buffer_size);
|
|
|
|
|
|
|
+ HMODULE hModule;
|
|
|
|
|
+ THROW_LAST_ERROR_IF(!GetModuleHandleEx(0, L"hostfxr.dll", &hModule));
|
|
|
|
|
+ Load(hModule);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-HostFxrErrorRedirector HostFxr::RedirectOutput(RedirectionOutput* writer) const noexcept
|
|
|
|
|
|
|
+void HostFxr::Load(HMODULE moduleHandle)
|
|
|
{
|
|
{
|
|
|
- return HostFxrErrorRedirector(m_corehost_set_error_writer_fn, writer);
|
|
|
|
|
|
|
+ m_hHostFxrDll = moduleHandle;
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ m_hostfxr_main_fn = ModuleHelpers::GetKnownProcAddress<hostfxr_main_fn>(moduleHandle, "hostfxr_main");
|
|
|
|
|
+ m_hostfxr_get_native_search_directories_fn = ModuleHelpers::GetKnownProcAddress<hostfxr_get_native_search_directories_fn>(moduleHandle, "hostfxr_get_native_search_directories");
|
|
|
|
|
+ m_corehost_set_error_writer_fn = ModuleHelpers::GetKnownProcAddress<corehost_set_error_writer_fn>(moduleHandle, "hostfxr_set_error_writer", /* optional */ true);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (...)
|
|
|
|
|
+ {
|
|
|
|
|
+ EventLog::Error(
|
|
|
|
|
+ ASPNETCORE_EVENT_GENERAL_ERROR,
|
|
|
|
|
+ ASPNETCORE_EVENT_HOSTFXR_DLL_INVALID_VERSION_MSG,
|
|
|
|
|
+ ModuleHelpers::GetModuleFileNameValue(moduleHandle).c_str()
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ throw;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-HostFxr HostFxr::CreateFromLoadedModule()
|
|
|
|
|
-{
|
|
|
|
|
- HMODULE hModule;
|
|
|
|
|
- THROW_LAST_ERROR_IF_NULL(hModule = GetModuleHandle(L"hostfxr.dll"));
|
|
|
|
|
|
|
|
|
|
|
|
+void HostFxr::Load(const std::wstring& location)
|
|
|
|
|
+{
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
- return HostFxr(
|
|
|
|
|
- ModuleHelpers::GetKnownProcAddress<hostfxr_main_fn>(hModule, "hostfxr_main"),
|
|
|
|
|
- ModuleHelpers::GetKnownProcAddress<hostfxr_get_native_search_directories_fn>(hModule, "hostfxr_get_native_search_directories"),
|
|
|
|
|
- ModuleHelpers::GetKnownProcAddress<corehost_set_error_writer_fn>(hModule, "hostfxr_set_error_writer", /* optional */ true));
|
|
|
|
|
|
|
+ HMODULE hModule;
|
|
|
|
|
+ THROW_LAST_ERROR_IF_NULL(hModule = LoadLibraryW(location.c_str()));
|
|
|
|
|
+ Load(hModule);
|
|
|
}
|
|
}
|
|
|
catch (...)
|
|
catch (...)
|
|
|
{
|
|
{
|
|
|
EventLog::Error(
|
|
EventLog::Error(
|
|
|
ASPNETCORE_EVENT_GENERAL_ERROR,
|
|
ASPNETCORE_EVENT_GENERAL_ERROR,
|
|
|
- ASPNETCORE_EVENT_HOSTFXR_DLL_INVALID_VERSION_MSG,
|
|
|
|
|
- ModuleHelpers::GetModuleFileNameValue(hModule).c_str()
|
|
|
|
|
|
|
+ ASPNETCORE_EVENT_HOSTFXR_DLL_UNABLE_TO_LOAD_MSG,
|
|
|
|
|
+ location.c_str()
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
throw;
|
|
throw;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+void HostFxr::SetMain(hostfxr_main_fn hostfxr_main_fn)
|
|
|
|
|
+{
|
|
|
|
|
+ m_hostfxr_main_fn = hostfxr_main_fn;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+int HostFxr::Main(DWORD argc, const PCWSTR* argv) const noexcept(false)
|
|
|
|
|
+{
|
|
|
|
|
+ return m_hostfxr_main_fn(argc, argv);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+int HostFxr::GetNativeSearchDirectories(INT argc, const PCWSTR* argv, PWSTR buffer, DWORD buffer_size, DWORD* required_buffer_size) const noexcept
|
|
|
|
|
+{
|
|
|
|
|
+ return m_hostfxr_get_native_search_directories_fn(argc, argv, buffer, buffer_size, required_buffer_size);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+HostFxrErrorRedirector HostFxr::RedirectOutput(RedirectionOutput* writer) const noexcept
|
|
|
|
|
+{
|
|
|
|
|
+ return HostFxrErrorRedirector(m_corehost_set_error_writer_fn, writer);
|
|
|
|
|
+}
|