Skip to content

Commit 7885354

Browse files
Suppress P/Invoke warning for GetWindowThreadProcessId in UWP (#3372)
1 parent a4a3c30 commit 7885354

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- P/Invoke warning for GetWindowThreadProcessId no longer shows when using Sentry in UWP applications ([#3372](https://github.com/getsentry/sentry-dotnet/pull/3372))
8+
39
## 4.6.2
410

511
### Fixes

src/Sentry/Internal/ProcessInfo.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ private static DateTimeOffset GetStartupTime()
149149
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
150150
private static extern IntPtr GetForegroundWindow();
151151

152-
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
152+
// GetWindowThreadProcessId is only available in the Windows SDK, so trying to call this from UWP apps will fail.
153+
// We wrap use of this in a try/catch as a workaround. However, we need `ExactSpelling = true` here to suppress
154+
// warnings about the use of this API when compiling UWP applications.
155+
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
153156
private static extern int GetWindowThreadProcessId(IntPtr handle, out int processId);
154157
}

0 commit comments

Comments
 (0)