191 lines
8.6 KiB
VB.net
191 lines
8.6 KiB
VB.net
Imports System.Runtime.InteropServices
|
|
Imports System.Text
|
|
|
|
Public Class NativeMethods
|
|
Public Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Int32) As Integer
|
|
Public Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As IntPtr, ByVal WinTitle As String, ByVal MaxLength As Integer) As Integer
|
|
|
|
<DllImport("Shell32", CharSet:=CharSet.Auto, SetLastError:=True)>
|
|
Public Shared Function ShellExecuteEx(ByRef lpExecInfo As ShellExecuteInfo) As Boolean
|
|
End Function
|
|
<DllImport("user32.dll")>
|
|
Public Shared Function GetDC(ByVal hwnd As IntPtr) As IntPtr
|
|
End Function
|
|
<DllImport("user32.dll")>
|
|
Public Shared Function ReleaseDC(ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As IntPtr
|
|
End Function
|
|
<DllImport("user32.dll")>
|
|
Public Shared Function GetWindowRect(ByVal hWnd As HandleRef, ByRef lpRect As RectangleAPI) As Boolean
|
|
End Function
|
|
<DllImport("user32.dll")>
|
|
Public Shared Function AttachThreadInput(ByVal idAttach As IntPtr, ByVal idAttachTo As IntPtr, fAttach As Boolean) As Boolean
|
|
End Function
|
|
<DllImport("user32.dll")>
|
|
Public Shared Function GetFocus() As IntPtr
|
|
End Function
|
|
<DllImport("user32.dll")>
|
|
Public Shared Function WindowFromPoint(ByVal p As PointAPI) As IntPtr
|
|
End Function
|
|
<DllImport("user32.dll")>
|
|
Public Shared Function GetForegroundWindow() As IntPtr
|
|
End Function
|
|
<DllImport("user32.dll")>
|
|
Public Shared Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, ByRef lpdwProcessID As Integer) As Integer
|
|
End Function
|
|
<DllImport("user32.dll")>
|
|
Public Shared Function GetClassName(ByVal hwnd As Integer, ByVal lpClassName As StringBuilder, ByVal nMaxCount As Integer) As Integer
|
|
End Function
|
|
<DllImport("kernel32.dll")>
|
|
Public Shared Function OpenProcess(ByVal dwDesiredAccess As UInteger, ByVal bInheritHandle As Boolean, ByVal dwProcessId As UInteger) As IntPtr
|
|
End Function
|
|
<DllImport("kernel32.dll")>
|
|
Public Shared Function VirtualAllocEx(ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As UIntPtr, ByVal flAllocationType As UInteger, ByVal flProtect As PageProtection) As IntPtr
|
|
End Function
|
|
<DllImport("user32.dll", SetLastError:=True)>
|
|
Public Shared Function GetWindowThreadProcessId(ByVal hWnd As IntPtr, <Out> ByRef lpdwProcessId As UInteger) As UInteger
|
|
End Function
|
|
<DllImport("kernel32.dll")>
|
|
Public Shared Function VirtualFreeEx(ByVal hProcess As IntPtr, ByVal lpAddress As IntPtr, ByVal dwSize As UIntPtr, ByVal dwFreeType As UInteger) As Boolean
|
|
End Function
|
|
<DllImport("kernel32.dll")>
|
|
Public Shared Function CloseHandle(ByVal hObject As IntPtr) As Boolean
|
|
End Function
|
|
<DllImport("kernel32.dll")>
|
|
Public Shared Function MapViewOfFile(ByVal hFileMappingObject As IntPtr, ByVal dwDesiredAccess As UInteger, ByVal dwFileOffsetHigh As UInteger, ByVal dwFileOffsetLow As UInteger, ByVal dwNumberOfBytesToMap As UIntPtr) As IntPtr
|
|
End Function
|
|
<DllImport("kernel32.dll")>
|
|
Public Shared Function UnmapViewOfFile(ByVal lpBaseAddress As IntPtr) As Boolean
|
|
End Function
|
|
<DllImport("kernel32.dll", SetLastError:=True)>
|
|
Public Shared Function CreateFileMapping(ByVal hFile As IntPtr, ByVal lpFileMappingAttributes As IntPtr, ByVal flProtect As PageProtection, ByVal dwMaximumSizeHigh As Integer, ByVal dwMaximumSizeLow As Integer, ByVal lpName As String) As IntPtr
|
|
End Function
|
|
<DllImport("user32.dll")>
|
|
Public Shared Function SendMessage(ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
|
|
End Function
|
|
<DllImport("kernel32.dll")>
|
|
Public Shared Function ReadProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAddress As IntPtr,
|
|
<Out> ByVal lpBuffer As Byte(), ByVal nSize As UIntPtr, ByVal lpNumberOfBytesRead As IntPtr) As Boolean
|
|
End Function
|
|
<DllImport("Kernel32.dll", EntryPoint:="RtlMoveMemory", SetLastError:=False)>
|
|
Public Shared Sub MoveMemoryFromByte(ByVal dest As IntPtr, ByRef src As Byte, ByVal size As Integer)
|
|
End Sub
|
|
<DllImport("Kernel32.dll", EntryPoint:="RtlMoveMemory", SetLastError:=False)>
|
|
Public Shared Sub MoveMemoryToByte(ByRef dest As Byte, ByVal src As IntPtr, ByVal size As Integer)
|
|
End Sub
|
|
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
|
|
Public Shared Function RegisterWindowMessage(ByVal lpString As String) As Integer
|
|
End Function
|
|
<DllImport("user32.dll", ExactSpelling:=True, SetLastError:=True)>
|
|
Public Shared Function GetCursorPos(ByRef lpPoint As PointAPI) As <MarshalAs(UnmanagedType.Bool)> Boolean
|
|
End Function
|
|
|
|
Public Declare Function RegisterHotKey Lib "user32" (
|
|
ByVal Hwnd As IntPtr,
|
|
ByVal ID As Integer,
|
|
ByVal Modifiers As Integer,
|
|
ByVal Key As Integer
|
|
) As Integer
|
|
|
|
Public Declare Function UnregisterHotKey Lib "user32" (
|
|
ByVal Hwnd As IntPtr,
|
|
ByVal ID As Integer
|
|
) As Integer
|
|
|
|
Public Declare Auto Function GetWindowText Lib "user32" (
|
|
ByVal hWnd As IntPtr,
|
|
ByVal lpString As StringBuilder,
|
|
ByVal cch As Integer
|
|
) As Integer
|
|
|
|
Public Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal IDString As String) As Short
|
|
Public Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal Atom As Short) As Short
|
|
|
|
Public Const STANDARD_RIGHTS_REQUIRED As Integer = &HF0000
|
|
Public Const SECTION_QUERY As Short = &H1
|
|
Public Const SECTION_MAP_WRITE As Short = &H2
|
|
Public Const SECTION_MAP_READ As Short = &H4
|
|
Public Const SECTION_MAP_EXECUTE As Short = &H8
|
|
Public Const SECTION_EXTEND_SIZE As Short = &H10
|
|
Public Const SECTION_ALL_ACCESS As Integer = STANDARD_RIGHTS_REQUIRED Or SECTION_QUERY Or SECTION_MAP_WRITE Or SECTION_MAP_READ Or SECTION_MAP_EXECUTE Or SECTION_EXTEND_SIZE
|
|
Public Const FILE_MAP_ALL_ACCESS As Integer = SECTION_ALL_ACCESS
|
|
Public Const PROCESS_VM_OPERATION As Short = &H8
|
|
Public Const PROCESS_VM_READ As Short = &H10
|
|
Public Const PROCESS_VM_WRITE As Short = &H20
|
|
Public Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
|
|
Public Const MEM_COMMIT As Short = &H1000
|
|
Public Const MEM_RESERVE As Short = &H2000
|
|
Public Const MEM_DECOMMIT As Short = &H4000
|
|
Public Const MEM_RELEASE As Integer = &H8000
|
|
Public Const MEM_FREE As Integer = &H10000
|
|
Public Const MEM_PRIVATE As Integer = &H20000
|
|
Public Const MEM_MAPPED As Integer = &H40000
|
|
Public Const MEM_TOP_DOWN As Integer = &H100000
|
|
Public Const INVALID_HANDLE_VALUE As Integer = -1
|
|
Public Const SW_SHOW As Short = 5
|
|
Public Const SEE_MASK_INVOKEIDLIST = &HC
|
|
Public Const SEE_MASK_NOCLOSEPROCESS = &H40
|
|
Public Const SEE_MASK_FLAG_NO_UI = &H400
|
|
Public Const WM_HOTKEY As Integer = &H312
|
|
|
|
Public Enum PageProtection As UInteger
|
|
NoAccess = &H1
|
|
[Readonly] = &H2
|
|
ReadWrite = &H4
|
|
WriteCopy = &H8
|
|
Execute = &H10
|
|
ExecuteRead = &H20
|
|
ExecuteReadWrite = &H40
|
|
ExecuteWriteCopy = &H80
|
|
Guard = &H100
|
|
NoCache = &H200
|
|
WriteCombine = &H400
|
|
End Enum
|
|
|
|
Public Enum ChildWindowFromPointFlags As UInteger
|
|
CWP_ALL
|
|
CWP_SKIPINVISIBLE
|
|
CWP_SKIPDISABLED
|
|
CWP_SKIPTRANSPARENT
|
|
End Enum
|
|
|
|
Public Structure RectangleAPI
|
|
Public Left As Integer
|
|
Public Top As Integer
|
|
Public Right As Integer
|
|
Public Bottom As Integer
|
|
|
|
Public Overrides Function ToString() As String
|
|
Return String.Format("Top: {0}, Bottom: {1}, Left: {2}, Right: {3}", Top, Bottom, Left, Right)
|
|
End Function
|
|
End Structure
|
|
|
|
Public Structure ShellExecuteInfo
|
|
Public cbSize As Integer
|
|
Public fMask As Integer
|
|
Public hwnd As IntPtr
|
|
<MarshalAs(UnmanagedType.LPTStr)> Public lpVerb As String
|
|
<MarshalAs(UnmanagedType.LPTStr)> Public lpFile As String
|
|
<MarshalAs(UnmanagedType.LPTStr)> Public lpParameters As String
|
|
<MarshalAs(UnmanagedType.LPTStr)> Public lpDirectory As String
|
|
Dim nShow As Integer
|
|
Dim hInstApp As IntPtr
|
|
Dim lpIDList As IntPtr
|
|
<MarshalAs(UnmanagedType.LPTStr)> Public lpClass As String
|
|
Public hkeyClass As IntPtr
|
|
Public dwHotKey As Integer
|
|
Public hIcon As IntPtr
|
|
Public hProcess As IntPtr
|
|
End Structure
|
|
|
|
<System.Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)>
|
|
Public Structure PointAPI
|
|
Public X As Integer
|
|
Public Y As Integer
|
|
|
|
Public Sub New(ByVal X As Integer, ByVal Y As Integer)
|
|
Me.X = X
|
|
Me.Y = Y
|
|
End Sub
|
|
End Structure
|
|
End Class
|