Many thanks to the Perl Monks for helping me get this far. I am forced to report however that I still need some help. I am stuck trying to call a function, getting an error I do not understand.

Here is my code, with lots of comments at to how it behaves:

use Win32::OLE;
use Win32::OLE::Const;
my $HALi;

# Create a new OLE object using the CLSID of HALiCnt.HALi
## This works, or at least does not return any errors
  $HALi = Win32::OLE->new('{0533EA34-1857-443E-8A9F-62399F881402}') ||
  die "Cannot create COM server";


print "Text String representing TYPE of COM server via CLSID.. ";
print Win32::OLE->QueryObjectType($HALi);
## Returns the string 'HALiCnt.HALi', so I guess the previous 'NEW' was
## Successful
print "\n";



## The VB examples I have suggest that the system must be initialized
## at the start of the program with the VB command 'HALi.Init()'
## So I translate this to::::
$HALi->Init();
## Fails with "This Key Already associated with an element of this collection
## I had tried many other combinations, but this is the only
## format that generates anything other than "invalid class string"
# However, if I do not make the Init call, but instead call destroy
$HALi->DESTROY(); # Call DESTROY to free memory and release the HALi Objects
# Then this appears to work just fine.

print "Last OLE Error detected.. ";
print Win32::OLE->LastError();
## Returns a '0' if I do not call Init() but returns the error posted 
So I am fairly sure that I am opening the correct COM objects, and the fact that I get the "already associated" error implies that the Init() function is present. But I am doing it incorrectly somehow.

Here is the result of the actual run:

C:\perl>testole.pl
Text String representing TYPE of COM server via CLSID.. HALiCnt_HALi
OLE exception from "HALiCnt":

This key is already associated with an element of this collection

Win32::OLE(0.1403) error 0x800a01c9
    in METHOD/PROPERTYGET "Init" at C:\perl\testole.pl line 26
Last OLE Error detected.. OLE exception from "HALiCnt":

This key is already associated with an element of this collection

Win32::OLE(0.1403) error 0x800a01c9
    in METHOD/PROPERTYGET "Init"
C:\perl>
I have spent hours studying docs and experimenting with different forms of the Init() function. I have used OLEView to look at the object libraries and the OLE Browser as well. Any format other than the one gives me "invalid Class String".

I am once again lost, and in need of enlightenment.

Thanks,

Nathan


In reply to Still More help needed with Win32::OLE project. by wa4otj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.