Win32::OLE uses late binding (the IDispatch interface, aka OLE Automation); 
there is no such thing as casting to different "objects"
as there is only a single IDispatch interface per object.  This is the same as 
using Jscript or VBScript, but not VB or C++ which
normally use early binding.

 

It is up to the developer of the object to make sure all interfaces are 
automation accessible.  Ask them for sample code in VBScript
or VBA.  If you cannot access the interfaces from there, then you won't be able 
to access them via Win32::OLE either.

 

Cheers,

-Jan

 

 

From: [email protected] 
[mailto:[email protected]] On Behalf Of
[email protected]
Sent: Wednesday, December 16, 2009 11:40 AM
To: [email protected]
Subject: How to simulate VB "Casting" for $perl_objects via Win32::OLE?

 

Hi --

 

Short version: how can we simulate .NET/VB object-type CASTing, in Win32::OLE 
Perl?

 

Long version:

 

We're building a bridge between a java-web-app and a .net-based-desktop app. 
Perl is the glue language of choice, of course :)

 

Where we've got trouble is that the .net programmers tell us we need to "cast" 
object_1 to be type object_2, and we haven't see how
that's done in the Win32::OLE manual pages.

 

For example we start with a Collection, iterate through 
CoursesCollection->Item(ix) and from there we get a
StudentsCollection->Item( foo ) which is a generic object but needs to be CAST 
as a 'proper' Student object instead. How do we do
that in Win32::OLE?


my $classes = App->Classes;

my $class_ct = $classes->Count;

for ( my $class_ix = 1; $class_ix <= $class_ct; $class_ix ++ ) {

  my $class = $classes->Item( $class_ix );

 

  my $students = $class->Students;

  my $stu_ct = $students->Count;

  for ( my $stu_ix = 1; $stu_ix <= $stu_ct; $stu_ix ++ ) {

    my $stu = $students->Item( $stu_ix );

 

   # $stu is a GENERIC object here with only basic methods

   # need to 'cast' it to "Student" type so we can get grades

   my $grades = $stu->Grades; # boom! (Name not found, meaning no such method)

  }

}

 

We were hoping the objects were classed somehow inside Perl, but all objects 
appear to be simply Win32::OLE objects, and even trying
to get to the hash keys gives an error...

 

Any pointers/flames welcome. Thanks!


-- 
will trillich
"Tis the set of the sails / And not the gales / That tells the way we go." -- 
Ella Wheeler Wilcox

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to