Suppressing the console window by using WinMain - two variants

This commit is contained in:
Willi Schinmeyer 2012-05-17 14:11:03 +02:00
parent 9b5ba1fe10
commit 54238f9bf1
2 changed files with 62 additions and 3 deletions

View file

@ -51,6 +51,65 @@ bool g_bBuildList = false;
int g_argc; int g_argc;
char** g_argv; char** g_argv;
// =============================================================================
// Windows WinMain() wrapper for main()
// used in Release Builds to suppress the Console
#if defined(_WIN32)
// contains __getmainargs()
//#include <internal.h>
#include <winbase.h>
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 // Splash screen

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="9.00" Version="9,00"
Name="radiant" Name="radiant"
ProjectGUID="{65D02375-63EE-4A8A-9F8E-504B1D5A1D02}" ProjectGUID="{65D02375-63EE-4A8A-9F8E-504B1D5A1D02}"
Keyword="Win32Proj" Keyword="Win32Proj"
@ -135,7 +135,7 @@
AdditionalDependencies="Ws2_32.lib glib-2.0.lib gobject-2.0.lib intl.lib gtk-win32-2.0.lib gdk-win32-2.0.lib pango-1.0.lib pangoft2-1.0.lib gdkglext-win32-1.0.lib gtkglext-win32-1.0.lib libxml2.lib mathlib.lib synapse.lib l_net.lib cmdlib.lib" AdditionalDependencies="Ws2_32.lib glib-2.0.lib gobject-2.0.lib intl.lib gtk-win32-2.0.lib gdk-win32-2.0.lib pango-1.0.lib pangoft2-1.0.lib gdkglext-win32-1.0.lib gtkglext-win32-1.0.lib libxml2.lib mathlib.lib synapse.lib l_net.lib cmdlib.lib"
AdditionalLibraryDirectories="&quot;$(SolutionDir)\..\gtk-2.16.6\lib&quot;;&quot;$(SolutionDir)\..\libxml2-2.7.3\lib&quot;;&quot;$(SolutionDir)\..\gtkglext-1.2.0\lib&quot;;&quot;$(SolutionDir)\build\$(ConfigurationName)\libs&quot;" AdditionalLibraryDirectories="&quot;$(SolutionDir)\..\gtk-2.16.6\lib&quot;;&quot;$(SolutionDir)\..\libxml2-2.7.3\lib&quot;;&quot;$(SolutionDir)\..\gtkglext-1.2.0\lib&quot;;&quot;$(SolutionDir)\build\$(ConfigurationName)\libs&quot;"
GenerateDebugInformation="true" GenerateDebugInformation="true"
SubSystem="1" SubSystem="2"
OptimizeReferences="2" OptimizeReferences="2"
EnableCOMDATFolding="2" EnableCOMDATFolding="2"
TargetMachine="1" TargetMachine="1"