using System;
using System.Runtime.InteropServices;
namespace Remotely.Shared.Win32
{
public static class Kernel32
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool CloseHandle(IntPtr hSnapshot);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetCommandLine();
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool GlobalMemoryStatusEx([In, Out] MEMORYSTATUSEX lpBuffer);
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, uint dwProcessId);
[DllImport("kernel32.dll")]
public static extern bool ProcessIdToSessionId(uint dwProcessId, ref uint pSessionId);
[DllImport("kernel32.dll")]
public static extern uint WTSGetActiveConsoleSessionId();
///
/// contains information about the current state of both physical and virtual memory, including extended memory
///
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class MEMORYSTATUSEX
{
///
/// Size of the structure, in bytes. You must set this member before calling GlobalMemoryStatusEx.
///
public uint dwLength;
///
/// Number between 0 and 100 that specifies the approximate percentage of physical memory that is in use (0 indicates no memory use and 100 indicates full memory use).
///
public uint dwMemoryLoad;
///
/// Total size of physical memory, in bytes.
///
public ulong ullTotalPhys;
///
/// Size of physical memory available, in bytes.
///
public ulong ullAvailPhys;
///
/// Size of the committed memory limit, in bytes. This is physical memory plus the size of the page file, minus a small overhead.
///
public ulong ullTotalPageFile;
///
/// Size of available memory to commit, in bytes. The limit is ullTotalPageFile.
///
public ulong ullAvailPageFile;
///
/// Total size of the user mode portion of the virtual address space of the calling process, in bytes.
///
public ulong ullTotalVirtual;
///
/// Size of unreserved and uncommitted memory in the user mode portion of the virtual address space of the calling process, in bytes.
///
public ulong ullAvailVirtual;
///
/// Size of unreserved and uncommitted memory in the extended portion of the virtual address space of the calling process, in bytes.
///
public ulong ullAvailExtendedVirtual;
///
/// Initializes a new instance of the class.
///
public MEMORYSTATUSEX()
{
this.dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX));
}
}
}
}