Thanx for any help. The code below worked well in VB6 but as I was hobbiest in vb6, I am floundering in VBnet. Please help me convert this, VBnet seems to dislike this code.
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByRef lpBuffer As Long, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Declare Function ReadProcessMemoryStr Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByVal lpBuffer As String, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Declare Function ReadProcessMemoryVal Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByRef lpBuffer As Long, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Dim hwnd As Long
Dim pid As Long
Dim pHandle As Long
Dim hProcess As Long
Dim Val1 As String * 16
Dim Val2 As Long
Dim Val3 As Long
Dim Myhex
hwnd = FindWindow(vbNullString, "any program window name here")
If hwnd = 0 Then
Exit Sub
End If
GetWindowThreadProcessId (hwnd, pid)
pHandle = OpenProcess(&H1F0FFF, False, pid)
If pHandle = 0 Then
Exit Sub
End If
'example
ReadProcessMemoryStr pHandle, &H1000070, Val1, 1, 0& 'Reads as String
Text1 = Val1
ReadProcessMemoryVal pHandle, &H1000070, Val2, 1, 0& 'Reads as value
Text2 = Val2
ReadProcessMemoryVal pHandle, &H1000070, Val3, 1, 0& 'Reads as hex
Myhex = Hex(Val3)
Text3 = Myhex
WriteProcessMemory pHandle, &H1000070, 4, 1, 0& 'Set value to 4
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByRef lpBuffer As Long, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Declare Function ReadProcessMemoryStr Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByVal lpBuffer As String, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Declare Function ReadProcessMemoryVal Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByRef lpBuffer As Long, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Dim hwnd As Long
Dim pid As Long
Dim pHandle As Long
Dim hProcess As Long
Dim Val1 As String * 16
Dim Val2 As Long
Dim Val3 As Long
Dim Myhex
hwnd = FindWindow(vbNullString, "any program window name here")
If hwnd = 0 Then
Exit Sub
End If
GetWindowThreadProcessId (hwnd, pid)
pHandle = OpenProcess(&H1F0FFF, False, pid)
If pHandle = 0 Then
Exit Sub
End If
'example
ReadProcessMemoryStr pHandle, &H1000070, Val1, 1, 0& 'Reads as String
Text1 = Val1
ReadProcessMemoryVal pHandle, &H1000070, Val2, 1, 0& 'Reads as value
Text2 = Val2
ReadProcessMemoryVal pHandle, &H1000070, Val3, 1, 0& 'Reads as hex
Myhex = Hex(Val3)
Text3 = Myhex
WriteProcessMemory pHandle, &H1000070, 4, 1, 0& 'Set value to 4
Last edited: