ConsoleApi.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using Microsoft.Win32.SafeHandles;
  2. using System.Runtime.InteropServices;
  3. namespace MiniTerm.Native
  4. {
  5. /// <summary>
  6. /// PInvoke signatures for win32 console api
  7. /// </summary>
  8. static class ConsoleApi
  9. {
  10. internal const int STD_OUTPUT_HANDLE = -11;
  11. internal const uint ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
  12. internal const uint DISABLE_NEWLINE_AUTO_RETURN = 0x0008;
  13. [DllImport("kernel32.dll", SetLastError = true)]
  14. internal static extern SafeFileHandle GetStdHandle(int nStdHandle);
  15. [DllImport("kernel32.dll", SetLastError = true)]
  16. internal static extern bool SetConsoleMode(SafeFileHandle hConsoleHandle, uint mode);
  17. [DllImport("kernel32.dll", SetLastError = true)]
  18. internal static extern bool GetConsoleMode(SafeFileHandle handle, out uint mode);
  19. internal delegate bool ConsoleEventDelegate(CtrlTypes ctrlType);
  20. internal enum CtrlTypes : uint
  21. {
  22. CTRL_C_EVENT = 0,
  23. CTRL_BREAK_EVENT,
  24. CTRL_CLOSE_EVENT,
  25. CTRL_LOGOFF_EVENT = 5,
  26. CTRL_SHUTDOWN_EVENT
  27. }
  28. [DllImport("kernel32.dll", SetLastError = true)]
  29. internal static extern bool SetConsoleCtrlHandler(ConsoleEventDelegate callback, bool add);
  30. }
  31. }