Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Win32 console app. help

Back to Forum: Tech Off
  • User profile image
    pdiemert

    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?)

    Any insight would be greatly appreciated.

  • User profile image
    AT

    Google "ATTACH_PARENT_PROCESS"

    The best is http://article.gmane.org/gmane.editors.vim.devel/4437 ,
    or  http://msdn.microsoft.com/msdnmag/issues/04/02/CQA/default.aspx


    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.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.