So, my question is a bit different from most. I'm not trying to open a cmd window or make the program start with a cmd window. I want my program to just open a window when the executable is clicked, but output from the console when the executable is run from the command line. I was wondering if that is possible? I know that it is possible in Linux.
I don't understand your question at all. Its just gibberish to me. You want to open a window, but not open a window. You want to open a console, but not open a console, or maybe sometimes, but not all the time.
I think he wants to know if the app is running from command line to behave differently depending on this.
In Linux every program can use stdin and stdout, be it GUI or not, but on windows this behaviour needs to be emulated.
Hmm, I tried to implement it, but it isn't exactly what I wanted. It determines if the program has a console window attached to it. It doesn't know if the program was executed from the console.
Maybe I can restate exactly what I am looking for to make my question a bit more clear. I am writing a windows application using winapi. When I compile the executable, the executable can be run from two ways. The first way is by double clicking on the file. The second way is by executing the file from the command line.
I want to make it so that when I run the program from the command line, it uses that to output messages.
This is the "solution" that I devised. If this is the only "solution" it's not worth doing at all IMHO.
The reason that you can't really do it is because of the way that Windows loads the applications with explorer. You assume that there is a way for the program to know that explorer ran it, whereas AFAIK, explorer is simply a wrapper around the OS itself, the same as the console providing a different interface. Therefore, running from the console gives no differences than running from a normal system. As such, your option is the only one that would really work, though of course due to its hackish nature can have problems (e.g. user types 'cls && ./myprog.exe' or the like). The other option is to have two different programs to run, one from the console and one from explorer. These programs could just be wrappers, and the actual program functionality is provided by a DLL shared between the two programs.
Thanks for the information! I guess that the best way to solve this then is to compile one that opens the console and another one that doesn't. It's a little disappointing.
I think you are right. I got the program to output the command that executed the executable. When opening it with explorer it used its full path, but when using cmd it was just the executable. However, both were just paths to the exe. I think that you are right in that there is no way for the program to know.