Kernel32.cs 1.8 KB

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