|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
internal static partial class Interop
{
internal static partial class Kernel32
{
[Flags]
internal enum SnapshotFlags : uint
{
HeapList = 0x00000001,
Process = 0x00000002,
Thread = 0x00000004,
Module = 0x00000008,
Module32 = 0x00000010,
All = (HeapList | Process | Thread | Module),
Inherit = 0x80000000,
NoHeaps = 0x40000000
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct PROCESSENTRY32
{
internal int dwSize;
internal int cntUsage;
internal int th32ProcessID;
internal IntPtr th32DefaultHeapID;
internal int th32ModuleID;
internal int cntThreads;
internal int th32ParentProcessID;
internal int pcPriClassBase;
internal int dwFlags;
#if NET
internal ExeFileNameBuffer szExeFile;
[InlineArray(MAX_PATH)]
internal struct ExeFileNameBuffer
{
private char _element0;
}
#else
internal unsafe fixed char szExeFile[MAX_PATH];
#endif
}
// https://learn.microsoft.com/windows/desktop/api/tlhelp32/nf-tlhelp32-createtoolhelp32snapshot
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[LibraryImport(Libraries.Kernel32, SetLastError = true)]
internal static partial nint CreateToolhelp32Snapshot(SnapshotFlags dwFlags, uint th32ProcessID);
// https://learn.microsoft.com/windows/desktop/api/tlhelp32/nf-tlhelp32-process32first
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[LibraryImport(Libraries.Kernel32, EntryPoint = "Process32FirstW", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static unsafe partial bool Process32First(nint hSnapshot, PROCESSENTRY32* lppe);
// https://learn.microsoft.com/windows/desktop/api/tlhelp32/nf-tlhelp32-process32next
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[LibraryImport(Libraries.Kernel32, EntryPoint = "Process32NextW", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static unsafe partial bool Process32Next(nint hSnapshot, PROCESSENTRY32* lppe);
}
}
|