1 /*
2   KeePass Password Safe - The Open-Source Password Manager
3   Copyright (C) 2003-2021 Dominik Reichl <dominik.reichl@t-online.de>
4 
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation; either version 2 of the License, or
8   (at your option) any later version.
9 
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14 
15   You should have received a copy of the GNU General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19 
20 using System;
21 using System.Diagnostics;
22 using System.Runtime.InteropServices;
23 using System.Security;
24 using System.Text;
25 using System.Windows.Forms;
26 
27 using KeePass.UI;
28 
29 namespace KeePass.Native
30 {
31 	internal static partial class NativeMethods
32 	{
33 		[DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
34 		[return: MarshalAs(UnmanagedType.Bool)]
SetDllDirectory(string lpPathName)35 		internal static extern bool SetDllDirectory(string lpPathName);
36 
37 		[DllImport("Wer.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
WerAddExcludedApplication(string pwzExeName, [MarshalAs(UnmanagedType.Bool)] bool bAllUsers)38 		internal static extern int WerAddExcludedApplication(string pwzExeName,
39 			[MarshalAs(UnmanagedType.Bool)] bool bAllUsers);
40 
41 		[DllImport("User32.dll")]
42 		[return: MarshalAs(UnmanagedType.Bool)]
IsWindow(IntPtr hWnd)43 		private static extern bool IsWindow(IntPtr hWnd);
44 
45 		[DllImport("User32.dll")]
SendMessage(IntPtr hWnd, int nMsg, IntPtr wParam, IntPtr lParam)46 		internal static extern IntPtr SendMessage(IntPtr hWnd, int nMsg,
47 			IntPtr wParam, IntPtr lParam);
48 
49 		[DllImport("User32.dll", EntryPoint = "SendMessage")]
SendMessageHDItem(IntPtr hWnd, int nMsg, IntPtr wParam, ref HDITEM hdItem)50 		internal static extern IntPtr SendMessageHDItem(IntPtr hWnd, int nMsg,
51 			IntPtr wParam, ref HDITEM hdItem);
52 
53 		// [DllImport("User32.dll", EntryPoint = "SendMessage")]
54 		// private static extern IntPtr SendMessageLVGroup(IntPtr hWnd, int nMsg,
55 		//	IntPtr wParam, ref LVGROUP lvGroup);
56 
57 		[DllImport("User32.dll", SetLastError = true)]
SendMessageTimeout(IntPtr hWnd, int nMsg, IntPtr wParam, IntPtr lParam, uint fuFlags, uint uTimeout, ref IntPtr lpdwResult)58 		internal static extern IntPtr SendMessageTimeout(IntPtr hWnd, int nMsg,
59 			IntPtr wParam, IntPtr lParam, uint fuFlags, uint uTimeout,
60 			ref IntPtr lpdwResult);
61 
62 		[DllImport("User32.dll")]
63 		[return: MarshalAs(UnmanagedType.Bool)]
PostMessage(IntPtr hWnd, int nMsg, IntPtr wParam, IntPtr lParam)64 		internal static extern bool PostMessage(IntPtr hWnd, int nMsg,
65 			IntPtr wParam, IntPtr lParam);
66 
67 		// [DllImport("User32.dll")]
68 		// internal static extern uint GetMessagePos();
69 
70 		[DllImport("User32.dll", CharSet = CharSet.Auto, SetLastError = true)]
RegisterWindowMessage(string lpString)71 		internal static extern int RegisterWindowMessage(string lpString);
72 
73 		// [DllImport("User32.dll")]
74 		// internal static extern IntPtr GetDesktopWindow();
75 
76 		[DllImport("User32.dll", CharSet = CharSet.Auto, SetLastError = true)]
FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow)77 		internal static extern IntPtr FindWindowEx(IntPtr hwndParent,
78 			IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
79 
80 		[DllImport("User32.dll")]
GetWindow(IntPtr hWnd, uint uCmd)81 		internal static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);
82 
83 		[DllImport("User32.dll", CharSet = CharSet.Auto, ExactSpelling = false,
84 			SetLastError = true)]
GetWindowLong(IntPtr hWnd, int nIndex)85 		internal static extern int GetWindowLong(IntPtr hWnd, int nIndex);
86 
87 		// [DllImport("User32.dll", CharSet = CharSet.Auto, ExactSpelling = false, SetLastError = true)]
88 		// internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
89 
90 		[DllImport("User32.dll", CharSet = CharSet.Auto, ExactSpelling = false)]
GetClassLong(IntPtr hWnd, int nIndex)91 		private static extern IntPtr GetClassLong(IntPtr hWnd, int nIndex);
92 
93 		[DllImport("User32.dll", CharSet = CharSet.Auto, ExactSpelling = false)]
GetClassLongPtr(IntPtr hWnd, int nIndex)94 		private static extern IntPtr GetClassLongPtr(IntPtr hWnd, int nIndex);
95 
96 		// [DllImport("User32.dll", CharSet = CharSet.Auto, SetLastError = true)]
97 		// private static extern int GetClassName(IntPtr hWnd,
98 		//	StringBuilder lpClassName, int nMaxCount);
99 
100 		[DllImport("User32.dll")]
101 		[return: MarshalAs(UnmanagedType.Bool)]
IsIconic(IntPtr hWnd)102 		internal static extern bool IsIconic(IntPtr hWnd);
103 
104 		[DllImport("User32.dll")]
105 		[return: MarshalAs(UnmanagedType.Bool)]
IsZoomed(IntPtr hWnd)106 		internal static extern bool IsZoomed(IntPtr hWnd);
107 
108 		[DllImport("User32.dll", CharSet = CharSet.Auto, ExactSpelling = false,
109 			SetLastError = true)]
GetWindowTextLength(IntPtr hWnd)110 		private static extern int GetWindowTextLength(IntPtr hWnd);
111 
112 		// [DllImport("User32.dll", CharSet = CharSet.Auto, ExactSpelling = false, SetLastError = true)]
113 		// private static extern int GetWindowText(IntPtr hWnd,
114 		//	StringBuilder lpString, int nMaxCount);
115 		[DllImport("User32.dll", CharSet = CharSet.Auto, ExactSpelling = false,
116 			SetLastError = true)]
GetWindowText(IntPtr hWnd, IntPtr lpString, int nMaxCount)117 		private static extern int GetWindowText(IntPtr hWnd, IntPtr lpString,
118 			int nMaxCount);
119 
120 		[DllImport("User32.dll", SetLastError = true)]
121 		[return: MarshalAs(UnmanagedType.Bool)]
GetWindowRect(IntPtr hWnd, ref RECT lpRect)122 		internal static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
123 
124 		// [DllImport("User32.dll")]
125 		// internal static extern IntPtr GetActiveWindow();
126 
127 		[DllImport("User32.dll")]
GetForegroundWindow()128 		private static extern IntPtr GetForegroundWindow(); // Private, is wrapped
129 
130 		[DllImport("User32.dll")]
131 		[return: MarshalAs(UnmanagedType.Bool)]
SetForegroundWindow(IntPtr hWnd)132 		private static extern bool SetForegroundWindow(IntPtr hWnd);
133 
134 		[DllImport("User32.dll")]
135 		[return: MarshalAs(UnmanagedType.Bool)]
EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam)136 		internal static extern bool EnumWindows(EnumWindowsProc lpEnumFunc,
137 			IntPtr lParam);
138 
139 		[DllImport("User32.dll")]
140 		[return: MarshalAs(UnmanagedType.Bool)]
RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk)141 		internal static extern bool RegisterHotKey(IntPtr hWnd, int id,
142 			uint fsModifiers, uint vk);
143 
144 		[DllImport("User32.dll")]
145 		[return: MarshalAs(UnmanagedType.Bool)]
UnregisterHotKey(IntPtr hWnd, int id)146 		internal static extern bool UnregisterHotKey(IntPtr hWnd, int id);
147 
148 		[DllImport("User32.dll", EntryPoint = "SendInput", SetLastError = true)]
SendInput32(uint nInputs, INPUT32[] pInputs, int cbSize)149 		internal static extern uint SendInput32(uint nInputs, INPUT32[] pInputs,
150 			int cbSize);
151 
152 		[DllImport("User32.dll", EntryPoint = "SendInput", SetLastError = true)]
SendInput64Special(uint nInputs, SpecializedKeyboardINPUT64[] pInputs, int cbSize)153 		internal static extern uint SendInput64Special(uint nInputs,
154 			SpecializedKeyboardINPUT64[] pInputs, int cbSize);
155 
156 		[DllImport("User32.dll")]
GetMessageExtraInfo()157 		internal static extern IntPtr GetMessageExtraInfo();
158 
159 		// [DllImport("User32.dll")]
160 		// internal static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,
161 		//	IntPtr dwExtraInfo);
162 
163 		[DllImport("User32.dll")]
MapVirtualKey(uint uCode, uint uMapType)164 		private static extern uint MapVirtualKey(uint uCode, uint uMapType);
165 
166 		[DllImport("User32.dll")]
MapVirtualKeyEx(uint uCode, uint uMapType, IntPtr hKL)167 		private static extern uint MapVirtualKeyEx(uint uCode, uint uMapType,
168 			IntPtr hKL);
169 
170 		[DllImport("User32.dll", CharSet = CharSet.Auto)]
VkKeyScan(char ch)171 		private static extern ushort VkKeyScan(char ch);
172 
173 		[DllImport("User32.dll", CharSet = CharSet.Auto)]
VkKeyScanEx(char ch, IntPtr hKL)174 		private static extern ushort VkKeyScanEx(char ch, IntPtr hKL);
175 
176 		[DllImport("User32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
ToUnicode(uint wVirtKey, uint wScanCode, IntPtr lpKeyState, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder sbBuff, int cchBuff, uint wFlags)177 		private static extern int ToUnicode(uint wVirtKey, uint wScanCode,
178 			IntPtr lpKeyState, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder sbBuff,
179 			int cchBuff, uint wFlags);
180 
181 		[DllImport("User32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
ToUnicodeEx(uint wVirtKey, uint wScanCode, IntPtr lpKeyState, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder sbBuff, int cchBuff, uint wFlags, IntPtr hKL)182 		private static extern int ToUnicodeEx(uint wVirtKey, uint wScanCode,
183 			IntPtr lpKeyState, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder sbBuff,
184 			int cchBuff, uint wFlags, IntPtr hKL);
185 
186 		// [DllImport("User32.dll")]
187 		// [return: MarshalAs(UnmanagedType.Bool)]
188 		// private static extern bool GetKeyboardState(IntPtr lpKeyState);
189 
190 		// [DllImport("User32.dll", CharSet = CharSet.Auto)]
191 		// [return: MarshalAs(UnmanagedType.Bool)]
192 		// private static extern bool GetKeyboardLayoutName([MarshalAs(UnmanagedType.LPTStr)]
193 		//	StringBuilder pwszKLID);
194 
195 		[DllImport("User32.dll")]
GetKeyState(int vKey)196 		internal static extern ushort GetKeyState(int vKey);
197 
198 		[DllImport("User32.dll")]
GetAsyncKeyState(int vKey)199 		internal static extern ushort GetAsyncKeyState(int vKey);
200 
201 		[DllImport("User32.dll")]
202 		[return: MarshalAs(UnmanagedType.Bool)]
BlockInput([MarshalAs(UnmanagedType.Bool)] bool fBlockIt)203 		internal static extern bool BlockInput([MarshalAs(UnmanagedType.Bool)]
204 			bool fBlockIt);
205 
206 		// [DllImport("User32.dll")]
207 		// [return: MarshalAs(UnmanagedType.Bool)]
208 		// internal static extern bool AttachThreadInput(uint idAttach,
209 		//	uint idAttachTo, [MarshalAs(UnmanagedType.Bool)] bool fAttach);
210 
211 		[DllImport("User32.dll")]
SetClipboardViewer(IntPtr hWndNewViewer)212 		internal static extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer);
213 
214 		[DllImport("User32.dll")]
215 		[return: MarshalAs(UnmanagedType.Bool)]
ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext)216 		internal static extern bool ChangeClipboardChain(IntPtr hWndRemove,
217 			IntPtr hWndNewNext);
218 
219 		[DllImport("User32.dll")]
220 		[return: MarshalAs(UnmanagedType.Bool)]
OpenClipboard(IntPtr hWndNewOwner)221 		internal static extern bool OpenClipboard(IntPtr hWndNewOwner);
222 
223 		[DllImport("User32.dll")]
224 		[return: MarshalAs(UnmanagedType.Bool)]
EmptyClipboard()225 		internal static extern bool EmptyClipboard();
226 
227 		[DllImport("User32.dll")]
228 		[return: MarshalAs(UnmanagedType.Bool)]
CloseClipboard()229 		internal static extern bool CloseClipboard();
230 
231 		[DllImport("User32.dll", SetLastError = true)]
SetClipboardData(uint uFormat, IntPtr hMem)232 		internal static extern IntPtr SetClipboardData(uint uFormat, IntPtr hMem);
233 
234 		// [DllImport("User32.dll", SetLastError = true)]
235 		// internal static extern IntPtr GetClipboardData(uint uFormat);
236 
237 		[DllImport("User32.dll", CharSet = CharSet.Auto, ExactSpelling = false,
238 			SetLastError = true)]
RegisterClipboardFormat(string lpszFormat)239 		internal static extern uint RegisterClipboardFormat(string lpszFormat);
240 
241 		// [DllImport("User32.dll")]
242 		// internal static extern uint GetClipboardSequenceNumber();
243 
244 		// [DllImport("User32.dll")]
245 		// internal static extern IntPtr GetClipboardOwner();
246 
247 		[DllImport("Kernel32.dll")]
GlobalAlloc(uint uFlags, UIntPtr dwBytes)248 		internal static extern IntPtr GlobalAlloc(uint uFlags, UIntPtr dwBytes);
249 
250 		[DllImport("Kernel32.dll")]
GlobalFree(IntPtr hMem)251 		internal static extern IntPtr GlobalFree(IntPtr hMem);
252 
253 		[DllImport("Kernel32.dll")]
GlobalLock(IntPtr hMem)254 		internal static extern IntPtr GlobalLock(IntPtr hMem);
255 
256 		[DllImport("Kernel32.dll", SetLastError = true)]
257 		[return: MarshalAs(UnmanagedType.Bool)]
GlobalUnlock(IntPtr hMem)258 		internal static extern bool GlobalUnlock(IntPtr hMem);
259 
260 		[DllImport("Kernel32.dll")]
GlobalSize(IntPtr hMem)261 		internal static extern UIntPtr GlobalSize(IntPtr hMem);
262 
263 		[DllImport("ShlWApi.dll", CharSet = CharSet.Auto)]
264 		[return: MarshalAs(UnmanagedType.Bool)]
PathCompactPathEx(StringBuilder pszOut, string szPath, uint cchMax, uint dwFlags)265 		internal static extern bool PathCompactPathEx(StringBuilder pszOut,
266 			string szPath, uint cchMax, uint dwFlags);
267 
268 		[DllImport("User32.dll")]
269 		[return: MarshalAs(UnmanagedType.Bool)]
DrawAnimatedRects(IntPtr hWnd, int idAni, [In] ref RECT lprcFrom, [In] ref RECT lprcTo)270 		internal static extern bool DrawAnimatedRects(IntPtr hWnd,
271 			int idAni, [In] ref RECT lprcFrom, [In] ref RECT lprcTo);
272 
273 		[DllImport("User32.dll")]
274 		[return: MarshalAs(UnmanagedType.Bool)]
GetComboBoxInfo(IntPtr hWnd, ref COMBOBOXINFO pcbi)275 		internal static extern bool GetComboBoxInfo(IntPtr hWnd,
276 			ref COMBOBOXINFO pcbi);
277 
278 		[DllImport("User32.dll", CharSet = CharSet.Auto, ExactSpelling = false,
279 			SetLastError = true)]
CreateDesktop(string lpszDesktop, string lpszDevice, IntPtr pDevMode, UInt32 dwFlags, [MarshalAs(UnmanagedType.U4)] DesktopFlags dwDesiredAccess, IntPtr lpSecurityAttributes)280 		internal static extern IntPtr CreateDesktop(string lpszDesktop,
281 			string lpszDevice, IntPtr pDevMode, UInt32 dwFlags,
282 			[MarshalAs(UnmanagedType.U4)] DesktopFlags dwDesiredAccess,
283 			IntPtr lpSecurityAttributes);
284 
285 		[DllImport("User32.dll", SetLastError = true)]
286 		[return: MarshalAs(UnmanagedType.Bool)]
CloseDesktop(IntPtr hDesktop)287 		internal static extern bool CloseDesktop(IntPtr hDesktop);
288 
289 		// [DllImport("User32.dll", SetLastError = true)]
290 		// internal static extern IntPtr OpenDesktop(string lpszDesktop,
291 		//	UInt32 dwFlags, [MarshalAs(UnmanagedType.Bool)] bool fInherit,
292 		//	[MarshalAs(UnmanagedType.U4)] DesktopFlags dwDesiredAccess);
293 
294 		[DllImport("User32.dll", SetLastError = true)]
295 		[return: MarshalAs(UnmanagedType.Bool)]
SwitchDesktop(IntPtr hDesktop)296 		internal static extern bool SwitchDesktop(IntPtr hDesktop);
297 
298 		[DllImport("User32.dll", SetLastError = true)]
OpenInputDesktop(uint dwFlags, [MarshalAs(UnmanagedType.Bool)] bool fInherit, [MarshalAs(UnmanagedType.U4)] DesktopFlags dwDesiredAccess)299 		internal static extern IntPtr OpenInputDesktop(uint dwFlags,
300 			[MarshalAs(UnmanagedType.Bool)] bool fInherit,
301 			[MarshalAs(UnmanagedType.U4)] DesktopFlags dwDesiredAccess);
302 
303 		[DllImport("User32.dll", SetLastError = true)]
304 		[return: MarshalAs(UnmanagedType.Bool)]
GetUserObjectInformation(IntPtr hObj, int nIndex, IntPtr pvInfo, uint nLength, ref uint lpnLengthNeeded)305 		internal static extern bool GetUserObjectInformation(IntPtr hObj,
306 			int nIndex, IntPtr pvInfo, uint nLength, ref uint lpnLengthNeeded);
307 
308 		[DllImport("User32.dll", SetLastError = true)]
GetThreadDesktop(uint dwThreadId)309 		internal static extern IntPtr GetThreadDesktop(uint dwThreadId);
310 
311 		[DllImport("User32.dll", SetLastError = true)]
312 		[return: MarshalAs(UnmanagedType.Bool)]
SetThreadDesktop(IntPtr hDesktop)313 		internal static extern bool SetThreadDesktop(IntPtr hDesktop);
314 
315 		[DllImport("Kernel32.dll")]
GetCurrentThreadId()316 		internal static extern uint GetCurrentThreadId();
317 
318 		[DllImport("Imm32.dll")]
319 		[return: MarshalAs(UnmanagedType.Bool)]
ImmDisableIME(uint idThread)320 		internal static extern bool ImmDisableIME(uint idThread);
321 
322 		// [DllImport("Imm32.dll")]
323 		// internal static extern IntPtr ImmAssociateContext(IntPtr hWnd, IntPtr hIMC);
324 
325 		[DllImport("Kernel32.dll", CharSet = CharSet.Auto, ExactSpelling = false,
326 			SetLastError = true)]
CreateFile(string lpFileName, [MarshalAs(UnmanagedType.U4)] EFileAccess dwDesiredAccess, [MarshalAs(UnmanagedType.U4)] EFileShare dwShareMode, IntPtr lpSecurityAttributes, [MarshalAs(UnmanagedType.U4)] ECreationDisposition dwCreationDisposition, [MarshalAs(UnmanagedType.U4)] uint dwFlagsAndAttributes, IntPtr hTemplateFile)327 		internal static extern IntPtr CreateFile(string lpFileName,
328 			[MarshalAs(UnmanagedType.U4)] EFileAccess dwDesiredAccess,
329 			[MarshalAs(UnmanagedType.U4)] EFileShare dwShareMode,
330 			IntPtr lpSecurityAttributes,
331 			[MarshalAs(UnmanagedType.U4)] ECreationDisposition dwCreationDisposition,
332 			[MarshalAs(UnmanagedType.U4)] uint dwFlagsAndAttributes,
333 			IntPtr hTemplateFile);
334 
335 		[DllImport("Kernel32.dll", SetLastError = true)]
336 		[return: MarshalAs(UnmanagedType.Bool)]
CloseHandle(IntPtr hObject)337 		internal static extern bool CloseHandle(IntPtr hObject);
338 
339 		[DllImport("Kernel32.dll", CharSet = CharSet.Auto, ExactSpelling = false,
340 			SetLastError = true)]
GetFileAttributes(string lpFileName)341 		internal static extern uint GetFileAttributes(string lpFileName);
342 
343 		[DllImport("Kernel32.dll", CharSet = CharSet.Auto, ExactSpelling = false,
344 			SetLastError = true)]
345 		[return: MarshalAs(UnmanagedType.Bool)]
DeleteFile(string lpFileName)346 		internal static extern bool DeleteFile(string lpFileName);
347 
348 		[DllImport("Kernel32.dll", ExactSpelling = true, SetLastError = true)]
349 		[return: MarshalAs(UnmanagedType.Bool)]
DeviceIoControl(IntPtr hDevice, uint dwIoControlCode, IntPtr lpInBuffer, uint nInBufferSize, IntPtr lpOutBuffer, uint nOutBufferSize, out uint lpBytesReturned, IntPtr lpOverlapped)350 		internal static extern bool DeviceIoControl(IntPtr hDevice, uint dwIoControlCode,
351 			IntPtr lpInBuffer, uint nInBufferSize, IntPtr lpOutBuffer, uint nOutBufferSize,
352 			out uint lpBytesReturned, IntPtr lpOverlapped);
353 
354 		[DllImport("ComCtl32.dll", CharSet = CharSet.Auto)]
TaskDialogIndirect([In] ref VtdConfig pTaskConfig, [Out] out int pnButton, [Out] out int pnRadioButton, [Out] [MarshalAs(UnmanagedType.Bool)] out bool pfVerificationFlagChecked)355 		internal static extern Int32 TaskDialogIndirect([In] ref VtdConfig pTaskConfig,
356 			[Out] out int pnButton, [Out] out int pnRadioButton,
357 			[Out] [MarshalAs(UnmanagedType.Bool)] out bool pfVerificationFlagChecked);
358 
359 		[DllImport("UxTheme.dll", ExactSpelling = true, CharSet = CharSet.Unicode)]
SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList)360 		internal static extern int SetWindowTheme(IntPtr hWnd, string pszSubAppName,
361 			string pszSubIdList);
362 
363 		[DllImport("Shell32.dll")]
SHChangeNotify(int wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2)364 		internal static extern void SHChangeNotify(int wEventId, uint uFlags,
365 			IntPtr dwItem1, IntPtr dwItem2);
366 
367 		// [DllImport("Shell32.dll")]
368 		// internal static extern uint SHChangeNotifyRegister(IntPtr hwnd, int fSources,
369 		//	int fEvents, uint wMsg, int cEntries, ref SHCHANGENOTIFYENTRY pshcne);
370 
371 		// [DllImport("Shell32.dll")]
372 		// [return: MarshalAs(UnmanagedType.Bool)]
373 		// internal static extern bool SHChangeNotifyDeregister(uint ulID);
374 
375 		[DllImport("User32.dll")]
376 		[return: MarshalAs(UnmanagedType.Bool)]
GetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi)377 		private static extern bool GetScrollInfo(IntPtr hwnd, int fnBar,
378 			ref SCROLLINFO lpsi);
379 
380 		// [DllImport("User32.dll")]
381 		// private static extern int SetScrollInfo(IntPtr hwnd, int fnBar,
382 		//	[In] ref SCROLLINFO lpsi, [MarshalAs(UnmanagedType.Bool)] bool fRedraw);
383 
384 		// [DllImport("User32.dll")]
385 		// private static extern int ScrollWindowEx(IntPtr hWnd, int dx, int dy,
386 		//	IntPtr prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate,
387 		//	uint flags);
388 
389 		[DllImport("User32.dll")]
GetKeyboardLayout(uint idThread)390 		internal static extern IntPtr GetKeyboardLayout(uint idThread);
391 
392 		[DllImport("User32.dll")]
ActivateKeyboardLayout(IntPtr hkl, uint uFlags)393 		internal static extern IntPtr ActivateKeyboardLayout(IntPtr hkl, uint uFlags);
394 
395 		[DllImport("User32.dll")]
GetWindowThreadProcessId(IntPtr hWnd, [Out] out uint lpdwProcessId)396 		internal static extern uint GetWindowThreadProcessId(IntPtr hWnd,
397 			[Out] out uint lpdwProcessId);
398 
399 		// [DllImport("UxTheme.dll")]
400 		// internal static extern IntPtr OpenThemeData(IntPtr hWnd,
401 		//	[MarshalAs(UnmanagedType.LPWStr)] string pszClassList);
402 
403 		// [DllImport("UxTheme.dll")]
404 		// internal static extern uint CloseThemeData(IntPtr hTheme);
405 
406 		// [DllImport("UxTheme.dll")]
407 		// internal extern static uint DrawThemeBackground(IntPtr hTheme, IntPtr hdc,
408 		//	int iPartId, int iStateId, ref RECT pRect, ref RECT pClipRect);
409 
410 		[DllImport("Gdi32.dll")]
411 		[return: MarshalAs(UnmanagedType.Bool)]
DeleteObject(IntPtr hObject)412 		internal static extern bool DeleteObject(IntPtr hObject);
413 
414 		[DllImport("User32.dll")]
415 		[return: MarshalAs(UnmanagedType.Bool)]
GetLastInputInfo(ref LASTINPUTINFO plii)416 		private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
417 
418 		[DllImport("Shell32.dll", CharSet = CharSet.Auto)]
SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, uint uFlags)419 		private static extern IntPtr SHGetFileInfo(string pszPath,
420 			uint dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo,
421 			uint uFlags);
422 
423 		[DllImport("User32.dll")]
424 		[return: MarshalAs(UnmanagedType.Bool)]
DestroyIcon(IntPtr hIcon)425 		internal static extern bool DestroyIcon(IntPtr hIcon);
426 
427 		// [DllImport("User32.dll", SetLastError = true)]
428 		// [return: MarshalAs(UnmanagedType.Bool)]
429 		// internal static extern bool DrawIconEx(IntPtr hdc, int xLeft, int yTop,
430 		//	IntPtr hIcon, int cxWidth, int cyWidth, uint istepIfAniCur,
431 		//	IntPtr hbrFlickerFreeDraw, uint diFlags);
432 
433 		[DllImport("User32.dll")]
GetDC(IntPtr hWnd)434 		internal static extern IntPtr GetDC(IntPtr hWnd);
435 
436 		[DllImport("User32.dll")]
ReleaseDC(IntPtr hWnd, IntPtr hDC)437 		internal static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
438 
439 		[DllImport("Gdi32.dll")]
GetDeviceCaps(IntPtr hdc, int nIndex)440 		internal static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
441 
442 		[DllImport("WinMM.dll", CharSet = CharSet.Auto)]
443 		[return: MarshalAs(UnmanagedType.Bool)]
PlaySound(string pszSound, IntPtr hmod, uint fdwSound)444 		internal static extern bool PlaySound(string pszSound, IntPtr hmod,
445 			uint fdwSound);
446 
447 		// [DllImport("Shell32.dll", CharSet = CharSet.Auto)]
448 		// internal static extern IntPtr ShellExecute(IntPtr hwnd,
449 		//	string lpOperation, string lpFile, string lpParameters,
450 		//	string lpDirectory, int nShowCmd);
451 
452 		[DllImport("User32.dll", CharSet = CharSet.Auto)]
MessageBox(IntPtr hWnd, string lpText, string lpCaption, [MarshalAs(UnmanagedType.U4)] MessageBoxFlags uType)453 		internal static extern int MessageBox(IntPtr hWnd, string lpText,
454 			string lpCaption, [MarshalAs(UnmanagedType.U4)] MessageBoxFlags uType);
455 
456 		[DllImport("User32.dll")]
457 		[return: MarshalAs(UnmanagedType.Bool)]
SetProcessDPIAware()458 		internal static extern bool SetProcessDPIAware();
459 
460 		[DllImport("ShCore.dll")]
SetProcessDpiAwareness( [MarshalAs(UnmanagedType.U4)] ProcessDpiAwareness a)461 		internal static extern int SetProcessDpiAwareness(
462 			[MarshalAs(UnmanagedType.U4)] ProcessDpiAwareness a);
463 
464 		[DllImport("Kernel32.dll")]
CreateToolhelp32Snapshot( [MarshalAs(UnmanagedType.U4)] ToolHelpFlags dwFlags, uint th32ProcessID)465 		internal static extern IntPtr CreateToolhelp32Snapshot(
466 			[MarshalAs(UnmanagedType.U4)] ToolHelpFlags dwFlags, uint th32ProcessID);
467 
468 		[DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
469 		[return: MarshalAs(UnmanagedType.Bool)]
Process32First(IntPtr hSnapshot, ref PROCESSENTRY32 lppe)470 		internal static extern bool Process32First(IntPtr hSnapshot,
471 			ref PROCESSENTRY32 lppe);
472 
473 		[DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
474 		[return: MarshalAs(UnmanagedType.Bool)]
Process32Next(IntPtr hSnapshot, ref PROCESSENTRY32 lppe)475 		internal static extern bool Process32Next(IntPtr hSnapshot,
476 			ref PROCESSENTRY32 lppe);
477 
478 		// [DllImport("Kernel32.dll", SetLastError = true)]
479 		// internal static extern IntPtr OpenProcess(uint dwDesiredAccess,
480 		//	[MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, uint dwProcessId);
481 
482 		// [DllImport("User32.dll")]
483 		// [return: MarshalAs(UnmanagedType.Bool)]
484 		// internal static extern bool IsImmersiveProcess(IntPtr hProcess);
485 
486 		[DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
CreateActCtx(ref ACTCTX pActCtx)487 		internal static extern IntPtr CreateActCtx(ref ACTCTX pActCtx);
488 
489 		[DllImport("Kernel32.dll")]
ReleaseActCtx(IntPtr hActCtx)490 		internal static extern void ReleaseActCtx(IntPtr hActCtx);
491 
492 		[DllImport("Kernel32.dll")]
493 		[return: MarshalAs(UnmanagedType.Bool)]
ActivateActCtx(IntPtr hActCtx, ref UIntPtr lpCookie)494 		internal static extern bool ActivateActCtx(IntPtr hActCtx,
495 			ref UIntPtr lpCookie);
496 
497 		[DllImport("Kernel32.dll")]
498 		[return: MarshalAs(UnmanagedType.Bool)]
DeactivateActCtx(uint dwFlags, UIntPtr ulCookie)499 		internal static extern bool DeactivateActCtx(uint dwFlags,
500 			UIntPtr ulCookie);
501 
502 		[DllImport("User32.dll", SetLastError = true)]
503 		[return: MarshalAs(UnmanagedType.Bool)]
ShutdownBlockReasonCreate(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] string pwszReason)504 		internal static extern bool ShutdownBlockReasonCreate(IntPtr hWnd,
505 			[MarshalAs(UnmanagedType.LPWStr)] string pwszReason);
506 
507 		[DllImport("User32.dll", SetLastError = true)]
508 		[return: MarshalAs(UnmanagedType.Bool)]
ShutdownBlockReasonDestroy(IntPtr hWnd)509 		internal static extern bool ShutdownBlockReasonDestroy(IntPtr hWnd);
510 
511 		// [DllImport("User32.dll")]
512 		// internal static extern int GetSystemMetrics(int nIndex);
513 
514 		[DllImport("User32.dll", SetLastError = true)]
515 		[return: MarshalAs(UnmanagedType.Bool)]
SetWindowDisplayAffinity(IntPtr hWnd, uint dwAffinity)516 		internal static extern bool SetWindowDisplayAffinity(IntPtr hWnd,
517 			uint dwAffinity);
518 
519 		[DllImport("User32.dll", EntryPoint = "SystemParametersInfo",
520 			CharSet = CharSet.Auto, ExactSpelling = false, SetLastError = true)]
521 		[return: MarshalAs(UnmanagedType.Bool)]
SystemParametersInfoI32(uint uiAction, uint uiParam, ref int pvParam, uint fWinIni)522 		internal static extern bool SystemParametersInfoI32(uint uiAction,
523 			uint uiParam, ref int pvParam, uint fWinIni);
524 	}
525 }
526