From 387a2b37ad949e1e9471f922c288ddb00bdbd57e Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 30 Jun 2021 18:20:25 +0300 Subject: [PATCH] Use "SetDefaultDllDirectories". --- win_directx_helper/win_directx_helper.cpp | 29 ++--------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/win_directx_helper/win_directx_helper.cpp b/win_directx_helper/win_directx_helper.cpp index 11590db..42a4024 100644 --- a/win_directx_helper/win_directx_helper.cpp +++ b/win_directx_helper/win_directx_helper.cpp @@ -49,33 +49,8 @@ HRESULT (__stdcall *CreateDXGIFactory1)( _COM_Outptr_ void **ppFactory); Handle SafeLoadLibrary(const wchar_t *name) { - static const auto SystemPath = [] { - WCHAR buffer[MAX_PATH + 1] = { 0 }; - return GetSystemDirectory(buffer, MAX_PATH) - ? std::wstring(buffer) - : std::wstring(); - }(); - static const auto WindowsPath = [] { - WCHAR buffer[MAX_PATH + 1] = { 0 }; - return GetWindowsDirectory(buffer, MAX_PATH) - ? std::wstring(buffer) - : std::wstring(); - }(); - const auto tryPath = [&](const std::wstring &path) { - if (!path.empty()) { - const auto full = path + L'\\' + name; - if (const auto result = Handle(LoadLibrary(full.c_str()))) { - return result; - } - } - return Handle(); - }; - if (const auto result1 = tryPath(SystemPath)) { - return result1; - } else if (const auto result2 = tryPath(WindowsPath)) { - return result2; - } - return nullptr; + SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32); + return LoadLibrary(name); } template