How to print to console from COM library summoned with Activator from .NET code?

StackOverflow https://stackoverflow.com/questions/21403950

  •  03-10-2022
  •  | 
  •  

سؤال

There is COM object dll registered with regsvr32 in system which is doing some foo()

But how can I printf from it? e.g. I can't see anything if I just printf("test"); from it.

I'm getting my com object by progid

let A<'T> progid =
    Activator.CreateInstance
        ( Type.GetTypeFromProgID progid )
            :?> 'T

and call method alike myObj.foo()

هل كانت مفيدة؟

المحلول

You can call AllocConsole first to bring up a console window in your GUI application.

Note that if you do this, add the following lines after the AllocConsole call.

freopen ("CONOUT$", "w", stdout );
freopen ("CONERR$", "w", stderr );

Also, you can redirect stdout/stderr to a file by doing this:

C:\> myprogram.exe > out.txt 2> err.txt
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top