Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fall back to Window.Title if GetWindowText fails #7345

Merged
merged 1 commit into from
Jun 28, 2023

Conversation

bgrainger
Copy link
Contributor

@bgrainger bgrainger commented Dec 6, 2022

This is an attempt to recover from badly-behaving Windows message hooks that may change the last error during message processing.

Fixes #7344
Fixes #4181

Description

UnsafeNativeMethods.GetWindowText may throw if badly-behaving Windows message hooks are installed on the system, or potentially for other reasons. This can crash a WPF application.

Instead of crashing, we now ignore the exception and try to fall back to using Window.Title, which should contain the same text.

Customer Impact

WPF applications can crash unpredictably. It may be possible for customers to work around it with more P/Invoke code: #6026 (comment)

Having a fix in WPF itself would be simpler for most customers.

Regression

No.

Testing

Will ship in a consumer application and monitor user crash reports.

Risk

Legitimate failures of GetWindowText (too short a buffer? something else?) might incorrectly be ignored. However, if Window.Title is used as a fallback, the risk seems minimal.

Microsoft Reviewers: Open in CodeFlow

This is an attempt to recover from badly-behaving windows message hooks that may change the last error during message processing.
@bgrainger bgrainger requested a review from a team as a code owner December 6, 2022 20:26
@ghost ghost assigned bgrainger Dec 6, 2022
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Dec 6, 2022
@ghost ghost requested review from dipeshmsft and singhashish-wpf December 6, 2022 20:27
@ghost ghost added the Community Contribution A label for all community Contributions label Dec 6, 2022
Copy link
Member

@lindexi lindexi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jfontsaballs
Copy link

I have a production app that is facing this issue, and would very much appreciate this PR being approved and merged into a .NET release.

@dipeshmsft
Copy link
Member

@bgrainger , thanks for your contribution

@bgrainger bgrainger deleted the ignore-getwindowtext-failure branch June 28, 2023 12:17
@ghost ghost locked as resolved and limited conversation to collaborators Jul 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
5 participants