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

Suppress P/Invoke warning for GetWindowThreadProcessId in UWP #3372

Merged
merged 2 commits into from
May 16, 2024

Conversation

jamescrosswell
Copy link
Collaborator

Resolves #3249

@jamescrosswell jamescrosswell marked this pull request as ready for review May 16, 2024 04:18
// GetWindowThreadProcessId is only available in the Windows SDK, so trying to call this from UWP apps will fail.
// We wrap use of this in a try/catch as a workaround. However, we need `ExactSpelling = true` here to suppress
// warnings about the use of this API when compiling UWP applications.
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
Copy link
Contributor

Choose a reason for hiding this comment

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

I get that the warning stated

Please make sure the P/Invoke either points to a Windows API allowed in UWP applications, or a native DLL that is part of the package. 
If for some reason your P/Invoke does not satisfy those requirements, please use [DllImport(ExactSpelling=true) to indicate that you understand the implications of using non-UWP A 

but isn't adding ExactSpelling=true more a "Trust me, I know what I'm doing" and not a suppression of a warning?
But does it make a difference? The comment explains it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I published a new Sentry.nupkg file after making this change, referenced it in a UWP solution and rebuilt... yes the warnings go away if you do that. It's a very bizarre way to suppress warnings if you ask me (thus the code comment).

@jamescrosswell jamescrosswell merged commit 7885354 into main May 16, 2024
21 checks passed
@jamescrosswell jamescrosswell deleted the uwp-pinvoke-warning branch May 16, 2024 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UWP: "In foreground" context warning + not working
2 participants