stdout redirection
From: Nadav (Nadav_at_discussions.microsoft.com)
Date: 10/23/04
- Next message: Jonathan Wilson: "Re: SDK download (and ATL)"
- Previous message: Gary Chang[MSFT]: "RE: MC++ Unmanaged MFC calling Managed WinForm class"
- Next in thread: William DePalo [MVP VC++]: "Re: stdout redirection"
- Reply: William DePalo [MVP VC++]: "Re: stdout redirection"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 23 Oct 2004 04:29:02 -0700
Hi,
Introduction:
***************
I am trying to redirect stdout to a RichEdit control, this is done by
initiating a StringWriter, associated it with a StringBuilder and setting the
Console.Out to the String Writer, when ever the RichEdit is to be updated
text from the StringBuilder is being copied.
The Problem:
***************
What was just described works well as long as I am dealing with managed
code, my managed app loads some inproc unmanaged DLLs using PInvoke, these
DLLs are using printf*.* to write to the stdout, BUT when redirecting stdout
in the manner just described all of the data being printed by the unmanaged
app doesn’t show on the redirected console output.
I have tried redirecting the unmanaged code output in the following manner:
int fd = 0;
FILE *fp = 0;
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. ( internally
GetFileType doesn’t recognize the stdout handle returned by ‘GetStdHandle’ As
a valid file handle…
What should I do how can I redirect the unmanaged stdout to the same
destination as the managed stdout? I would expect the unmanaged code to
transparently write to the redirect stdout….
Any help would be appreciated.
--
Nadav
http://www.ddevel.com
- Next message: Jonathan Wilson: "Re: SDK download (and ATL)"
- Previous message: Gary Chang[MSFT]: "RE: MC++ Unmanaged MFC calling Managed WinForm class"
- Next in thread: William DePalo [MVP VC++]: "Re: stdout redirection"
- Reply: William DePalo [MVP VC++]: "Re: stdout redirection"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|