std::cout redirect causes crash under windows Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
ONeill
I live to help wx-kind
I live to help wx-kind
Posts: 152
Joined: Wed Oct 04, 2006 12:51 pm

std::cout redirect causes crash under windows

Post by ONeill »

Hello,

i want to redirect cout,cerr and clog to 3 wxTextCtrl's.

I do it like this:

Code: Select all

    wxTextCtrl *temp = new wxTextCtrl(this,-1,wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY);
    std::clog.rdbuf((std::streambuf*)temp);
    AddPage(temp, wxT("Ausgabe"), true);

    temp = new wxTextCtrl(this,-1,wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY);
    std::cerr.rdbuf((std::streambuf*)temp);
    AddPage(temp, wxT("Fehler"), false);

    temp = new wxTextCtrl(this,-1,wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY);
    std::cout.rdbuf((std::streambuf*)temp);
    AddPage(temp, wxT("Log"), false);
This works quite fine under Linux ( got one problem which i describe in another thread ), but under windows my programm crashes with a memory error.

Is there something i must think about under windows?

Thanks for help
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 »

Hm, that C cast isn't very nice.
wxTextCtrl is probably under windows no valid streambuf.
So, do you have the right flags set in your setup.h?
ONeill
I live to help wx-kind
I live to help wx-kind
Posts: 152
Joined: Wed Oct 04, 2006 12:51 pm

Post by ONeill »

What right flags do you mean?
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 »

Some compilers and/or build configurations don't support multiply inheriting wxTextCtrl from std::streambuf in which case this class is not compiled in. You also must have wxUSE_STD_IOSTREAM option on (i.e. set to 1) in your setup.h to be able to use it. Under Unix, specify --enable-std_iostreams switch when running configure for this.
http://wxwidgets.org/manuals/2.6.3/wx_w ... redirector
ONeill
I live to help wx-kind
I live to help wx-kind
Posts: 152
Joined: Wed Oct 04, 2006 12:51 pm

Post by ONeill »

If i compile with wxSTD_USE_IOSTREAM = 1.

I get some Linker errors:

Code: Select all

MyWorkspaceDialog.obj : error LNK2001: Nicht aufgel
S.Volkenandt
Knows some wx things
Knows some wx things
Posts: 26
Joined: Tue Nov 14, 2006 1:51 pm
Location: Duesseldorf, Germany

Post by S.Volkenandt »

You should not set wxSTD_USE_IOSTREAM manually. You have to configure wxWidgets (before compilation) to use iostreams so wxWidgets sets wxSTD_USE_IOSTREAM itself.

If you define wxSTD_USE_IOSTREAM for your application, but not when compiling wxWidgets, your application "assumes" that the iostreams mechanisms are available, but of course they aren't present in the DLLs/LIBs...
ONeill
I live to help wx-kind
I live to help wx-kind
Posts: 152
Joined: Wed Oct 04, 2006 12:51 pm

Post by ONeill »

Ok, i thought it is very strange only to set for my application ;)

Ok, i'll get a coffee and wait for compilation to finish ^^
Post Reply