[SDL] sdlmain
Julien Lecomte
julien at famille-lecomte.net
Tue Jul 4 09:51:40 PDT 2006
On 04/07/2006 17:39, Torsten Giebl wrote:
> Hello !
>
>> -mconsole just prevents a console from being opened at start of program.
>> It doesn't define anything or change linking in any way apart from what
>> I said above.
>
> You do not understand me right. For me it would be usefull, when
> your app is a console app so compiling with -mconsole to have the
> output on that console and when compiling in Windowed Mode
> with -mwindows the files should be created. I do not know
> if it is possible to detect this at runtime.
I don't see why you need to detect this at runtime; after all, you've
decided to link either in console or windows mode, so you know if you
have a console or not.
Since you know if you'll have a console or not, you can compile two
SDLmain libraries (one with --disable-stdio-redirect, see FAQ:
http://www.libsdl.org/cgi/docwiki.cgi/FAQ_20Console) which I'll name
libSDLconsole and libSDLwindows, and use the correct one at link time.
You can then use two different command lines for two different targets:
$ gcc -mconsole foobar.c -lmingw32 -lSDLconsole -lSDL
$ gcc -mwindows foobar.c -lmingw32 -lSDLwindows -lSDL
If you nevertheless want to detect this at runtime, you can detect a
console at runtime with GetConsoleWindow, but this is non portable
(windows specific and WinXP or better).
----
#define _WIN32_WINNT 0x0500
#include <stdio.h>
#include <windows.h>
int main(void)
{
if (GetConsoleWindow())
printf("console\n");
else
printf("not console\n");
return 0;
}
----
More information about the SDL
mailing list