Skip to content

Commit 3181630

Browse files
Use Environment.ProcessId instead of calling a Win32 function
1 parent 2565c86 commit 3181630

File tree

8 files changed

+8
-19
lines changed

8 files changed

+8
-19
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/DpiUtil/DpiUtil+ProcessDpiAwarenessHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private static PROCESS_DPI_AWARENESS GetProcessDpiAwarenessFromWindow(IntPtr hWn
9999
{
100100
// If a valid window is not specified, then query the current process instead of the process
101101
// associated with the window
102-
windowThreadProcessId = SafeNativeMethods.GetCurrentProcessId();
102+
windowThreadProcessId = Environment.ProcessId;
103103
}
104104

105105
Debug.Assert(windowThreadProcessId != 0, "GetWindowThreadProcessId failed");

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Automation/Peers/AutomationPeer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ public void ResetChildrenCache()
14661466
///
14671467
internal int[] GetRuntimeId()
14681468
{
1469-
return new int [] { 7, SafeNativeMethods.GetCurrentProcessId(), this.GetHashCode() };
1469+
return new int [] { 7, Environment.ProcessId, this.GetHashCode() };
14701470
}
14711471

14721472
///
@@ -2500,7 +2500,7 @@ internal PatternInfo(int id, WrapObject wrapObject, PatternInterface patternInte
25002500
private static object IsKeyboardFocusable(AutomationPeer peer) { return peer.IsKeyboardFocusable(); }
25012501
private static object IsEnabled(AutomationPeer peer) { return peer.IsEnabled(); }
25022502
private static object GetBoundingRectangle(AutomationPeer peer) { return peer.GetBoundingRectangle(); }
2503-
private static object GetCurrentProcessId(AutomationPeer peer) { return SafeNativeMethods.GetCurrentProcessId(); }
2503+
private static object GetCurrentProcessId(AutomationPeer peer) { return Environment.ProcessId; }
25042504
private static object GetRuntimeId(AutomationPeer peer) { return peer.GetRuntimeId(); }
25052505
private static object GetClassName(AutomationPeer peer) { return peer.GetClassName(); }
25062506
private static object GetHelpText(AutomationPeer peer) { return peer.GetHelpText(); }

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndTarget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ out processId
542542
"hwnd"
543543
);
544544
}
545-
else if (processId != SafeNativeMethods.GetCurrentProcessId())
545+
else if (processId != Environment.ProcessId)
546546
{
547547
throw new ArgumentException(
548548
SR.HwndTarget_InvalidWindowProcess,

src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Interop/HwndHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ private void BuildWindow(HandleRef hwndParent)
10531053
(idWindowProcess == UnsafeNativeMethods.GetProcessIdOfThread(hCurrentThread)))
10541054
#else
10551055
if ((idWindowThread == SafeNativeMethods.GetCurrentThreadId()) &&
1056-
(idWindowProcess == SafeNativeMethods.GetCurrentProcessId()))
1056+
(idWindowProcess == Environment.ProcessId))
10571057
#endif
10581058
{
10591059
_hwndSubclass = new HwndSubclass(_hwndSubclassHook);

src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/SafeNativeMethodsCLR.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,6 @@ public static void ScreenToClient(HandleRef hWnd, ref NativeMethods.POINT pt)
267267
}
268268
}
269269

270-
public static int GetCurrentProcessId()
271-
{
272-
return SafeNativeMethodsPrivate.GetCurrentProcessId();
273-
}
274-
275-
276270
public static int GetCurrentThreadId()
277271
{
278272
return SafeNativeMethodsPrivate.GetCurrentThreadId();
@@ -290,7 +284,7 @@ public static int GetCurrentThreadId()
290284

291285
int sessionId;
292286
if (SafeNativeMethodsPrivate.ProcessIdToSessionId(
293-
GetCurrentProcessId(), out sessionId))
287+
Environment.ProcessId, out sessionId))
294288
{
295289
result = sessionId;
296290
}
@@ -618,9 +612,6 @@ internal static bool PhysicalToLogicalPointForPerMonitorDPI(
618612

619613
private partial class SafeNativeMethodsPrivate
620614
{
621-
[DllImport(ExternDll.Kernel32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
622-
public static extern int GetCurrentProcessId();
623-
624615
[DllImport(ExternDll.Kernel32, ExactSpelling = true, CharSet = CharSet.Auto)]
625616
[return:MarshalAs(UnmanagedType.Bool)]
626617
public static extern bool ProcessIdToSessionId([In]int dwProcessId, [Out]out int pSessionId);

src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ internal static Accessible CreateNativeFromEvent(IntPtr hwnd, int idObject, int
164164
// DuplicateHandle back to this process.)
165165
IntPtr wParam = IntPtr.Zero;
166166
if(Environment.OSVersion.Version.Major >= 6)
167-
wParam = new IntPtr(UnsafeNativeMethods.GetCurrentProcessId());
167+
wParam = new IntPtr(Environment.ProcessId);
168168

169169
// send the window a WM_GETOBJECT message requesting the specific object id.
170170
IntPtr lResult = Misc.ProxySendMessage(hwnd, NativeMethods.WM_GETOBJECT, wParam, new IntPtr(idObject));

src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/SafeProcessHandle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal SafeProcessHandle(IntPtr hwnd) : base(true)
2525

2626
if (hwnd == IntPtr.Zero)
2727
{
28-
processId = UnsafeNativeMethods.GetCurrentProcessId();
28+
processId = (uint)Environment.ProcessId;
2929
}
3030
else
3131
{

src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Win32/UnsafeNativeMethods.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ internal static class UnsafeNativeMethods
3333
[DllImport(ExternDll.Kernel32, SetLastError = true)]
3434
internal static extern IntPtr OpenProcess(int flags, bool inherit, uint dwProcessId);
3535

36-
[DllImport(ExternDll.Kernel32)]
37-
public static extern uint GetCurrentProcessId();
3836
[DllImport(ExternDll.Kernel32)]
3937
internal static extern void GetSystemInfo(out NativeMethods.SYSTEM_INFO SystemInfo);
4038
[DllImport(ExternDll.Kernel32, SetLastError = true)]

0 commit comments

Comments
 (0)