I assume that you are attaching the MFC application to the parent process console in order to obtain input from the console window.
However, when starting the MFC application from the command line, cmd.exe is also processing console input and that is the interference that you are experiencing.
You can build your MFC application and then use the editbin utility to change the application's subsystem from Windows To Console.
This will cause the system treat your MFC application as if it was a console application and the application handles for stdin, stdout and stderr will be initialized automatically at startup.
By doing this your MFC application will be able to interact with the user for console input without interference. However, it also means that closing the console will also terminate the MFC application. You can manage the visibility of the console window to avoid accidental closure by the user.
For example, I created a new MFC SDI application using the new application wizard. In the application class I added a bool variable and some code to InitInstance and ExitInstance as follows:
Added to InitInstance -
// Added by RLWA32
DWORD dwId = 0, dwNum = 0;
dwNum = GetConsoleProcessList(&dwId, 1);
_ASSERTE(dwNum != 0);
if (dwNum > 1) // more than one process is sharing the console
m_bShowConsole = true;
_tprintf(_T("Enter Input:"));
TCHAR str[5]{};
int ch{};
int ndx = 0, count = ARRAYSIZE(str) - 1;
while (ndx < count)
{
ch = _gettch();
if (_istalnum(ch))
{
str[ndx] = ch;
_puttch(_T('*'));
++ndx;
}
};
// Hide console window so we cannot be terminated by mistake if the user closes the console
ShowWindow(GetConsoleWindow(), SW_HIDE);
MessageBox(NULL, str, _T("Entered info"), MB_TOPMOST | MB_OK);
// End of RLWA32 additions
Added to ExitInstance -
// Added by RLWA32 - Unhide the console window
if (m_bShowConsole)
ShowWindow(GetConsoleWindow(), SW_SHOW);
After building the application this was the editbin.exe command -
editbin /subsystem:console MFCSample.exe