1
0
Fork 0

Codechange: [WIN32] Reduce manual dynamic loading as WinXP is the minimum version

pull/8698/head
glx22 2021-05-20 18:28:14 +02:00 committed by Loïc Guilloux
parent f4c7d5577e
commit 5d05c4919b
2 changed files with 11 additions and 14 deletions

View File

@ -360,6 +360,7 @@ if(WIN32)
-DUNICODE -DUNICODE
-D_UNICODE -D_UNICODE
-DWITH_UNISCRIBE -DWITH_UNISCRIBE
-DPSAPI_VERSION=1
) )
target_link_libraries(openttd target_link_libraries(openttd
@ -367,6 +368,7 @@ if(WIN32)
winmm winmm
imm32 imm32
usp10 usp10
psapi
) )
endif() endif()

View File

@ -22,6 +22,7 @@
#include <windows.h> #include <windows.h>
#include <mmsystem.h> #include <mmsystem.h>
#include <signal.h> #include <signal.h>
#include <psapi.h>
#include "../../safeguards.h" #include "../../safeguards.h"
@ -206,18 +207,13 @@ static char *PrintModuleInfo(char *output, const char *last, HMODULE mod)
/* virtual */ char *CrashLogWindows::LogModules(char *output, const char *last) const /* virtual */ char *CrashLogWindows::LogModules(char *output, const char *last) const
{ {
MakeCRCTable(AllocaM(uint32, 256)); MakeCRCTable(AllocaM(uint32, 256));
BOOL (WINAPI *EnumProcessModules)(HANDLE, HMODULE*, DWORD, LPDWORD);
output += seprintf(output, last, "Module information:\n"); output += seprintf(output, last, "Module information:\n");
if (LoadLibraryList((Function*)&EnumProcessModules, "psapi.dll\0EnumProcessModules\0\0")) {
HMODULE modules[100];
DWORD needed;
BOOL res;
HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
if (proc != nullptr) { if (proc != nullptr) {
res = EnumProcessModules(proc, modules, sizeof(modules), &needed); HMODULE modules[100];
DWORD needed;
BOOL res = EnumProcessModules(proc, modules, sizeof(modules), &needed);
CloseHandle(proc); CloseHandle(proc);
if (res) { if (res) {
size_t count = std::min<DWORD>(needed / sizeof(HMODULE), lengthof(modules)); size_t count = std::min<DWORD>(needed / sizeof(HMODULE), lengthof(modules));
@ -226,7 +222,6 @@ static char *PrintModuleInfo(char *output, const char *last, HMODULE mod)
return output + seprintf(output, last, "\n"); return output + seprintf(output, last, "\n");
} }
} }
}
output = PrintModuleInfo(output, last, nullptr); output = PrintModuleInfo(output, last, nullptr);
return output + seprintf(output, last, "\n"); return output + seprintf(output, last, "\n");
} }