Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6134407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:21:05+00:00 2026-05-23T17:21:05+00:00

I have a C++ Win32 application that runs as a console app if run

  • 0

I have a C++ Win32 application that runs as a console app if run with command line arguments, but as a windowed app if there are no command line arguments. I do it using this method to create a console using AllocConsole() and STD_OUTPUT_HANDLE:

http://www.halcyon.com/~ast/dload/guicon.htm

My entry point is wWinMain (unicode WinMain).

It almost works great. If I run app.exe param1, I get the console and no GUI window. If I run app.exe with no parameters, it fires up the GUI and moves merrily along with no console.

There’s one thing missing.

If I run app.exe param1 > output.txt, the stdout output is not redirected to the output.txt file. It gets lost along the way. Is there a way to have a hybrid app like I have and still preserve any command-line redirects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:21:06+00:00Added an answer on May 23, 2026 at 5:21 pm

    Try to call AttachConsole first with ATTACH_PARENT_PROCESS (value -1) as its argument. That will redirect your app to the console it has been run from, and therefore allow the > output.txt to obtain whatever it outputs. Otherwise, the output isn’t caught because two different consoles are used – the one your app has been run from, and the one it has created. The redirection to the file works on the first, while your app outputs to the second.

    Edit: The above is correct assuming your app is run with arguments from an existing console (cmd.exe or so). However, this might not always be the case – it might be run with arguments from a shortcut, task scheduler, another process etc. When this is the case, AttachConsole will fail, and when this happens, you should call AllocConsole as before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a delphi (Win32) web application that can run either as a CGI
We have a Win32 application that hosts the .NET runtime and opens up .NET
I have a C++ application that uses the Win32 API for Windows, and I'm
I'm using libcurl in a Win32 C++ application. I have the curllib.vcproj project added
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,
OK, so I have a very large multi-threaded unmanaged c++ application (server) that runs
I am responsible for a Delphi/Win32 project management application. I have just completed a
We have an x-files problem with our .NET application. Or, rather, hybrid Win32 and
I have created a minidump using win32 api [DllImport(DbgHelp.dll, SetLastError = true)] private static
In a Win32 application I have a dialog with a list control which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.