Skip to content

Commit

Permalink
Suppress P/Invoke warning for GetWindowThreadProcessId in UWP (#3372)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescrosswell authored May 16, 2024
1 parent a4a3c30 commit 7885354
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- P/Invoke warning for GetWindowThreadProcessId no longer shows when using Sentry in UWP applications ([#3372](https://github.com/getsentry/sentry-dotnet/pull/3372))

## 4.6.2

### Fixes
Expand Down
5 changes: 4 additions & 1 deletion src/Sentry/Internal/ProcessInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ private static DateTimeOffset GetStartupTime()
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern IntPtr GetForegroundWindow();

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
// 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)]
private static extern int GetWindowThreadProcessId(IntPtr handle, out int processId);
}

0 comments on commit 7885354

Please sign in to comment.