Console outputs don't show outputs under the Visual Studio Community 2017, with Window Desktop Applications

zzhang2006
zzhang2006 used Ask the Experts™
on
I am using Visual Studio Community 2017/C++ and AGK Trial 2 to develop GUI apps. The Console output nor the VS output don't show any debug messages, whereas the exact same code worked fine with Visual Studio 2010.  To start with I  used an AGK template VS2015 project and inserted my old working AGK code to it. It builds and runs perfectly in VS2017, but the Console doesn't show any debugging messages printed with "cout", as it did when using VS2010.   The following code  is the function I used to pop up the Console:

// for the console to display "cout" outputs, all these must be included
// And later these should be removed when you program is fully debugge
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <direct.h>
#include <fcntl.h>
#include <io.h>

void console_back()
{

int hCrt;
     FILE *hf;

   AllocConsole();
   hCrt = _open_osfhandle(
             (long) GetStdHandle(STD_OUTPUT_HANDLE),
             _O_TEXT
          );
   hf = _fdopen( hCrt, "w" );
   *stdout = *hf;
   int i = setvbuf( stdout, NULL, _IONBF, 0 );

   return;
}

// in the main code
console_back();
cout << "Hi, Hello World";	

Open in new window

As is see in the attached snapshot, the Console pops up but stays blank, though the is no runtime complains from the
system about the cout << "Hi ..".  

Experts, any ideas why this happens?  I hope there is a workaround for this problem, sample code is highly appreciated.

A side note, I am using a trial version of AGK package, where I don't have a debug version of AGKWindows.lib so I can't
build VS2017  in debug mode.  This makes debugging with console messages the only option for right now.
After all as long as I have a way to debug, I will be happy. But I don't know if the retail version of AGK  has the debug version of the AGKWindows.lib in C++.  Any comments or suggestions along this avenue are also appreciated.

Thanks

Ze
Console_done_problem.PNG
Console_done_problem.PNG
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
// in the main code
console_back("Hi, Hello World);


void console_back(string message){
...
cout << message;


}
zzhang2006Professor

Author

Commented:
David,
The function console_back does take any input parameters. It just somehow bring up a console and connect the standard out stream to cout, but it failed here.

Thanks anyway!

Ze

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial