Kernel32.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace winsw
  4. {
  5. /// <summary>
  6. /// kernel32.dll P/Invoke wrappers
  7. /// </summary>
  8. internal class Kernel32
  9. {
  10. [DllImport("Kernel32.dll", SetLastError = true)]
  11. internal static extern int SetStdHandle(int device, IntPtr handle);
  12. [DllImport("kernel32.dll", SetLastError = true)]
  13. internal static extern bool CreateProcess(string lpApplicationName,
  14. string lpCommandLine, IntPtr lpProcessAttributes,
  15. IntPtr lpThreadAttributes, bool bInheritHandles,
  16. uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory,
  17. [In] ref STARTUPINFO lpStartupInfo,
  18. out PROCESS_INFORMATION lpProcessInformation);
  19. [DllImport("kernel32.dll")]
  20. internal static extern int GetLastError();
  21. }
  22. [StructLayout(LayoutKind.Sequential)]
  23. internal struct PROCESS_INFORMATION
  24. {
  25. public IntPtr hProcess;
  26. public IntPtr hThread;
  27. public int dwProcessId;
  28. public int dwThreadId;
  29. }
  30. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
  31. struct STARTUPINFO
  32. {
  33. public Int32 cb;
  34. public string lpReserved;
  35. public string lpDesktop;
  36. public string lpTitle;
  37. public Int32 dwX;
  38. public Int32 dwY;
  39. public Int32 dwXSize;
  40. public Int32 dwYSize;
  41. public Int32 dwXCountChars;
  42. public Int32 dwYCountChars;
  43. public Int32 dwFillAttribute;
  44. public Int32 dwFlags;
  45. public Int16 wShowWindow;
  46. public Int16 cbReserved2;
  47. public IntPtr lpReserved2;
  48. public IntPtr hStdInput;
  49. public IntPtr hStdOutput;
  50. public IntPtr hStdError;
  51. }
  52. }