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

Use Environment.ProcessId instead of calling a Win32 function #9211

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private static PROCESS_DPI_AWARENESS GetProcessDpiAwarenessFromWindow(IntPtr hWn
{
// If a valid window is not specified, then query the current process instead of the process
// associated with the window
windowThreadProcessId = SafeNativeMethods.GetCurrentProcessId();
windowThreadProcessId = Environment.ProcessId;
}

Debug.Assert(windowThreadProcessId != 0, "GetWindowThreadProcessId failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ public void ResetChildrenCache()
///
internal int[] GetRuntimeId()
{
return new int [] { 7, SafeNativeMethods.GetCurrentProcessId(), this.GetHashCode() };
return new int [] { 7, Environment.ProcessId, this.GetHashCode() };
}

///
Expand Down Expand Up @@ -2500,7 +2500,7 @@ internal PatternInfo(int id, WrapObject wrapObject, PatternInterface patternInte
private static object IsKeyboardFocusable(AutomationPeer peer) { return peer.IsKeyboardFocusable(); }
private static object IsEnabled(AutomationPeer peer) { return peer.IsEnabled(); }
private static object GetBoundingRectangle(AutomationPeer peer) { return peer.GetBoundingRectangle(); }
private static object GetCurrentProcessId(AutomationPeer peer) { return SafeNativeMethods.GetCurrentProcessId(); }
private static object GetCurrentProcessId(AutomationPeer peer) { return Environment.ProcessId; }
private static object GetRuntimeId(AutomationPeer peer) { return peer.GetRuntimeId(); }
private static object GetClassName(AutomationPeer peer) { return peer.GetClassName(); }
private static object GetHelpText(AutomationPeer peer) { return peer.GetHelpText(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ out processId
"hwnd"
);
}
else if (processId != SafeNativeMethods.GetCurrentProcessId())
else if (processId != Environment.ProcessId)
{
throw new ArgumentException(
SR.HwndTarget_InvalidWindowProcess,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ private void BuildWindow(HandleRef hwndParent)
(idWindowProcess == UnsafeNativeMethods.GetProcessIdOfThread(hCurrentThread)))
#else
if ((idWindowThread == SafeNativeMethods.GetCurrentThreadId()) &&
(idWindowProcess == SafeNativeMethods.GetCurrentProcessId()))
(idWindowProcess == Environment.ProcessId))
#endif
{
_hwndSubclass = new HwndSubclass(_hwndSubclassHook);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,6 @@ public static void ScreenToClient(HandleRef hWnd, ref NativeMethods.POINT pt)
}
}

public static int GetCurrentProcessId()
{
return SafeNativeMethodsPrivate.GetCurrentProcessId();
}


public static int GetCurrentThreadId()
{
return SafeNativeMethodsPrivate.GetCurrentThreadId();
Expand All @@ -290,7 +284,7 @@ public static int GetCurrentThreadId()

int sessionId;
if (SafeNativeMethodsPrivate.ProcessIdToSessionId(
GetCurrentProcessId(), out sessionId))
Environment.ProcessId, out sessionId))
{
result = sessionId;
}
Expand Down Expand Up @@ -618,9 +612,6 @@ internal static bool PhysicalToLogicalPointForPerMonitorDPI(

private partial class SafeNativeMethodsPrivate
{
[DllImport(ExternDll.Kernel32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern int GetCurrentProcessId();

[DllImport(ExternDll.Kernel32, ExactSpelling = true, CharSet = CharSet.Auto)]
[return:MarshalAs(UnmanagedType.Bool)]
public static extern bool ProcessIdToSessionId([In]int dwProcessId, [Out]out int pSessionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ internal static Accessible CreateNativeFromEvent(IntPtr hwnd, int idObject, int
// DuplicateHandle back to this process.)
IntPtr wParam = IntPtr.Zero;
if(Environment.OSVersion.Version.Major >= 6)
wParam = new IntPtr(UnsafeNativeMethods.GetCurrentProcessId());
wParam = new IntPtr(Environment.ProcessId);

// send the window a WM_GETOBJECT message requesting the specific object id.
IntPtr lResult = Misc.ProxySendMessage(hwnd, NativeMethods.WM_GETOBJECT, wParam, new IntPtr(idObject));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal SafeProcessHandle(IntPtr hwnd) : base(true)

if (hwnd == IntPtr.Zero)
{
processId = UnsafeNativeMethods.GetCurrentProcessId();
processId = (uint)Environment.ProcessId;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ internal static class UnsafeNativeMethods
[DllImport(ExternDll.Kernel32, SetLastError = true)]
internal static extern IntPtr OpenProcess(int flags, bool inherit, uint dwProcessId);

[DllImport(ExternDll.Kernel32)]
public static extern uint GetCurrentProcessId();
[DllImport(ExternDll.Kernel32)]
internal static extern void GetSystemInfo(out NativeMethods.SYSTEM_INFO SystemInfo);
[DllImport(ExternDll.Kernel32, SetLastError = true)]
Expand Down
Loading