I am writing some code for driving Internet Explorer from a Perl 5 program through Win32::OLE
, and I am looking for ways to convert numeric status/error codes that are delivered back to the Perl program via events (such as NavigateError
) into a somewhat more human-readable form.
Is there some kind of library function that converts i.e. 0x800C0005L or -2146697211 to "INET_E_RESOURCE_NOT_FOUND"
or something even more readable?
I have tried Win32::FormatMessage()
, but that seems to work only for non application-specific error conditions.
Update: Here is some example code for clarification. Some test output is shown below.
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use Time::HiRes qw(sleep time);
use Win32::OLE qw(EVENTS);
use Win32::OLE::Variant;
$|++;
sub ie_browse {
my $url = shift;
my $ie = Win32::OLE->new('InternetExplorer.Application') or die;
Win32::OLE->WithEvents($ie,
sub {
my ($obj, $event, @args) = @_;
given ($event) {
when ('NavigateComplete2') {
push @extra,
'url='.($args[1]->As(VT_BSTR));
say "$event: @extra";
}
when ('NavigateError') {
push @extra,
'url='.($args[1]->As(VT_BSTR)),
'statuscode='.($args[3]->As(VT_I4));
say "$event: @extra";
}
}
}, 'DWebBrowserEvents2');
Win32::OLE->SpinMessageLoop;
$ie->{visible} = 1;
Win32::OLE->SpinMessageLoop;
$ie->Navigate2($url);
Win32::OLE->SpinMessageLoop;
while(1) {
Win32::OLE->SpinMessageLoop;
sleep(0.1);
}
}
ie_browse $ARGV[0];
Here is some output for two fetch attempt. Fetching the Stack Overflow page is successful, of course.
C:\Documents and Settings\nobody\Desktop>perl ie.pl http://stackoverflow.com/
NavigateComplete2: url=http://stackoverflow.com/
Terminating on signal SIGINT(2)
But example.invalid
doesn't exist.
C:\Documents and Settings\nobody\Desktop>perl ie.pl http://example.invalid/
NavigateError: url=http://example.invalid/ statuscode=-2146697211
NavigateComplete2: url=http://example.invalid/
Terminating on signal SIGINT(2)
I am interested in turning that numeric value (-2146697211) that has been passed back into something useful. This is not an OLE error as such but an error condition signaled by the Internet Explorer COM object.