wa4otj has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Still More help needed with Win32::OLE project.
by Solo (Deacon) on Jun 15, 2004 at 15:06 UTC | |
by wa4otj (Beadle) on Jun 15, 2004 at 15:33 UTC | |
by Solo (Deacon) on Jun 15, 2004 at 22:01 UTC |