puff has asked for the wisdom of the Perl Monks concerning the following question:

The following perl/Win32::OLE program crashes perl with Unhandled exception at 0x7c94eb28 in perl.exe: 0xC0000029: An invalid unwind target was encountered during an unwind operation. I've spent considerable time tryine to find the issue without success. Can anyone help? If nothing else, would some kind soul please run it on their machine and let me know if it crashes in other environments.

Thanks!
#!/usr/bin/perl -w # # use local version of mech with alternate page completion logic # use strict; use warnings; use Time::HiRes qw(gettimeofday); use URI; use Win32::OLE qw( EVENTS in with valof ); use Win32::OLE::Variant; my $t_start; my $tend = gettimeofday; my $url; my $urlCounter= 0; my $timeTestStart = time(); my $t_now; my $t_last_event; my $dl_tot = 0; my $dl_cnt = 0; my $timedelay = 5; my $timeout = 60; $|=1; my $ie = Win32::OLE->new( 'InternetExplorer.Application' ) or die( "Cannot create an InternetExplorer.Application" ); $ie->{menubar} = 1; $ie->{toolbar} = 1; $ie->{statusbar} = 1; $ie->{visible} = 1; # give IE a chance to get itself established print "IE should be visible\n"; $ie->navigate('about:blank'); sleep 5; Win32::OLE->WithEvents( $ie, \&win32_ie_events, "DWebBrowserEvents2" ) +; $Win32::OLE::Warn = 2; # I'll deal with errors myself #$Win32::OLE::Warn=3; # force a croak on errors my $vttrue = Variant(VT_BOOL, 1); my @urls = qw( http://www.whitehouse.gov http://www.cnn.com http://www.popuptest.com/popuptest12.html http://www.popuptest.com/popuptest1.html http://www.instantattention.com/?aid=1589 ); foreach $url (@urls) { $url =~ s/\s//; if( $url =~ /^#/) { next; } # do not nav to pdf files if( $url =~ /^$/) { next; } $urlCounter++; my $elapsed = time() - $timeTestStart; my @xtime = gmtime($elapsed); print "\n\n"; print localtime(time) . " elapsed " . $xtime[2] . ":" . $xtime[1] +. ":" . $xtime[0] . "\n"; print "url $urlCounter $url\n"; $dl_tot = 0; $dl_cnt = 0; $t_start = $t_last_event = gettimeofday(); $ie->navigate($url); while (1) { #print "."; Win32::OLE->SpinMessageLoop; if(Win32::OLE->LastError) { print "OLE error after sping loop ", Win32::OLE->LastError +, "\n"; die "OLE error\n"; } # get current time $t_now = gettimeofday(); # check if navigation is complete if((($t_now - $t_last_event) > $timedelay) && # no events f +or a bit ($ie->ReadyState == 4) && # browser says + it's ready $dl_tot && # we've had so +me downloads ($dl_cnt == 0)) { # we've had eq +ual number of download completes print "done ok\n"; last; # we're done } # check for timeout if(( $t_now - $t_start ) > $timeout ) { # temp code, this hangs sometimes, need x19 style stuff, s +ometimes this seems to hang!! print "timeout\n"; sleep 5; last; } } my $seconds = $t_last_event - $t_start; print "Returned $seconds\n"; } $ie->close; exit; sub win32_ie_events { my( $agent, $event, @args ) = @_; $t_last_event = gettimeofday(); print "--- "; CASE: { $event eq 'DownloadBegin' and do { $dl_cnt++; last CASE; }; $event eq 'DownloadComplete' and do { $dl_cnt--; $dl_tot++; last CASE; }; $event eq 'NewWindow2' and do { print "NewWindow2 kill popup\n"; $args[1]->Put( 1 ); # doesn't work print "cancel[" .$args[1]->Value() . "]\n"; last CASE; }; $event eq 'NewWindow3' and do { print "NewWindow3 kill popup\n"; print "$args[2], $args[3], $args[4]\n"; $args[1]->Put( 1 ); # doesn't work print "cancel[" .$args[1]->Value() . "]\n"; last CASE; } } my $te = sprintf '%6.2f', $t_last_event - $t_start; print "$te $dl_cnt $dl_tot [$event]\n"; if(Win32::OLE->LastError) { print "OLE error ", Win32::OLE->LastError, "\n"; die "OLE error\n"; } }
Some additional research indicates that code that previously was able to block popups no longer works (although it does not crash perl)
#!perl use strict; use warnings; use Win32::OLE qw/EVENTS/; use Win32::OLE::Variant; my $ie = Win32::OLE->CreateObject('InternetExplorer.Application', 'Qui +t') or die "Can't start IE", Win32::OLE::LastError(); $ie->{Visible} = 1; $|++; Win32::OLE->WithEvents($ie, 'main', 'DWebBrowserEvents2'); $ie->GoHome; Win32::OLE->MessageLoop(); sub NewWindow2 { my ($self, $browser, $cancel) = @_; $cancel->Put(1); print "$self->{LocationURL} tried to open a new window!\n"; } sub OnQuit { Win32::OLE->QuitMessageLoop; }


More ..........

It turns out that there is a bug in the current version of Win32::OLE that causes the crash. Jan Dubois has sent a patch and I expect there will be a new version available shortly. Thanks very much Jan!

Based on my testing other posted popup blockers (http://www.perlmonks.org/index.pl?node_id=273090, and http://www.roth.net/perl/scripts/scripts.asp?IEEVENTS.PL) that use Win32::OLE also fail. I believe that Jan's patch addresses them all. If this is not the case, I will post accordingly.