I was traveling last week and when I tried to send this to the list it bounced. Hopefully this will get through.
_____ From: Richard Bell [mailto:[EMAIL PROTECTED] Sent: Thursday, November 17, 2005 4:31 PM To: libwin32@perl.org Subject: Win32::OLE event handling and IE automation questions I'm considering some enhancements to Win32::IE::Mechanize and have encountered a potential issue with Win32::OLE. One of the things I'm attempting to do is to improve IE Mech's page complete logic. Doing so requires monitoring IE's event stream looking for a condition that indicates that IE has 'completed' the page. In testing various schemes, I've encountered a problem relating to IE's popup treatment. When I configure IE to block popups the test program I'm using runs well. When I disable IE's popup blocker and run the test program I get a perl crash shortly after IE's NewWindow3 event. I can provide the test jig if anyone is interested. As an experiment I added some logic to the IE perl event handler to catch the NewWindow3 event and create a new IE for it with the following code sub win32_ie_events { my( $agent, $event, @args ) = @_; $events_ok++ or init_win32_ie_events(); $t_last_event = gettimeofday(); CASE: { # NON RELEVANT CODE DELETED $event eq 'NewWindow3' and do { my $pu = Win32::OLE->new('InternetExplorer.Application')->{Application}; #Win32::OLE->WithEvents( $pu, \&win32_ie_events, 'DWebBrowserEvents2' ); $args[0]->Put($pu); } } my $te = sprintf '%6.2f', $t_last_event - $t_start; print "$te $agent $dl_cnt $dl_tot [$event]\n"; } With this code in place, the test program runs OK. However, it raises the question of how to handle the child's events re child completion and other potential IE Mech issues. It appears that I can examine the event's agent parameter to tell which IE the event came from (I'm not really sure about this). So I tried to use the same event handler per the code that is commented out. When I do this, the print statements generate output that looks like two events overwriting each other. It appears that the event routine may have been reentered! I've considered a separate event handler for the child window but ultimately, that is not attractive since a parent may have many children who may have many children and so on. I suppose I might be able to do something with anonymous handlers. However, I attack this issue, it seems to me that there are issues of multiple OLE event streams to perl that need to be dealt with. Now my questions - Is my guess about what is going on correct? Is the current Win32::OLE event support safe in the sense that it passes only one event at a time to perl when there are multiple concurrently automation objects? Is there a programming technique that can make it safe in this sense? What is it? Would anonymous event handlers work? Would this create threading issues with perl? I'd also appreciate any advice concerning how to address this issue. If anyone has questions or would like the testing routines I'll gladly provide them. Regards, Richard Richard Bell rbell01824earthlink.net <mailto:[EMAIL PROTECTED]>