Q: ActivePerl - calling an ActiveX object

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default Q: ActivePerl - calling an ActiveX object

    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?

    bubbabubbs@yahoo.com Guest

  2. Similar Questions and Discussions

    1. ActiveX component can't create object
      I'm having problems setting up a monstrous COM+ Frankenapp on my local machine. The application works on the development server when I access it...
    2. 3rd Party ActiveX Object not working
      I have been able to use a 3rd Party ActiveX object in a ASP.NET (using ASPCOMPAT=TRUE and impersonation), .NET C# Windows (form) application and...
    3. Calling a MFC ActiveX Control from a ASP.net web service.
      I am looking for some information about a problem I have run into. I have a third party MFC ActiveX Control and I would like to wrap it with a...
    4. Calling Acrobat file from WScript.Shell ActiveX object
      WinXP, Acrobat 6 When I type the name of a PDF file at the Windows command prompt, the file opens properly. Then I create the following JavaScript...
    5. problems calling ActiveX control inside VB OCX from ASP
      I seem to have run into two documented bugs whose workarounds are incompatible. What I have is an OCX written in VB 6 that has a few classes in it....
  3. #2

    Default Re: Q: ActivePerl - calling an ActiveX object

    [email]bubbabubbs@yahoo.com[/email] wrote in news:1154481724.075186.314530
    @i42g2000cwa.googlegroups.com:
    > 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.)
    Given that we have no idea what this component is, it is hard to come up
    with specific recommendations. I'll make some general comments below.

    > Here is my ActivePerl script (slightly simplified):
    >
    > ################################################## ##############
    use strict;
    use warnings;
    > use Win32::OLE;
    > use Win32::OLE::Const 'Microsoft ActiveX Data Objects';
    Win32::OLE->Option(Warn => 3);
    > my $sLogFileName = "log.txt";
    > open( LOG, ">$sLogFileName" );
    open my $log_fh, '>', $sLogFileName
    or die "Cannot open '$sLogFileName': $!";
    > $arg4 = 0.0;
    my $arg4 = 0.0;
    > my $service = Win32::OLE->new( '3rdPartyComponent.Service' );
    > print LOG "before: " . $arg4 . "\n";
    print $log_fh "before: $arg4\n";
    > $service->foo( 31, 4000, 28000, \$arg4 );
    I seriously doubt the service provides a method named 'foo'. There is no
    way for us to determine if you are using the correct method.

    It is possible the higher warning setting for Win32::OLE will give some
    useful information.

    Sinan
    --
    A. Sinan Unur <1usa@llenroc.ude.invalid>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    [url]http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html[/url]

    A. Sinan Unur Guest

  4. #3

    Default Re: Q: ActivePerl - calling an ActiveX object

    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


    A. Sinan Unur wrote:
    > [email]bubbabubbs@yahoo.com[/email] wrote in news:1154481724.075186.314530
    > @i42g2000cwa.googlegroups.com:
    >
    > > 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.)
    >
    > Given that we have no idea what this component is, it is hard to come up
    > with specific recommendations. I'll make some general comments below.
    >
    >
    > > Here is my ActivePerl script (slightly simplified):
    > >
    > > ################################################## ##############
    >
    > use strict;
    > use warnings;
    >
    > > use Win32::OLE;
    > > use Win32::OLE::Const 'Microsoft ActiveX Data Objects';
    >
    > Win32::OLE->Option(Warn => 3);
    >
    > > my $sLogFileName = "log.txt";
    > > open( LOG, ">$sLogFileName" );
    >
    > open my $log_fh, '>', $sLogFileName
    > or die "Cannot open '$sLogFileName': $!";
    >
    > > $arg4 = 0.0;
    >
    > my $arg4 = 0.0;
    >
    > > my $service = Win32::OLE->new( '3rdPartyComponent.Service' );
    > > print LOG "before: " . $arg4 . "\n";
    >
    > print $log_fh "before: $arg4\n";
    >
    > > $service->foo( 31, 4000, 28000, \$arg4 );
    >
    > I seriously doubt the service provides a method named 'foo'. There is no
    > way for us to determine if you are using the correct method.
    >
    > It is possible the higher warning setting for Win32::OLE will give some
    > useful information.
    >
    > Sinan
    > --
    > A. Sinan Unur <1usa@llenroc.ude.invalid>
    > (remove .invalid and reverse each component for email address)
    >
    > comp.lang.perl.misc guidelines on the WWW:
    > [url]http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html[/url]
    bubbabubbs@yahoo.com Guest

  5. #4

    Default Re: Q: ActivePerl - calling an ActiveX object


    Quoth [email]bubbabubbs@yahoo.com[/email]:
    > 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

    --
    Giles: It's very common for Indian spirits to change to animal form.
    Buffy: [...] and, 'Native American'. G: Sorry? B: We don't say 'Indian'.
    G: Oh, right, yes; always behind on the terms... yes, still trying not to refer
    to you lot as 'bloody colonials'. [Buffy, 'Pangs'] [email]benmorrow@tiscali.co.uk[/email]
    Ben Morrow Guest

  6. #5

    Default Re: Q: ActivePerl - calling an ActiveX object

    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 );

    bubbabubbs@yahoo.com Guest

  7. #6

    Default Re: Q: ActivePerl - calling an ActiveX object

    [email]bubbabubbs@yahoo.com[/email] wrote in news:1154555107.290341.146720
    @i42g2000cwa.googlegroups.com:
    > 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 );
    First off, thank you very much for sharing the solution. I am sure knowing
    that will help me some time in the future.

    I would like to point out, however, that it is useful to leave some
    context in your post so others can also understand what you figured out.

    See the posting guidelines for this group.

    Sinan
    --
    A. Sinan Unur <1usa@llenroc.ude.invalid>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    [url]http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html[/url]

    A. Sinan Unur Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139