Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Query an object in Perl using Win32::OLE

by juo (Curate)
on May 25, 2004 at 12:41 UTC ( #356185=perlquestion: print w/replies, xml ) Need Help??
juo has asked for the wisdom of the Perl Monks concerning the following question:

I have tried my first attempt in Perl to use COM API function instead of using the VB but I find it so hard to do something simple in VB converted in Perl. I fail to simply find the way to query an object value. I am able to setup the link between the application that supports COM API using the following code but I cannot get any property value out.
#! perl -w use strict; use FileHandle; use Win32::OLE; my $Class = "ValorLepComApi.T5KAEFactory"; eval {$LEP = Win32::OLE->GetActiveObject($Class)}; die "LEP not installed" if $@;
In VB the following code works fine but I cannot get it converted to Perl
For each PLACEMENT in Recipe.Placements MsgBox PLACEMENT.PlacementPart.Refdes Next
The above simple code will get all the values out of the object PLACEMENT.PlacementPart.Refdes but I am not able to get this written in Perl. I looked all over the internet but could not find any example. Only examples on how to excecute things like in Excel but not query objects values. Any good books on general Object orientated programming in Perl for dummies.

Replies are listed 'Best First'.
Re: Query an object in Perl using Win32::OLE
by Solo (Deacon) on May 25, 2004 at 13:43 UTC
    VB hides a lot of the true complexity of OLE, because MS has spent the development effort to do so.

    You need to look at Win32::OLE::Enum, since you seem to be working with collections. Handling collections is also covered in the Win32::OLE POD under Functions.

    This code is untested, but I would try:

    use Win32; use Win32::OLE; use Win32::OLE::Enum; # louder errors Win32::OLE->Option(Warn => 3); ... my $Enum = Win32::OLE::Enum->new($Recipe->Placements); while (defined(my $placement = $Enum->Next)) { Win32::MsgBox($placement->PlacementPart->{Refdes}); } # - or - use Win32::OLE qw/ in /; for my $placement (in $Recipe->Placements) { Win32::MsgBox($placement->PlacementPart->{Refdes}); }

    You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.
      Thank you very much Solo for the documentation links and sample code. This is the headstart I needed. Your sample code works fine also. Pieter
Re: Query an object in Perl using Win32::OLE
by diotalevi (Canon) on May 25, 2004 at 12:57 UTC
    You may want to examine the source of Notes::OLE to see how I interact with Lotus Domino's COM objects. It may be similar for you.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://356185]
Approved by EdwardG
Front-paged by Happy-the-monk
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2017-08-19 09:42 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (310 votes). Check out past polls.