# HG changeset patch # User glx22 # Date 2021-05-20 16:28:14 # Node ID a3297d91e51687914ea8a439ea3d5b50bd8b901c # Parent 260a951230d56c233d6e87548320a91d3357a5c4 Codechange: [WIN32] Reduce manual dynamic loading as WinXP is the minimum version diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -360,6 +360,7 @@ if(WIN32) -DUNICODE -D_UNICODE -DWITH_UNISCRIBE + -DPSAPI_VERSION=1 ) target_link_libraries(openttd @@ -367,6 +368,7 @@ if(WIN32) winmm imm32 usp10 + psapi ) endif() diff --git a/src/os/windows/crashlog_win.cpp b/src/os/windows/crashlog_win.cpp --- a/src/os/windows/crashlog_win.cpp +++ b/src/os/windows/crashlog_win.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "../../safeguards.h" @@ -206,25 +207,19 @@ static char *PrintModuleInfo(char *outpu /* virtual */ char *CrashLogWindows::LogModules(char *output, const char *last) const { MakeCRCTable(AllocaM(uint32, 256)); - BOOL (WINAPI *EnumProcessModules)(HANDLE, HMODULE*, DWORD, LPDWORD); - output += seprintf(output, last, "Module information:\n"); - if (LoadLibraryList((Function*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0\0")) { + HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); + if (proc != nullptr) { HMODULE modules[100]; DWORD needed; - BOOL res; + BOOL res = EnumProcessModules(proc, modules, sizeof(modules), &needed); + CloseHandle(proc); + if (res) { + size_t count = std::min(needed / sizeof(HMODULE), lengthof(modules)); - HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); - if (proc != nullptr) { - res = EnumProcessModules(proc, modules, sizeof(modules), &needed); - CloseHandle(proc); - if (res) { - size_t count = std::min(needed / sizeof(HMODULE), lengthof(modules)); - - for (size_t i = 0; i != count; i++) output = PrintModuleInfo(output, last, modules[i]); - return output + seprintf(output, last, "\n"); - } + for (size_t i = 0; i != count; i++) output = PrintModuleInfo(output, last, modules[i]); + return output + seprintf(output, last, "\n"); } } output = PrintModuleInfo(output, last, nullptr);