1
0
Fork 0

Use "SetDefaultDllDirectories".

This commit is contained in:
John Preston 2021-06-30 18:20:25 +03:00
parent e2455f3194
commit 387a2b37ad

View file

@ -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 <typename Function>