By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,709 Members | 2,155 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,709 IT Pros & Developers. It's quick & easy.

How to get stdout/stderr from unmanaged DLL?

P: n/a
I have setup Console redirection within my Console app (via Console.SetOut
and Console.SetErrror) to route console WriteLine calls to a logfile. This
works just fine with one exception...

I use PInvoke to call into several unmanaged DLLs which write diagnostic
information out to stdout (and possibly stderr). When I run in a
"standalone" mode with no redirection, these DLLs do generate output to the
console window. But I want to run in a "batch" mode where the app is
launched without a window. In this mode I still get all Console.WriteLine
and Console.Error.WriteLine output properly redirected, but lose all output
from the unmanaged DLLs.

Is there anything I can do to get output from an unmanaged, PInvoke'd DLL to
get redirected properly?

Thanks!
-- Tom

Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Thomas. What do you mean by "batch" mode without a window? Calling your
c# console app from a batch file?

--
William Stacey [MVP]

"Thomas W. Brown" <th************@countrywide.NOSPAM.com> wrote in message
news:00**********************************@microsof t.com...
I have setup Console redirection within my Console app (via Console.SetOut
and Console.SetErrror) to route console WriteLine calls to a logfile.
This
works just fine with one exception...

I use PInvoke to call into several unmanaged DLLs which write diagnostic
information out to stdout (and possibly stderr). When I run in a
"standalone" mode with no redirection, these DLLs do generate output to
the
console window. But I want to run in a "batch" mode where the app is
launched without a window. In this mode I still get all Console.WriteLine
and Console.Error.WriteLine output properly redirected, but lose all
output
from the unmanaged DLLs.

Is there anything I can do to get output from an unmanaged, PInvoke'd DLL
to
get redirected properly?

Thanks!
-- Tom

Nov 17 '05 #2

P: n/a
Not necessarily, I just mean in a non-interactive way. Actually what I'm
trying to do is the following. I have a WindowsService which responds to
specific IPC commands by starting a utility application. It is this utility
application for which I want to get stdout redirected to a log file.

Reassigning my own TextWriter via Console.SetOut and Console.SetError *does*
correctly route all Console.WriteLine and Console.Error.WriteLine type of
calls from my managed code despite the fact that the app is running without a
console window. But any output from PInvoked calls to these unmanaged DLLs
is lost. I ensure that a Console exists for my application (via
AllocConsole) but this doesn't have any effect.

I know I could redirect to a temp file on the process startup from my
service and then get all output after the fact, but then I would lose the
sequence of output between console output from the managed code and unmanaged
DLL output.

-- Tom

"William Stacey [MVP]" wrote:
Hi Thomas. What do you mean by "batch" mode without a window? Calling your
c# console app from a batch file?

--
William Stacey [MVP]

"Thomas W. Brown" <th************@countrywide.NOSPAM.com> wrote in message
news:00**********************************@microsof t.com...
I have setup Console redirection within my Console app (via Console.SetOut
and Console.SetErrror) to route console WriteLine calls to a logfile.
This
works just fine with one exception...

I use PInvoke to call into several unmanaged DLLs which write diagnostic
information out to stdout (and possibly stderr). When I run in a
"standalone" mode with no redirection, these DLLs do generate output to
the
console window. But I want to run in a "batch" mode where the app is
launched without a window. In this mode I still get all Console.WriteLine
and Console.Error.WriteLine output properly redirected, but lose all
output
from the unmanaged DLLs.

Is there anything I can do to get output from an unmanaged, PInvoke'd DLL
to
get redirected properly?

Thanks!
-- Tom


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.