I'm also interested in a very similar thing for 3 purposes:
1) I want to write a Windows GUI application that can optionally write debug and error messages to the console. For example if the application fails to initialize, it shall be able to display an error message on the console (when executed within a cmd window). But I do not want to see a console window, when the program gets executed from the start menu in GUI mode.
2) When the user executes the program within a cmd window with a help option (such as myprogram.exe --help), I want to write that help to the console. Some GUI examples from Nokia display the help text in a Dialog box that pops up, which I find very un-natural.
3) Beneath interactive GUI mode, I want to be able to run the program in non-interactve mode using command-line options. In this case, the program shall not display any GUI, but it should write its output to the console. This is specially useful to integrate the program into batch files or to run it as a windows service.
One example where this makes really sense is the well known program ProjectX (written in Java). It normally starts with a GUI, where the user selects Video files for input and clicks on a "Start" button, which processes the input files and generates an output file. The same can also be done without GUI on the command line, just by providing filenames as command-line arguments. I use this program together with some other command-line driven programs within a batch script to process and burn TV mpeg streams onto Video DVD.
Another example is the program Gimp, which is a GUI image editor but can also manipulate images on command-line level. By the way, I noticed that (different to Linux), the windows version of Gimp contains two executables one with GUI and another one without GUI.
In the windows.h there is a FreeConsole() function which closes the unwanted console that opens, when my program supports both GUI+console. But this does not really solve my problem, because the console first pops up, and then immediately closes. This is ugly.
Do I really need to ship twi different executables, one for GUI and another one for Command-Line?