/ src / common / ManagedCommon / NativeMethods.cs
NativeMethods.cs
  1  // Copyright (c) Microsoft Corporation
  2  // The Microsoft Corporation licenses this file to you under the MIT license.
  3  // See the LICENSE file in the project root for more information.
  4  
  5  using System;
  6  using System.Runtime.InteropServices;
  7  
  8  namespace ManagedCommon
  9  {
 10      internal static class NativeMethods
 11      {
 12          [DllImport("kernel32.dll", SetLastError = true)]
 13          internal static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);
 14  
 15          [DllImport("kernel32.dll", SetLastError = true)]
 16          internal static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);
 17  
 18          [DllImport("psapi.dll", SetLastError = true)]
 19          internal static extern bool EnumProcesses(int[] processIds, uint arraySizeBytes, out uint bytesCopied);
 20  
 21          [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
 22          internal static extern bool QueryFullProcessImageName(IntPtr hProcess, uint dwFlags, System.Text.StringBuilder lpExeName, ref uint lpdwSize);
 23  
 24          [DllImport("kernel32.dll", SetLastError = true)]
 25          internal static extern bool GetExitCodeProcess(IntPtr hProcess, out uint lpExitCode);
 26  
 27          [DllImport("kernel32.dll", SetLastError = true)]
 28          internal static extern bool CloseHandle(IntPtr hObject);
 29  
 30          [DllImport("user32.dll", SetLastError = true)]
 31          internal static extern IntPtr SetForegroundWindow(IntPtr hWnd);
 32  
 33          [DllImport("user32.dll")]
 34          internal static extern IntPtr GetForegroundWindow();
 35  
 36          [DllImport("user32.dll")]
 37          internal static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr processId);
 38  
 39          [DllImport("user32.dll")]
 40          internal static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach);
 41  
 42          [DllImport("user32.dll")]
 43          internal static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
 44  
 45          [DllImport("dwmapi")]
 46          internal static extern IntPtr DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
 47  
 48          [StructLayout(LayoutKind.Sequential)]
 49          public struct INPUT
 50          {
 51              internal INPUTTYPE type;
 52              internal InputUnion data;
 53  
 54              internal static int Size
 55              {
 56                  get { return Marshal.SizeOf<INPUT>(); }
 57              }
 58          }
 59  
 60          [StructLayout(LayoutKind.Explicit)]
 61          internal struct InputUnion
 62          {
 63              [FieldOffset(0)]
 64              internal MOUSEINPUT mi;
 65              [FieldOffset(0)]
 66              internal KEYBDINPUT ki;
 67              [FieldOffset(0)]
 68              internal HARDWAREINPUT hi;
 69          }
 70  
 71          [StructLayout(LayoutKind.Sequential)]
 72          internal struct MOUSEINPUT
 73          {
 74              internal int dx;
 75              internal int dy;
 76              internal int mouseData;
 77              internal uint dwFlags;
 78              internal uint time;
 79              internal UIntPtr dwExtraInfo;
 80          }
 81  
 82          [StructLayout(LayoutKind.Sequential)]
 83          internal struct KEYBDINPUT
 84          {
 85              internal short wVk;
 86              internal short wScan;
 87              internal uint dwFlags;
 88              internal int time;
 89              internal UIntPtr dwExtraInfo;
 90          }
 91  
 92          [StructLayout(LayoutKind.Sequential)]
 93          internal struct HARDWAREINPUT
 94          {
 95              internal int uMsg;
 96              internal short wParamL;
 97              internal short wParamH;
 98          }
 99  
100          internal enum INPUTTYPE : uint
101          {
102              INPUT_MOUSE = 0,
103              INPUT_KEYBOARD = 1,
104              INPUT_HARDWARE = 2,
105          }
106  
107          [StructLayout(LayoutKind.Sequential)]
108          internal struct MARGINS
109          {
110              public int cxLeftWidth;
111              public int cxRightWidth;
112              public int cyTopHeight;
113              public int cyBottomHeight;
114          }
115      }
116  }