Re: stdout redirection
From: William DePalo [MVP VC++] (willd.no.spam_at_mvps.org)
Date: 10/23/04
- Previous message: Jonathan Wilson: "Re: SDK download (and ATL)"
- In reply to: Nadav: "stdout redirection"
- Next in thread: Nadav: "Re: stdout redirection"
- Reply: Nadav: "Re: stdout redirection"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 23 Oct 2004 12:00:16 -0400
"Nadav" <Nadav@discussions.microsoft.com> wrote in message
news:37582031-D696-4C6F-94C8-05A2C047F7A3@microsoft.com...
> I am trying to redirect stdout to a RichEdit control, this is done by
> ...
> fd = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE),_O_APPEND);
> fp = _fdopen(fd,"w");
> *stdout = *fp;
> setvbuf(stdout, NULL, _IONBF, 0);
> But apparently it doesn't work: '_open_osfhandle' returns -1.
I resort to this redirection technique when I need to add more debug trace
capability than is convenient with OutputDebugString().
_If_ I recall correctly, when you redirect the standard output device of a
console application, any output you do in the main module _or_ in a DLL gets
redirected properly.
However, if you AllocConsole() in a windowed application and redirect
standard output to it, then the redirection works _only_ in the main module.
Any DLL loaded by the executable still "thinks" that it does not have a
standard output device because the executable image was not marked as a
console application when the DLL's runtime was initialized.
So, my _guess_ is that you need to pass the device handle of the console to
whatever executable component is redirecting output and redirect its
standard output as well. Of course, I might be wrong.
Regards,
Will
- Previous message: Jonathan Wilson: "Re: SDK download (and ATL)"
- In reply to: Nadav: "stdout redirection"
- Next in thread: Nadav: "Re: stdout redirection"
- Reply: Nadav: "Re: stdout redirection"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|