mhammond / pywin32

Python for Windows (pywin32) Extensions
4.9k stars 783 forks source link

EnumWindows() throws an exception if the callback returns False #2163

Open sn260591 opened 6 months ago

sn260591 commented 6 months ago

def enum_windows_proc(hwnd, extra): print(hwnd) return False

win32gui.EnumWindows(enum_windows_proc, None)



* Version of Python and pywin32
Python 3.11.7, pywin32 306
CristiFati commented 3 weeks ago

Should be fixed by #2219.

Avasam commented 1 week ago

@CristiFati I tried with a wheel from the latest action: https://github.com/mhammond/pywin32/actions/runs/9586723045 (pywin32-306-cp39-cp39-win_amd64.whl) and this is still the result I get:

Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32gui
>>> win32gui.EnumDesktopWindows  # Just making sure I am using a build from main
<built-in function EnumDesktopWindows>
>>> def enum_windows_proc(hwnd, extra):
...     print(hwnd)
...     return False
...
>>> win32gui.EnumWindows(enum_windows_proc, None)
66112
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pywintypes.error: (126, 'EnumWindows', 'The specified module could not be found.')
CristiFati commented 1 week ago

@Avasam: any way for me to get the .whl (to avoid local build)?

Avasam commented 1 week ago

@Avasam: any way for me to get the .whl (to avoid local build)?

In the link I shared, if you scroll down to "artefacts" there's a download button. Here's all the successful CI build jobs that ran on main: https://github.com/mhammond/pywin32/actions/workflows/main.yml?query=branch%3Amain+is%3Asuccess

You can do the same by looking at actions from a PR.

CristiFati commented 1 week ago

I'm experiencing a funny problem. Investigating: What does the following line output:

python -c "import win32api as wapi;print(wapi.GetLastError());wapi.SetLastError(0);print(wapi.GetLastError())"

What about if running each of the 4 lines separately in the interpreter console?