win32gui.EnumWindows problem in Python 2.2

Mark Hammond mhammond at skippinet.com.au
Wed Dec 18 23:15:16 EST 2002


griffin wrote:
> Hello,
> 
> After upgrading from python 2.0 to python 2.2, one of my scripts using
> Win32gui.Enum Windows () stopped working.  The callback function is being
> correctly called, but when it returns False to end the enumeration I get
> this error:
> win32gui.EnumWindows (self.findwindow, None)
> 
> pywintypes.api_error: (0, 'EnumWindows', 'No error message is available')
> 
> The scripts used to work fine under python 2.0. Does anyone have any idea
> what's going on and why this would be different under python 2.2?  I thought
> win32gui simply called the Windows API?

I am surprised this ever worked as you describe.  The MS docs state:
"""
If EnumWindowsProc returns zero, the return value is also zero.
"""

which means that EnumWindows will always raise that exception if your 
handler returns 0.  I haven't a Python 2.0 handy, but 2.1 certainly does.

Just catch and ignore the exception if exception[0]==0.

Mark.




More information about the Python-list mailing list