How to redirect stdout, stderr from a PInvoke'd DLL

dotnet framework

    Next

  • 1. How to assign an object reference to an System.IntPtr structure??
    I have got an Interface method that takes a void*. Dot Net interprets it as a System.IntPtr structure. I now want to pass a COM interface reference through the IntPtr type. How can i achieve this???
  • 2. Why does COM not find the file?
    I have written a C# executable, which I run regasm on to register it as a COM class for use in some unmanaged C++ code. Im the C++ code, I import the mscorlib.tlb and my .tlb file, declare some interface variables, and start COM just fine... but when I try to get an IUnknown interface pointer, or my custom interface pointer for the class I exposed, I get the following error: "Class not registered" -OR- something like could not find file. It does not list what file. What am I doing wrong in the exporting of this C# class? Thanks in advance Andrew S. Giles
  • 3. Arrays as properties and CCW
    I have been having some problems passing an array from VB6 to my C# CCW. Can anbody help me out? Here's some sample test code: C# Code: public class TestClass { public TestClass() { } } /// <summary> /// Summary description for Class1. /// </summary> public class TestArrayClass { public TestArrayClass() { } public TestClass[] testClassArray; public void SetTestClassArray(TestClass[] classes) { this.testClassArray = classes; } } VB6 Code: Dim testClassArray(0 To 1) As Object Set testClassArray(0) = CreateObject("CSharpTestClassLibrary.TestClass") Set testClassArray(1) = CreateObject("CSharpTestClassLibrary.TestClass") test.SetTestClassArray (testClassArray) test.testClassArray = testClassArray The problem is that the last line of the vb code (test.testClassArray = testClassArray) fails with the error "Invalid procedure call or argument". However, passing the array through the method (test.SetTestClassArray (testClassArray)) works just fine. Am I doing something wrong here?
  • 4. ASP.Net and ServicedComponent class not working together? [C#]
    Hi everyone, I have a toy class that inherits from ServicedComponent and a hand-crafted interface. It looks like this: [Transaction(TransactionOption.Supported)] public class myclass: ServicedComponent, IReadData //IReadData is the hand-blown interface { public string GetString() { return "hello"; } [AutoComplete] public string GetData(string strParameters) { return "goodbye"; } } } I've put this into a COM+ package, using regsvcs.exe, and made the package as "open" as possible-- no security access checks, for instance. It's running as a server application under COM+. Here's the trouble: calling the class's GetData() method in a console app works fine, but the same call from an ASP.Net page gives an error that says: "System.InvalidCastException: QueryInterface for interface Interfaces.IReadData failed." Here's my definition of the IReadData interface-- it's simple enough: public interface IReadData { { string GetData(string strParameters); } } Am I doing something wrong here that I can't see? Are you allowed to inherit from interfaces at the same time as ServicedComponent, or are there restrictions regarding this I don't know about? Or, is there something else entirely at work? I'm scratching my head as to why this is happening. Thanks for any and all help. -Jim

How to redirect stdout, stderr from a PInvoke'd DLL

Postby VGhvbWFzIFcuIEJyb3du » Wed, 15 Jun 2005 02:44:07 GMT

As the subject indicates, I'm PInvoking unmanaged DLLs via my .NET 
application.  These DLLs (which I have to control over) output diagnostic 
information to stdout which I would like to intercept.  I can install my own 
TextWriter derived class as the output and error writers for Console but only 
managed Console writes get sent to my writer, the PInvoked DLL writes to 
stdout are still sent somewhere into the bit bucket.

Can anyone tell me what I may be missing??

Thanks,
-- Tom


Similar Threads:

1.Redirecting stdout/stderr on child process to a window

I'm developing a Windows CE 5.0 app using C# and I need to call a child
process and then capture its stdout/stderr into the textbox of a
window. So I'm P/Invoking the CreateProcess() function and the
SetStdioPathW() function. However, it seems that SetStdioPathW() is
intended for redirecting output to a file, not a window. What should I
be using instead?

2.Redirecting sdtin, stdout, stderr from an already running process

I am trying to redirect stdin, stdout, stderr of a process I started
with the win32 call CreateProcessAsUser, since I couldn't find a way
to start a process with .net that used a user name and password and
didn't show any kind of window.  The only way I can see to do redirect
the input and output now is to continue to use the win32 API (maybe a
pipe?).  Is there a way to do this with .net?  Can I get the process
input and output into a stream or something?

3.child process with redirected stdout and stderr

I need to create a child process and read the child's stdout and stderr in
the parent process. This seems to be surprisingly difficult to do in .NET.

The documentation for the System.Diagnostics.Process class talks about
creating separate threads for reading each stream.

Is there an easier way? Has anyone already written a wrapper?

Thanks.


4.can't redirect stdout and stderr in VC++ 7.1

I've just upgraded from VC++ 6.0 to Visual Studio 2003.  I've got a bunch of 
cout statements in my code for debugging purposes, just to record some info 
on what is happening in a UDP socket interface... i.e. stuff I can't readily 
look at with the debugger without perturbing the results.  Now for my 
problem...

In 6.0, I just put the argument " > log.txt" on the in the program argument 
field and my output was redirected to the log file with no problems.

In 7.1, I've followed the directions specified in the help, which say to put 
"> filename", without the quotes, in the command arguments in the debugging 
section of the property page.  Nothing happens.  I don't get a log file.  

I found one reference in the Knowledge Data Base to there being a problem 
with this in Windows NT 4.0, but I'm running XP, and I just made sure I've 
got all the Service Packs downloaded and the latest .Net bugfixes installed.

This seems like such a simple thing?  Any ideas what I might be missing?

Thanks,
Anne

5.How to get stdout/stderr from unmanaged DLL?

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

6. Capturing spawned child process's STDOUT & STDERR

7. Redirect stdout from unmanaged DLL

8. Windows CE + C# : How to redirect stdout/stderr of child process?



Return to dotnet framework

 

Who is online

Users browsing this forum: No registered users and 19 guest