Application with CLI or GUI
Brought to you by:
grzegok
I have an interesting scenario - I have an app which has a "Desktop" mode and a "Server" mode, which depending on certain command arguments, either launches a GUI or stays as a command line only tool.
Obviously I could build two different applications - one for Server and one for Desktop, but I am trying to create a universal binary. I can manipulate the "headerType" field and select "console", but I don't really want the console window appearing when it is in GUI mode.
Is there anyway of Launch4j looking for a command line option to either launch with the "console" or "gui" headerType?
I see you have "consolehead.c" and "guihead.c" - one of them is then linked with "head.c" to create the launcher. They both have different entry points - "main" and "WinMain, which is linked with -mwindows".
It has been a very long time since I touched Windows C programming, but is it not possible to use "WinMain" and still create a console window or does the use of WinMain effectively detach the application from the console window it was launched from?
I had a little play and by adding the following to "guihead.c" to call "SetConsoleFlag()" when a certain argument is seen then it will launch using "java.exe" instead of "javaw.exe". This results in a command line window appearing only when I pass "--cli".
if (strstr(lpCmdLine, "--cli") != NULL) {
setConsoleFlag();
}
Any downsides to this?
Chris
In Windows the application is either a console one or GUI, some applications use various tricks to overcome this. This is why there is java and javaw, and two versions of launch4j headers.
The downside to your solution is that you have no connection to the console from which the program was launched, it will open another console. There is a feature request to attach to the console, but there were some problems and it's not done yet.
Grzegorz