From 54238f9bf1bed8c879a1f12c0bfb7af469f2fc6c Mon Sep 17 00:00:00 2001 From: Willi Schinmeyer Date: Thu, 17 May 2012 14:11:03 +0200 Subject: [PATCH 1/3] Suppressing the console window by using WinMain - two variants --- radiant/main.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++ radiant/radiant.vcproj | 6 ++--- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/radiant/main.cpp b/radiant/main.cpp index ede1426..ace951a 100644 --- a/radiant/main.cpp +++ b/radiant/main.cpp @@ -51,6 +51,65 @@ bool g_bBuildList = false; int g_argc; char** g_argv; +// ============================================================================= +// Windows WinMain() wrapper for main() +// used in Release Builds to suppress the Console +#if defined(_WIN32) + +// contains __getmainargs() +//#include +#include + +int main(int argc, char* argv[]); + +int CALLBACK WinMain( + __in HINSTANCE hInstance, + __in HINSTANCE hPrevInstance, + __in LPSTR lpCmdLine, + __in int nCmdShow +){ + if(false) { + // while this works, it's not exactly nice + __argc = 3; + // load msvcrt.dll - we need an internal function from it + HMODULE crtlib = LoadLibrary("msvcrt.dll"); + if(crtlib == NULL) { + // do error handling here? + return 0; + } + + // retrieve pointer to function + struct fake_startupinfo { + int newmode; + }; + typedef int(*GetMainArgsPtr)(int*, char***, char***, int, fake_startupinfo*); + GetMainArgsPtr __getmainargs = (GetMainArgsPtr) GetProcAddress(crtlib, "__getmainargs"); + if(__getmainargs == NULL){ + FreeLibrary(crtlib); + return 0; + } + + fake_startupinfo startinfo; + startinfo.newmode = 0; //this sets _newmode - what does that do? + int argc; + char** argv; + char** envp; + int argret = __getmainargs(&argc, &argv, &envp, 0, &startinfo); //0: no wildcard expanding + FreeLibrary(crtlib); + if(argret < 0) { + // might want to handle this error here? + return 0; + } + return main(argc, argv); + } + else { + // This, on the other hand, seems very nice - but just like the first version I'm not sure it always works. + return main(__argc, __argv); + } +} + +#endif + // ============================================================================= // Splash screen diff --git a/radiant/radiant.vcproj b/radiant/radiant.vcproj index 851666b..0d5c3f6 100644 --- a/radiant/radiant.vcproj +++ b/radiant/radiant.vcproj @@ -1,7 +1,7 @@ - + Date: Thu, 17 May 2012 14:14:34 +0200 Subject: [PATCH 2/3] Removed vastly inferior variant of accessing argc/argv in WinMain() --- radiant/main.cpp | 41 +---------------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/radiant/main.cpp b/radiant/main.cpp index ace951a..19297d7 100644 --- a/radiant/main.cpp +++ b/radiant/main.cpp @@ -56,8 +56,6 @@ char** g_argv; // used in Release Builds to suppress the Console #if defined(_WIN32) -// contains __getmainargs() -//#include #include int main(int argc, char* argv[]); @@ -68,44 +66,7 @@ int CALLBACK WinMain( __in LPSTR lpCmdLine, __in int nCmdShow ){ - if(false) { - // while this works, it's not exactly nice - __argc = 3; - // load msvcrt.dll - we need an internal function from it - HMODULE crtlib = LoadLibrary("msvcrt.dll"); - if(crtlib == NULL) { - // do error handling here? - return 0; - } - - // retrieve pointer to function - struct fake_startupinfo { - int newmode; - }; - typedef int(*GetMainArgsPtr)(int*, char***, char***, int, fake_startupinfo*); - GetMainArgsPtr __getmainargs = (GetMainArgsPtr) GetProcAddress(crtlib, "__getmainargs"); - if(__getmainargs == NULL){ - FreeLibrary(crtlib); - return 0; - } - - fake_startupinfo startinfo; - startinfo.newmode = 0; //this sets _newmode - what does that do? - int argc; - char** argv; - char** envp; - int argret = __getmainargs(&argc, &argv, &envp, 0, &startinfo); //0: no wildcard expanding - FreeLibrary(crtlib); - if(argret < 0) { - // might want to handle this error here? - return 0; - } - return main(argc, argv); - } - else { - // This, on the other hand, seems very nice - but just like the first version I'm not sure it always works. - return main(__argc, __argv); - } + return main(__argc, __argv); } #endif From 2d902e10dae7154db49b07d537c3f7efbc5bae59 Mon Sep 17 00:00:00 2001 From: Willi Schinmeyer Date: Thu, 17 May 2012 14:19:22 +0200 Subject: [PATCH 3/3] Fixed encoding & locale problems in radiant.vcproj --- radiant/radiant.vcproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/radiant/radiant.vcproj b/radiant/radiant.vcproj index 0d5c3f6..81af2a2 100644 --- a/radiant/radiant.vcproj +++ b/radiant/radiant.vcproj @@ -1,7 +1,7 @@ - +