Kernel32.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. namespace XUnity.AutoTranslator.Plugin.Core.Debugging
  7. {
  8. public static class Kernel32
  9. {
  10. [DllImport( "kernel32.dll", CharSet = CharSet.Unicode )]
  11. public static extern int GetModuleFileNameW( HandleRef hModule, StringBuilder buffer, int length );
  12. [DllImport( "kernel32.dll", SetLastError = true )]
  13. public static extern bool AllocConsole();
  14. [DllImport( "kernel32.dll", SetLastError = false )]
  15. public static extern bool FreeConsole();
  16. [DllImport( "kernel32.dll", SetLastError = true )]
  17. public static extern IntPtr GetStdHandle( int nStdHandle );
  18. [DllImport( "kernel32.dll", SetLastError = true )]
  19. public static extern bool SetStdHandle( int nStdHandle, IntPtr hConsoleOutput );
  20. [DllImport( "kernel32.dll", CharSet = CharSet.Auto, SetLastError = true )]
  21. public static extern IntPtr CreateFile(
  22. string fileName,
  23. int desiredAccess,
  24. int shareMode,
  25. IntPtr securityAttributes,
  26. int creationDisposition,
  27. int flagsAndAttributes,
  28. IntPtr templateFile );
  29. [DllImport( "kernel32.dll", ExactSpelling = true, SetLastError = true )]
  30. public static extern bool CloseHandle( IntPtr handle );
  31. public static string ApplicationPath
  32. {
  33. get
  34. {
  35. StringBuilder stringBuilder = new StringBuilder( 260 );
  36. GetModuleFileNameW( new HandleRef( null, IntPtr.Zero ), stringBuilder, stringBuilder.Capacity );
  37. return stringBuilder.ToString();
  38. }
  39. }
  40. }
  41. }