From edefb23ebb9bad2faa64cda1c958b9a4879b30d0 Mon Sep 17 00:00:00 2001 From: ennewalker Date: Wed, 16 Jul 2008 03:07:15 +0000 Subject: [2018583] Fixing tiles issues with Windows 2000. I don't have any installs of Windows earlier than XP around, so I'm unable to test this fix directly. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.4@6573 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/libwt.cc | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/crawl-ref/source/libwt.cc b/crawl-ref/source/libwt.cc index df86c5fe87..72f23ac872 100644 --- a/crawl-ref/source/libwt.cc +++ b/crawl-ref/source/libwt.cc @@ -182,10 +182,24 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, GuicInit(hInstance, nCmdShow); - // Redirect output to the console - AttachConsole(ATTACH_PARENT_PROCESS); - freopen("CONOUT$", "wb", stdout); - freopen("CONOUT$", "wb", stderr); + // AttachConsole is a WindowsXP and above function. If this function + // doesn't exist, then don't call it. Call this function indirectly + // via GetProcAddress so that it is not implicitly linked in. + + typedef BOOL (WINAPI *ac_func)(DWORD); + ac_func attach_console = (ac_func)GetProcAddress( + GetModuleHandle(TEXT("kernel32.dll")), "AttachConsole"); + typedef BOOL (WINAPI *fc_func)(void); + fc_func free_console = (fc_func)GetProcAddress( + GetModuleHandle(TEXT("kernel32.dll")), "FreeConsole"); + + if (attach_console && free_console) + { + // Redirect output to the console + attach_console(ATTACH_PARENT_PROCESS); + freopen("CONOUT$", "wb", stdout); + freopen("CONOUT$", "wb", stderr); + } // I'll be damned if I have to parse lpCmdLine myself... int argc; @@ -208,7 +222,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, delete args; delete argv; - FreeConsole(); + if (attach_console && free_console) + { + free_console(); + } return msg.wParam; } -- cgit v1.2.3-54-g00ecf