Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Exposing perl code as a COM object

by slloyd (Hermit)
on Dec 11, 2005 at 00:16 UTC ( #515767=perlquestion: print w/replies, xml ) Need Help??

slloyd has asked for the wisdom of the Perl Monks concerning the following question:

I friend asked me to expose my compiled perl code as a COM object. I am really not too familiar with COM. Any ideas on how I would do this?

by me

Replies are listed 'Best First'.
Re: Exposing perl code as a COM object
by holli (Abbot) on Dec 11, 2005 at 00:22 UTC
    You can use PerlScript from ActiveState and the Microsoft Script Component Wizard.

    I'll search for links tomorrow. atm i'm too tired.

    holli, /regexed monk/
        It's entirely free. You need ActivePerl, the Windows Scripting Host ((WSH) comes per default with XP), optionally the Windows Script Component Wizard and the Windows Script 5.6 Documentation.

        In a nutshell you create so called .wsc files, that contain code and metainformation so that script code can act as a COM component. the script code can be written in any language the supports the WSH, including Active Perl.

        Please see the "PerlScript", "Perlscript Examples" pages of the ActivePerl docs and the examples at \Perl\eg\Windows Script Components.

        holli, /regexed monk/
        perlscript comes for free... but PerlCrtl is not free. perlscript allows you to use wsh stuff... if you can write a control using wsh you can do it in perlscript. ( i dunno if you can) PerlCtrl is supposed to be a way to wrap full feature COM around perl programs.
Re: Exposing perl code as a COM object
by JamesNC (Chaplain) on Dec 12, 2005 at 15:03 UTC
    I second holli suggestion. I have used the Windows Script Component-WSC for lots of stuff and it works GREAT and you can even make it a Distributed COM object ( info in MicroSofts WSC docs ). Here is one serious pitfall that will save you some head scratching. The WSC file you create is installed most easily by right clicking the file and then selecting Register. You will also see an option "Generate Type Library". Don't waste your time. The Type Library it creates will throw a exception at runtime if you add it as a reference (in Excel or Word) because the object type defined in the Type Library does not and never could match the object you define in your WSC. MicroSoft acknowledges the problem, but doesn't change the docs or fix the problem...<sigh>. ActiveState's PerlCtrl DOES correctly generate the typelib, so if you need the typelib then purchase the PerlDevKit ( it is a great deal IMO and has lots of great stuff like perlapp and perltray and PerlNET ).

    After you read the docs and try the examples, you may wonder how to share a perl hash or array with the MicroSoft world. The key is to use Win32::OLE::Variant and Win32::OLE to create either a VT_ARRAY|VT_VARIANT (use the Put method to store ) or use OLE and CreateObject("Scripting.Dictionary") if you want to use a hash-like object ( and yes, you can save other objects as keys or values) "Scripting.Dictionary" was modeled after Perl hashes I believe.:-)
    I have some examples if you need more help. I am too busy right now to post them right now.
Re: Exposing perl code as a COM object
by JamesNC (Chaplain) on Dec 12, 2005 at 20:19 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://515767]
Approved by Old_Gray_Bear
Front-paged by holli
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2021-05-14 10:30 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (149 votes). Check out past polls.