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

Hello all, I would like to translate the following vb(a) code over to Perl but I have not had any success. I have read the doc on win32 and ole but I can not get this to work.

I have a COM DLL which has a method called RLVersion. The way I call it in VBA is the following:

Set MyObject = CreateObject("RL.RLClass") call MyObject.RLVersion(1,y) msgbox(y)

The 1 tells it the number of output arguements and y is obviously the output arguement. It passed back a 6 character string.

and this works fine.

Here is one of my many attempts at converting it to Perl. The WIn32::OLE works, but calling the RLVersion (method) does not.

use Win32::OLE qw(in with); my $RL = Win32::OLE->new('RL.RLlass') or die "oops\n"; my $myoutput = $RiskLib->RiskLibVersion->Call(1);

I would appreciate any help. I need to prove that this can work before I can start to learn perl and move completely away from vb/vbscript.

Thanks for any help you can provide.

Stephen

Replies are listed 'Best First'.
Re: Calling COM method
by Mr. Muskrat (Canon) on Feb 05, 2005 at 21:55 UTC

    1. You created the Win32::OLE object as $RL but you're trying to use $RiskLib in the next line.
    2. my $myoutput = $RiskLib->RiskLibVersion->Call(1); does not appear to be a direct translation of call MyObject.RLVersion(1,y) so how did you arrive at this Perl statement?

      RL vs RiskLib : I just copied the code over wrong. Sorry about that.

      My problem is that I don't know how to translate the CALL to perl. I have tried and searched through the perldocs, win32::api, this site and googled. When I try the following I get the error "Can not call method "RiskLibVersion" on an undefined value at myprog.pl line 3

      use Win32::OLE qw(in with); my $RL = Win32::OLE->new('RiskLib.RiskLibclass') or die "oops\n"; call $RL->RiskLibVersion(1,$y); print $y;

      Thanks

      Stephen

Re: Calling COM method
by Jenda (Abbot) on Feb 05, 2005 at 23:30 UTC

    In the VB code you pass two parameters to the RLVersion(), you should do the same in Perl. You just need to tell Win32::OLE that you want that parameter passed by reference. Something like this might help:

    use Win32::OLE::Variant; my $y = Variant(VT_BSTR || VT_BYREF, ""); $RL->RLVersion(1, $y); print $y;
    I think something like this should work.

    Jenda
    We'd like to help you learn to help yourself
    Look around you, all you see are sympathetic eyes
    Stroll around the grounds until you feel at home
       -- P. Simon in Mrs. Robinson