Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Working with COM objects

by MadraghRua (Vicar)
on May 21, 2009 at 21:30 UTC ( #765553=perlquestion: print w/replies, xml ) Need Help??
MadraghRua has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks I am working with a windows application that has a COM interface library. I have some example Jscript that runs that I am now converting into Perl. So the Jscript looks something like this:

var server = new ActiveXObject("DataServer.Access"); var data = server.Object.Item var tool = new ActiveXObject("ToolServer.Tool"); findResult(data,tool); function findResult(data,tool) { tool.Clear; tool.Data = data; ... }
This is my interpretation of this in Perl:

#!/usr/bin/perl -w use strict; use Win32::OLE; use Dumpvalue; my $dumpvalue = Dumpvalue->new; my $server = Win32::OLE->new('DataServer.Access'); my $data = server->Object->Item; my $tool = Win32::OLE->new('ToolServer.Tool'); $tool->clear; $tool->Data = $data; $dumpvalue->dumpValue(\$tool);
Its the second last line that I don't understand. If I understand what I am supposed to do, the $tool object needs to have the Data attribute populated with the $data object. When I dump $data and $tool, I see hashes populated with data. For instance in $tool I can see:

'Completed' => 0 'Error' => '' 'Data' => undef 'Results' => Win32::OLE=HASH(0x209d2f4) 'Count' => 0 'Item' => undef 'Settings' => Win32::OLE=HASH(0x2098ae4) ...
and so on. So in this hash you can see that 'Data' => undef - I would like it set to $data.

I have looked the the documentation for Win32::OLE and I'm simply not clear on what the syntactic sugar is that I need to assign the $data instance to the $tool->Data attribute. What I have shown typically throws the following warning: Win32::OLE(0.1707) error 0x80020003: "Member not found" in PROPERTYPUTREF "data" at line 12

I've tried variations on assigning the $data instance to $tool->Data,including

$tool->Data = $data; $tool{Data} = $data; $tool{'Data'} = $data; $tool{'Data'} = $$data;
and so on.

I'm also open to any suggestions on what to try next. I'm also interested in finding out anything that that would allow me to observe the contents of the Jscript variables so I could better understand what is being passed there and where it is going.


yet another biologist hacking perl....

Replies are listed 'Best First'.
Re: Working with COM objects
by ig (Vicar) on May 22, 2009 at 00:20 UTC
Re: Working with COM objects
by MadraghRua (Vicar) on May 22, 2009 at 19:07 UTC
    Alright, I had a deeper look into Win32::OLE and came across the following

    $tool->LetProperty('Molecule',$data); $tool->setProperty('Molecule, $data);
    So it turns out that the LetProperty method loads the $data instance into the Molecule attribute of the $tool instance. I'll be looking more closely at this to understand why this worked over the previous syntactic sugars that i was using.

    I hope this node helps someone else in the future

    yet another biologist hacking perl....

      In Win32::OLE property assignment using the hash syntax is equivalent to the Visual Basic Set syntax (by reference assignment):

              $Object->{Property} = $OtherObject;

      corresponds to this Visual Basic statement:

              Set Object.Property = OtherObject

      To get the by value treatment of the Visual Basic Let statement

              Object.Property = OtherObject

      you have to use the LetProperty() object method in Perl:

              $Object->LetProperty($Property, $OtherObject);

      LetProperty() also supports optional arguments for the property assignment. See OBJECT->SetProperty(NAME,ARGS,VALUE) for details.

Re: Working with COM objects
by MadraghRua (Vicar) on May 22, 2009 at 17:37 UTC
    Alas I tried this and several variations on the theme but to no avail.

    OK, so here's the question reconfigured - I have two instances of two separate COM objects - tool and data. Tool instance has several attributes and a couple of methods. However one of the attributes is that it takes an instance of a data object for Tools->{data}. When I look at these things via Dumpvalue, I see that objects are typically represented in the data structure as a hash address and then you see a cascade of the data present under that hash address. So in the example above, I can see tools->{Results} has a Win32::OLE hash address and then you see the data under it.

    How would I do something like this for my Data object - perhaps there is something FUBAR'd under creating this Win32::OLE hash address for this COM object and simply supplying this would solve the problem. I've tried passing $data instance as /$data and as a passed reference

    $thingref = /$data; $tool->{Data} = $thingref;
    I know in Jscript that I can simply pass set tool.Data = data How do I do this in Perl?

    Win32::OLE is the best way to tackle this - yes? Or is there something else I should be looking at?


    yet another biologist hacking perl....

      | \|/ V my $data = server->Object->Item; ^ /|\ |

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://765553]
Approved by ikegami
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2017-05-29 23:52 GMT
Find Nodes?
    Voting Booth?