Q: ActivePerl - calling an ActiveX object

B

bubbabubbs

I have a 3rd-party ActiveX object (as a DLL) that I am trying to call
from Perl (ActivePerl 5.8) The function that I am calling takes three
'in' parameters, and returns the result via the fourth 'out'
parameter. So I need to pass the last parameter by reference, which I
know Perl supports. (Unfortunately, the 3rd party cannot/will not
modify the interface.)
Here is my ActivePerl script (slightly simplified):

################################################################
use Win32::OLE;
use Win32::OLE::Const 'Microsoft ActiveX Data Objects';

my $sLogFileName = "log.txt";
open( LOG, ">$sLogFileName" );

$arg4 = 0.0;
my $service = Win32::OLE->new( '3rdPartyComponent.Service' );
print LOG "before: " . $arg4 . "\n";
$service->foo( 31, 4000, 28000, \$arg4 );
print LOG " after: " . $arg4 . "\n";

$arg4 = 1.0;
my $service2 = Win32::OLE->new( '3rdPartyComponent.Service' );
print LOG "before: " . $arg4 . "\n";
$service2->foo( 31, 4000, 28000, \$arg4 );
print LOG " after: " . $arg4 . "\n";

close(LOG);
################################################################

Output from the script (log.txt):

before: 0
after: 0
before: 1
after: 1

I'm not getting any runtime errors, but $arg4 is not getting altered
after calling $service2->foo(). I know for the fact that after foo()
the value of $arg4 should be ~79.7 Also, I have tried calling the
ActiveX object from C++, and it works as expected. But the project
I'm working on requires me to use Perl. Does anyone have any ideas as
to what I am doing wrong.

I admit that I don't have a lot of experience with Perl, and am
learning as I go.

TIA

P.S. Is there a more appropriate newsgroup to post this to?
 
B

bubbabubbs

Sinan:

Thanks for your feedback. I made the code changes you suggested, but am
still not getting correct results from the ActiveX object. But I am not
getting any errors/warnings, either.

You are right, the method is not called 'foo', but something different.
I was hesitant, however, to provide the the method's real name in the
code snippet, as I'm not supposed to reveal proprietary information.
But I'm 100% sure aI am calling the right method.

What the method does is it implements a simple formula like arg4 =
(arg1-X)*arg2/arg3. At least that's what I've been able to figure out
by running some test cases and having the knowledge of the problem
domain. You are probably going to ask: "why don't you just implement
the formula in your code and forget about using the ActiveX object?" I
wish I could, but I can't... long story... the client and the 'suits'
insists on me using the ActiveX object.

Thanks
 
B

Ben Morrow

Quoth (e-mail address removed):
I have a 3rd-party ActiveX object (as a DLL) that I am trying to call
from Perl (ActivePerl 5.8) The function that I am calling takes three
'in' parameters, and returns the result via the fourth 'out'
parameter. So I need to pass the last parameter by reference, which I
know Perl supports.

Perl supports it for calling Perl subs, but Win32::OLE does not. You
need to use explicit Variants: see the section at the end of
Win32::OLE::Variant "Variants by reference".

Ben
 
B

bubbabubbs

Ok, I figured it out. This is how you do it:

my $arg4 = Variant( VT_R8 | VT_BYREF, 0.0); # !!!!
my $service = Win32::OLE->new( '3rdPartyComponent.Service' );
$service->foo( 31, 4000, 28000, $arg4 );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top