Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Query an object in Perl using Win32::OLE

by juo (Curate)
on May 25, 2004 at 12:41 UTC ( [id://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}); }

    --Solo
    --
    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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://356185]
Approved by EdwardG
Front-paged by Happy-the-monk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-24 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found