I am writing code to launch Internet Explorer from Perl 5 through Win32::OLE, and I am looking for ways to convert numeric status / error codes that are delivered back to the Perl program through events (for example NavigateError) in a slightly more readable form.
Is there some kind of library function that converts, for example, 0x800C0005L or -2146697211, into "INET_E_RESOURCE_NOT_FOUND"or something even more readable?
I tried Win32::FormatMessage(), but it seems to work only for error conditions that are application independent.
Update: Here is a sample code for clarification. Some test conclusion is shown below.
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];
.
, .
C:\Documents and Settings\nobody\Desktop>perl ie.pl http:
NavigateComplete2: url=http:
Terminating on signal SIGINT(2)
example.invalid .
C:\Documents and Settings\nobody\Desktop>perl ie.pl http:
NavigateError: url=http:
NavigateComplete2: url=http:
Terminating on signal SIGINT(2)
(-2146697211),
- . OLE ,
COM- Internet Explorer.