[python-win32] OnBeforeNavigate2 - resolution and a question

Vaclav Opekar opekar at eccam.com
Thu Nov 27 09:26:48 CET 2008


Hello all,
some time ago was trying to implement OnBeforeNavigate2 callback in 
python. (DWebBrowserEvents2 - 
http://msdn.microsoft.com/en-us/library/aa768283(VS.85).aspx)


BeforeNavigate2 has 7 parameters, 1 marked as [in,out] and the rest 6 as 
[in] only. The one out parameter (Cancel) controls whether page will be 
navigated to or not, depending what you return.

This definition come straight to  following implementation. (which 
doesnt work)
<snip>
     #this version doesnt work
     def OnBeforeNavigate2(self, pDisp, .... Cancel):
         print URL
         if self.pageNotAllowed(URL):
                 return	True   #do not navigate there
         return False           #Navigate there
</snip>


After some debugging of pywin32 package, I found that not only the 1 
param is passed by variant "by_ref" but 6 of them, even if the 
parameters are not "out" parameters my IE uses them as "by_ref"

<snip>
     #this version works fine
     def OnBeforeNavigate2(self, pDisp, .... Cancel):
         print URL
         if self.pageNotAllowed(URL):
                 return	None, None, None, None, None, True
         return None, None, None, None, None, False
</snip>

Question:
If I understand correctly this python callback implementation is IE 
implementation dependent. If some new version of IE will start to call 
this callback with [lets say]4 "by_ref" params only. Then this will stop 
work.

Is it possible to write python code independent of  number "by_ref" 
parameters passed?

Thanks,
  Vaclav



More information about the python-win32 mailing list