Replace DllImport with LibraryImport - 1 (#18603)

This commit is contained in:
Ilya authored and GitHub committed 2022-11-30 10:00:12 -08:00
1 parent 52ea419662
commit 3dc95ced87
27 files changed
+413 -333

No files matched your search

@@ -11,7 +11,7 @@ namespace Microsoft.PowerShell
/// <summary>
/// Helper functions for process info.
/// </summary>
public static partial class ProcessCodeMethods
public static class ProcessCodeMethods
{
private const int InvalidProcessId = -1;
@@ -61,32 +61,12 @@ namespace Microsoft.PowerShell
internal static int GetParentPid(Process process)
{
Diagnostics.Assert(process != null, "Ensure process is not null before calling");
PROCESS_BASIC_INFORMATION pbi;
Interop.Windows.PROCESS_BASIC_INFORMATION pbi;
int size;
var res = NtQueryInformationProcess(process.Handle, 0, out pbi, Marshal.SizeOf<PROCESS_BASIC_INFORMATION>(), out size);
var res = Interop.Windows.NtQueryInformationProcess(process.Handle, 0, out pbi, Marshal.SizeOf<Interop.Windows.PROCESS_BASIC_INFORMATION>(), out size);
return res != 0 ? InvalidProcessId : pbi.InheritedFromUniqueProcessId.ToInt32();
}
[StructLayout(LayoutKind.Sequential)]
private struct PROCESS_BASIC_INFORMATION
{
public IntPtr ExitStatus;
public IntPtr PebBaseAddress;
public IntPtr AffinityMask;
public IntPtr BasePriority;
public IntPtr UniqueProcessId;
public IntPtr InheritedFromUniqueProcessId;
}
[LibraryImport("ntdll.dll")]
private static partial int NtQueryInformationProcess(
IntPtr processHandle,
int processInformationClass,
out PROCESS_BASIC_INFORMATION processInformation,
int processInformationLength,
out int returnLength);
#endif
}
}