Anyone turned their app. into a console process at runtime? The scenario is that, depending on some flags determined at runtime I want to make my app. behave like either a desktop window or a console. Presumably, I need to set my application as a
"Windows" application at link time to prevent the creation of a console at startup by the shell, then create it myself if needed at runtime (via AllocConsole). However, this does not bode well when my app. is launched from an existing console. In this case
I do NOT want to create a separate console window and, furthermore, I want to "inherit" the IO handles from the process that launched me.
So, this raises three questions:
1) How can I easily determine if the process that started my process was a console?
2) How can I get access to the IO handles (stdout/stdin/stderr) of the parent console process?
3) Assuming #2, will I be able to get appropriate permissions to use the IO handles? (i.e. does Windows reserve the right to inherit these handles exclusively to app.s with the "I am a console" bit set in the exe header?)
Looks like the best you can do is to create two application - Console and Win32 with .COM and .EXE extensions.
Console version will simply start Win32 with redirected std handles and Win32 will decide to create main window or simply write to std output based on params.
devenv.exe/devenv.com use this technique, so it looks like correct and preferred one.
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.