aboutsummaryrefslogtreecommitdiff
path: root/backends/platform
diff options
context:
space:
mode:
authorHenrik "Henke37" Andersson2019-05-25 21:09:25 +0200
committerFilippos Karapetis2019-06-09 13:42:06 +0300
commitb527b573cf2fd25085c0ea2dcd3c83a7182a1b74 (patch)
tree27535c4c169c33c96d56681ef85bebf6ffe3d287 /backends/platform
parentd2f5023ee9ec5534a9f7a4754c4f1e805c0fb605 (diff)
downloadscummvm-rg350-b527b573cf2fd25085c0ea2dcd3c83a7182a1b74.tar.gz
scummvm-rg350-b527b573cf2fd25085c0ea2dcd3c83a7182a1b74.tar.bz2
scummvm-rg350-b527b573cf2fd25085c0ea2dcd3c83a7182a1b74.zip
WIN32: Let the PE header control showing the console.
This applies DRY to the console config and avoids junk code changes seen by git.
Diffstat (limited to 'backends/platform')
-rw-r--r--backends/platform/sdl/win32/win32.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp
index aada5b4e68..30ebf9d1d2 100644
--- a/backends/platform/sdl/win32/win32.cpp
+++ b/backends/platform/sdl/win32/win32.cpp
@@ -74,9 +74,23 @@ void OSystem_Win32::init() {
OSystem_SDL::init();
}
+WORD GetCurrentSubsystem() {
+ // HMODULE is the module base address. And the PIMAGE_DOS_HEADER is located at the beginning.
+ PIMAGE_DOS_HEADER EXEHeader = (PIMAGE_DOS_HEADER)GetModuleHandle(NULL);
+ assert(EXEHeader->e_magic == IMAGE_DOS_SIGNATURE);
+ // PIMAGE_NT_HEADERS is bitness dependant.
+ // Conveniently, since it's for our own process, it's always the correct bitness.
+ // IMAGE_NT_HEADERS has to be found using a byte offset from the EXEHeader,
+ // which requires the ugly cast.
+ PIMAGE_NT_HEADERS PEHeader = (PIMAGE_NT_HEADERS)(((char*)EXEHeader) + EXEHeader->e_lfanew);
+ assert(PEHeader->Signature == IMAGE_NT_SIGNATURE);
+ return PEHeader->OptionalHeader.Subsystem;
+}
+
void OSystem_Win32::initBackend() {
- // Console window is enabled by default on Windows
- ConfMan.registerDefault("console", true);
+ // The console window is enabled for the console subsystem,
+ // since Windows already creates the console window for us
+ ConfMan.registerDefault("console", GetCurrentSubsystem() == IMAGE_SUBSYSTEM_WINDOWS_CUI);
// Enable or disable the window console window
if (ConfMan.getBool("console")) {