Conversation
… return 0 for a NULL window handle like they always did before the tightening of ctypes definitions, rather than returning None, which was breaking some existing code such as lock screen detection.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a critical freeze issue where NVDA becomes unresponsive when users lock/unlock their Windows session using Windows+L. The issue was caused by an infinite loop in window detection logic that occurred after migrating to 64-bit, where NULL HWND values are now returned as None instead of 0, breaking existing comparison logic.
- Fixed high-level winUser functions to return 0 instead of None for NULL HWND values
- Added type hints for parameters and return values to affected functions
- Maintained backward compatibility with existing code that expects 0 for invalid window handles
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
seanbudd
approved these changes
Oct 8, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue number:
Fixes #19037
Summary of the issue:
After switching to 64 bit, when locking the user session with windows+l, or when cuming out of the lock screen, NVDA will freeze and become unusable. It was necessary to restart NVDA.
This was caused by NVDA going into an infinit loop when trying to detect if a given window was above or below the lock screen. A loop would be calling winUser.GetWindow, and breaking when the window equals GWL_NOT_FOUND (0). However, after switching to 64 bit, the value from winUser.getWindow when there was no window, was now None, not 0, so it never matched and the loop continued for ever.
winUser.getwindow internally calls user32's GetWindow, which with our new tightened winBindings ctypes definitions, was defined to return HWND, rather than just a default long. Problem is that ctypes always converts NULL pointers (including HWND) to None on return.
Description of user facing changes:
Description of developer facing changes:
Description of development approach:
for all functions in our high-level winUser module that return a window handle, ensure that 0 is returned instead of None if a null HWND is being returned. This keeps these high-level functions compatible with existing code, and therefore no longer breaks lock screen detection logic. Also add type hints for params and return for these particular functions.
Testing strategy:
Known issues with pull request:
None known.
Code Review Checklist: