summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-16 03:07:15 +0000
committerennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-16 03:07:15 +0000
commitedefb23ebb9bad2faa64cda1c958b9a4879b30d0 (patch)
treed75b13e324717c1d6ad9966fba82378cfb84bcb2
parent8d0205570b4dd7c1b647791e018ee4a05bc6250a (diff)
downloadcrawl-ref-edefb23ebb9bad2faa64cda1c958b9a4879b30d0.tar.gz
crawl-ref-edefb23ebb9bad2faa64cda1c958b9a4879b30d0.zip
[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
-rw-r--r--crawl-ref/source/libwt.cc27
1 files 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;
}