Changeset - r25627:a3297d91e516
[Not reviewed]
master
0 2 0
glx22 - 3 years ago 2021-05-20 16:28:14
glx@openttd.org
Codechange: [WIN32] Reduce manual dynamic loading as WinXP is the minimum version
2 files changed with 11 insertions and 14 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -357,19 +357,21 @@ add_definitions_based_on_options()
 

	
 
if(WIN32)
 
    add_definitions(
 
        -DUNICODE
 
        -D_UNICODE
 
        -DWITH_UNISCRIBE
 
        -DPSAPI_VERSION=1
 
    )
 

	
 
    target_link_libraries(openttd
 
        ws2_32
 
        winmm
 
        imm32
 
        usp10
 
        psapi
 
    )
 
endif()
 

	
 
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
 
    add_definitions(-DPOINTER_IS_64BIT)
 
endif()
src/os/windows/crashlog_win.cpp
Show inline comments
 
@@ -19,12 +19,13 @@
 
#include "../../saveload/saveload.h"
 
#include "../../video/video_driver.hpp"
 

	
 
#include <windows.h>
 
#include <mmsystem.h>
 
#include <signal.h>
 
#include <psapi.h>
 

	
 
#include "../../safeguards.h"
 

	
 
/* printf format specification for 32/64-bit addresses. */
 
#ifdef _M_AMD64
 
#define PRINTF_PTR "0x%016IX"
 
@@ -203,31 +204,25 @@ static char *PrintModuleInfo(char *outpu
 
	return output;
 
}
 

	
 
/* 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<DWORD>(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<DWORD>(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);
 
	return output + seprintf(output, last, "\n");
 
}
 

	
0 comments (0 inline, 0 general)