As a follow-up to the above, here's how you can wrapper .NET code and expose it to COM, making it available to Perl. The following example wrappers the .NET System.Console.Write and System.Console.WriteLine methods.
First, the .NET wrapper in C#. This is for .NET 2005
using System.Runtime.InteropServices; // visible to COM
// directive to tell COM to see this.
/* interface that our class will implement. Some examples use lead
+ing "_", some use "I"
* eg _WrapConsole or IWrapConsole
public interface _WrapConsole
// items to return
void WriteLine( string line);
void Write( string line);
// our class implements the interface defined above (after the ":"
public class WrapConsole : _WrapConsole
// COM needs a parameter-less constructor
// method to call WriteLine;
public void WriteLine(string line)
// method to call Write;
public void Write(string line)
At build time, through the VS 2005 IDE, check "Register for COM interop" in the Project Properties/Build section. From the commandline, you'd have to run 'regasm' to register the assembly into the Registry.
Next, the Perl code
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");
this is a test, should have a new line
this should not have a new line This should follow immediately, with a
+ new line
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||