Checking LastError is usually the best course of action.
If you are looking for just the number (like VB's Err.Number) here's a
few ways of doing it.
use Win32::OLE;
$this = Win32::OLE->new("This.That");
if (Win32::OLE->LastError != 0) {
printf ("hex = 0x%x\n", Win32::OLE->LastError());
print "dec = ".(Win32::OLE->LastError()+0)."\n";
print "Full Desc = ".Win32::OLE->LastError()."\n";
}
Which outputs the following:
hex = 0x800401f3
dec = -2147221005
Full Desc = Win32::OLE(0.1702) error 0x800401f3: "Invalid class string"
HTH
Steven
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Samuel Meder
Sent: Thursday, December 22, 2005 10:03 AM
To: [email protected]
Subject: COM, PerlScript and error handling
I've written a fairly simple script that creates a few COM object
handles and invokes methods on them (in my case related to managing
Virtual Server). This looks something like:
my $handle = $WScript->CreateObject("Foo.Application");
my $resultingObject = $handle->method();
Now, a call to "method" will sometimes result in a error and no object
will be returned. In that case I can check if $resultingObject is
undefined, but I've not been able to find any documentation about how to
get to the error (which seems to end up in some global/ contextual
object). So the questions I have are:
* Can I get to this error using Win32::OLE->LastError(). Will that mix
well with my perlscript use or should I just rewrite the whole thing
using Win32::OLE calls?
* Is the source for the perl <-> WSH glue code available somewhere? I
downloaded the activatstate perl source dist and couldn't find it there.
* Is there a better way to do this in perlscript? Is there another
global variable I can just access? (similar to Err in VBScript).
/Sam
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs