Use "SetDefaultDllDirectories".
This commit is contained in:
parent
e2455f3194
commit
387a2b37ad
1 changed files with 2 additions and 27 deletions
|
|
@ -49,33 +49,8 @@ HRESULT (__stdcall *CreateDXGIFactory1)(
|
||||||
_COM_Outptr_ void **ppFactory);
|
_COM_Outptr_ void **ppFactory);
|
||||||
|
|
||||||
Handle SafeLoadLibrary(const wchar_t *name) {
|
Handle SafeLoadLibrary(const wchar_t *name) {
|
||||||
static const auto SystemPath = [] {
|
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||||
WCHAR buffer[MAX_PATH + 1] = { 0 };
|
return LoadLibrary(name);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Function>
|
template <typename Function>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue