in reply to Re: Perl for OLE & OCX
in thread Perl for OLE & OCX

Yes, my code does use the || die function to ensure the object is actually open. I also use Query Object type to verify it, and then LastError on closing to verify no errors. Actual code is:
use strict;
use Win32::OLE;
use Win32::OLE::Const;
my $HALi;

# Create a new OLE object using the Root Name of HALiCnt.HALi
  $HALi = Win32::OLE->new('HALiCnt.HALi') ||
  die "Cannot create COM server HALiCnt.HALi";

if (Win32::OLE->QueryObjectType($HALi) eq "_HALi"){
print "Successful Com Server creation\n";
}

my $c = $HALi->{'Modes'}->Count();
print $c;

$HALi->DESTROY(); # Call DESTROY to free memory and release the HALi Objects

print "Last OLE Error detected.. ";
print Win32::OLE->LastError();
I have also spent hours with the OLE Browser and OLEView. The object is created successfully, verified, and destroyed all with no errors. But when I try to retrieve Count, it croaks. I have tried many, many variations on the call to Modes.Count. The VB example is simply HALi.Modes.Count but I can't make the Perl translation work. If I had VB I'd try it to verify *IT* works, but I think the proper answer is the lack of IDispatch interface, which I guess means I'm dead.

Thanks for the help

Nathan

Replies are listed 'Best First'.
Re^3: Perl for OLE & OCX
by NetWallah (Canon) on Jun 16, 2004 at 19:26 UTC
         class CModes, which contains a property Count as a readonly Long

    <Lightbulb>
    OK so if Count is really a property, is should be accessed thus:

    my $c = $HALi->{'Modes'}{Count}; # or, my preference my $c = $HALi->{Modes}->{Count};
    </Lightbulb>

    Update: Just noticed that meetraz had the same idea, but his access method is slightly different.

    Offense, like beauty, is in the eye of the beholder, and a fantasy.
    By guaranteeing freedom of expression, the First Amendment also guarantees offense.

      Again, thanks for the suggestion, but tried it already. I get 'Object variable or With block variable not set' when I try that.

      Nathan