/ src / modules / AdvancedPaste / AdvancedPaste / Helpers / 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  using System.Text;
  8  
  9  namespace AdvancedPaste.Helpers
 10  {
 11      internal static class NativeMethods
 12      {
 13          [StructLayout(LayoutKind.Sequential)]
 14          [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching Native Structure")]
 15          internal struct INPUT
 16          {
 17              internal INPUTTYPE type;
 18              internal InputUnion data;
 19  
 20              internal static int Size
 21              {
 22                  get { return Marshal.SizeOf<INPUT>(); }
 23              }
 24          }
 25  
 26          [StructLayout(LayoutKind.Explicit)]
 27          [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching Native Structure")]
 28          internal struct InputUnion
 29          {
 30              [FieldOffset(0)]
 31              internal MOUSEINPUT mi;
 32              [FieldOffset(0)]
 33              internal KEYBDINPUT ki;
 34              [FieldOffset(0)]
 35              internal HARDWAREINPUT hi;
 36          }
 37  
 38          [StructLayout(LayoutKind.Sequential)]
 39          [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching Native Structure")]
 40          internal struct MOUSEINPUT
 41          {
 42              internal int dx;
 43              internal int dy;
 44              internal int mouseData;
 45              internal uint dwFlags;
 46              internal uint time;
 47              internal UIntPtr dwExtraInfo;
 48          }
 49  
 50          [StructLayout(LayoutKind.Sequential)]
 51          [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching Native Structure")]
 52          internal struct KEYBDINPUT
 53          {
 54              internal short wVk;
 55              internal short wScan;
 56              internal uint dwFlags;
 57              internal int time;
 58              internal UIntPtr dwExtraInfo;
 59          }
 60  
 61          [StructLayout(LayoutKind.Sequential)]
 62          [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching Native Structure")]
 63          internal struct HARDWAREINPUT
 64          {
 65              internal int uMsg;
 66              internal short wParamL;
 67              internal short wParamH;
 68          }
 69  
 70          internal enum INPUTTYPE : uint
 71          {
 72              INPUT_MOUSE = 0,
 73              INPUT_KEYBOARD = 1,
 74              INPUT_HARDWARE = 2,
 75          }
 76  
 77          [Flags]
 78          internal enum KeyEventF
 79          {
 80              KeyDown = 0x0000,
 81              ExtendedKey = 0x0001,
 82              KeyUp = 0x0002,
 83              Unicode = 0x0004,
 84              Scancode = 0x0008,
 85          }
 86  
 87          public enum HResult
 88          {
 89              Ok = 0x0000,
 90              False = 0x0001,
 91              InvalidArguments = unchecked((int)0x80070057),
 92              OutOfMemory = unchecked((int)0x8007000E),
 93              NoInterface = unchecked((int)0x80004002),
 94              Fail = unchecked((int)0x80004005),
 95              ExtractionFailed = unchecked((int)0x8004B200),
 96              ElementNotFound = unchecked((int)0x80070490),
 97              TypeElementNotFound = unchecked((int)0x8002802B),
 98              NoObject = unchecked((int)0x800401E5),
 99              Win32ErrorCanceled = 1223,
100              Canceled = unchecked((int)0x800704C7),
101              ResourceInUse = unchecked((int)0x800700AA),
102              AccessDenied = unchecked((int)0x80030005),
103          }
104  
105          [Flags]
106          public enum AssocF
107          {
108              None = 0,
109              Init_NoRemapCLSID = 0x1,
110              Init_ByExeName = 0x2,
111              Open_ByExeName = 0x3,
112              Init_DefaultToStar = 0x4,
113              Init_DefaultToFolder = 0x8,
114              NoUserSettings = 0x10,
115              NoTruncate = 0x20,
116              Verify = 0x40,
117              RemapRunDll = 0x80,
118              NoFixUps = 0x100,
119              IgnoreBaseClass = 0x200,
120          }
121  
122          public enum AssocStr
123          {
124              Command = 1,
125              Executable,
126              FriendlyDocName,
127              FriendlyAppName,
128              NoOpen,
129              ShellNewValue,
130              DDECommand,
131              DDEIfExec,
132              DDEApplication,
133              DDETopic,
134              InfoTip,
135              QuickTip,
136              TileInfo,
137              ContentType,
138              DefaultIcon,
139              ShellExtension,
140              PerceivedType,
141              DelegateExecute,
142              SupportedUriProtocols,
143              ProgId,
144              AppId,
145              AppPublisher,
146              AppIconReference,
147          }
148  
149          [DllImport("user32.dll")]
150          internal static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
151  
152          [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
153          internal static extern short GetAsyncKeyState(int vKey);
154  
155          [StructLayout(LayoutKind.Sequential)]
156          internal struct PointInter
157          {
158              public int X;
159              public int Y;
160  
161              public static explicit operator System.Windows.Point(PointInter point) => new System.Windows.Point(point.X, point.Y);
162          }
163  
164          [DllImport("user32.dll")]
165          internal static extern bool GetCursorPos(out PointInter lpPoint);
166  
167          [DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Unicode)]
168          internal static extern HResult AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra, [Out] StringBuilder pszOut, [In][Out] ref uint pcchOut);
169  
170          [DllImport("user32.dll", SetLastError = true)]
171          internal static extern uint GetClipboardSequenceNumber();
172      }
173  }