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

  • Home
  • SEARCH
  • 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 8701777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:29:02+00:00 2026-06-13T02:29:02+00:00

I have a C++ MFC program that works, but I would also like to

  • 0

I have a C++ MFC program that works, but I would also like to be able to invoke a simpler version through the command line. (This works by using a cmd line version if there are cmd line arguments.) I would like the program to use the current “cmd” window that is open to run, and create a new shell for it to some degree. In InitInstance(), I have…

CString cmdLine;
cmdLine.Format("%s", this->m_lpCmdLine);
if(cmdLine.IsEmpty())
    dlg.DoModal(); // Run application normally
else
{
    CString header = "Welcome to the program!";
    AttachConsole(ATTACH_PARENT_PROCESS);     // Use current console window
    LPDWORD charsWritten = 0;
    WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), header, header.GetLength(), NULL, NULL);
}

How do I go about getting input into my program? cin seems not to work. I tried something like this:

char input[10] = "";
while((strcmp(input, "q") != 0) && (strcmp(input, "quit") != 0))
    scanf("%s", input);

But it doesn’t seem to work, as the command window waits for a new prompt.

  • 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-06-13T02:29:03+00:00Added an answer on June 13, 2026 at 2:29 am

    The fundamental problem is that your MFC program is not marked as a console mode program in its EXE header. So the command processor has no reason to wait for it to complete, like it normally does for console mode programs. You now have two programs trying to read from the console, you and cmd.exe. You lose.

    There are several workarounds, all unattractive:

    • Start your program with start /wait yourapp.exe arg1 arg2...
    • Change the Linker + System + SubSystem setting to Console. Call FreeConsole when you find out that you don’t have any arguments. The flash is kinda nasty, well known to Java programmers
    • Call AllocConsole() when you find out you do have arguments. You’ll get your own console.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MFC application that runs on my computer, but when I try
I have a MFC application written in VC6. I would like to temporarily allocate
I have an MFC C++ program that contains two classes, as follows; struct MyStruct
I have this MFC program that when I kill it with task manager I
I have a large program with several large DLL's that are compiled with MFC
I have a custom control written in C# that I would like to port
I have to program a simple threaded program with MFC/C++ for a uni assignment.
I have an MFC extension DLL that I've written. It contains derived classes of
I have a MFC application that launches a IWebBrowser2 window. On users computers where
I have a memory leak that I'm trying to hunt down in my mfc

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.