using System;
using System.Runtime.InteropServices; // visible to COM
using System.Collections.Generic;
using System.Text;
namespace WrapConsole
{
// directive to tell COM to see this.
[ComVisible(true)]
/* interface that our class will implement. Some examples use leading "_", some use "I"
* eg _WrapConsole or IWrapConsole
*/
public interface _WrapConsole
{
// items to return
[DispId(1)]
void WriteLine( string line);
[DispId(2)]
void Write( string line);
}
[ComVisible(true),
ClassInterface(ClassInterfaceType.None),
ProgId("WrapConsole")]
// our class implements the interface defined above (after the ":")
public class WrapConsole : _WrapConsole
{
// COM needs a parameter-less constructor
public WrapConsole()
{
}
// method to call WriteLine;
[ComVisible(true)]
public void WriteLine(string line)
{
System.Console.WriteLine(line);
}
// method to call Write;
[ComVisible(true)]
public void Write(string line)
{
System.Console.Write(line);
}
}
}
####
use Win32::OLE;
my $wc = Win32::OLE->new('WrapConsole') or die "oops\n";
$wc->WriteLine( 'this is a test, should have a new line');
$wc->Write( 'this should not have a new line ');
$wc->Write( "This should follow immediately, with a new line\n");
####
>perl pWrapConsole.pl
this is a test, should have a new line
this should not have a new line This should follow immediately, with a new line