User forums > General (but related to Code::Blocks)

stdout in GUI apps


This is something I always liked back in the old days with Visual Cafe (java)... Even if you made a GUI-based application, it would still dump whatever messages you sent to stdout into the same textbox that holds the compiler- and run- messages. Hidden when the app was built and distributed, but a great way of outputting quick debug info while you executed inside the IDE.

Would you be so kind to add this to C::B ? :)

AFAIK it's impossible in Windows (but I can mistake :)), as GUI applications do not have stdout opend by default, so to make thing like you described one at least need to write library and link it to all GUI application, while not touching non-GUI ones.
Moreover even if such library became written it might do tricky and non-portable think to init itself...

PS. I didn't want to say that it's impossible at all :), but that's very hard to implement in portable (as C::B is portable) way
May be you are looking for wxLog (er, not shure about name) and friends?

I *GOT* an idea. And i've been thinking about using it in codeblocks itself! The idea:

Using a *SEPARATE* log program. Actually a DDE / TCP server. The communication is done with a simple wxWidgets class (wxServer / wxClient). The program to be debugged would create a client class, that it would test for the server. The server would simply accept the messages and print them accordingly.

It shouldn't (repeat: SHOULDn't) be hard to implement. Any volunteer? :D

Actually.. I like Profic's idea if you'ld simply combine it with a log-box (along with the tabs for compiler/warnings/debug/etc at the bottom of C::B) which you can just assign a (log)file too and effectively just does a tail -f on it to display the contents as it grows. Anyone can just use their own way of logging, the only thing C::B needs is the tail -f box.

Seems I was mistaken :)
A simple program (listed below) compiled with mingw's gcc works fine - std::cerr do nothing if ran by double clicking it while outputing to file if ran as test0.exe 2>err.txt in cmd's prompt.
If it works so with others compilers to, it is easy to implement such thing by redirecting stderr to one of tabs below editor window.
Nevertheless this feature seems be reasonable even if program do not work well with all compilers, as most programs use its stderr fo logging debug info :)

Code (filename test0.cpp)

--- Code: ---#include <iostream>
#include <sstream>
#include <typeinfo>
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
std::stringstream l_str;
l_str << std::cerr.rdstate() << " : ";
std::basic_streambuf<char>* l_strbuf = std::cerr.rdbuf();
l_str << static_cast<void*>(l_strbuf) << " : ";
l_str << typeid(l_strbuf).name() << " : ";

std::cerr << "before MessageBox()" << std::endl;
MessageBoxA(NULL, l_str.str().c_str(), "std::cerr status", MB_OK);
std::cerr << "after MessageBox()" << std::endl;

--- End code ---

PS: "Preview" button stopped working - it redirect me to index page of c::b site


[0] Message Index

Go to full version