Why is the textbox empty?
Someone helped me revise my code I posted a while ago.
Anyway, what it is suppose to do is read a value stored in a specified memory address of a specified process.
Can someone look it over and guess why nothing shows up in the Textbox? Is it reading the value held by the address? Then why is the value not being displayed in the Textbox?
Module:
VB Code:
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, ByVal lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByVal lpBuffer As Long, ByVal nSize As Long, ByVal lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal ClassName As String, ByVal WindowName As String) As Long
Private Declare Function ReadProcessMem Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByRef lpBuffer As Long, ByVal nSize As Long, ByVal lpNumberOfBytesWritten As Long) As Long
Public Function ReadLong(ByVal strName As String, ByVal Offset As Long) 'no point in useing this ByVal valBuffer As Long)
Dim hWnd As Long
Dim pId As Long
Dim pHandle As Long
Dim Value As Long 'Place to store our data.
'To get window handle by useing the ClassName as a pointer, uncomment this..
'hWnd = FindWindow(strName, vbNullString)
'To get window handle by useing the Window name as a pointer, uncomment this..
hWnd = FindWindow(vbNullString, strName)
If hWnd = 0 Then
MsgBox("Sorry, couldn't get handle", vbExclamation, "Error")
Exit Function
End If
'notice I didn't use the "()" since this isn't a call..
GetWindowThreadProcessId(hWnd, pId)
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pId)
If pHandle = 0 Then
MsgBox("Couldn't get ProcessId", vbCritical, "Error")
Exit Function
End If
ReadProcessMem(pHandle, Offset, Value, &H4, 0&)
ReadLong = Value 'Return with what we read
CloseHandle(pHandle)
End Function
Now here is my Form:
VB Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim Offset As Long
Dim GameClass As String
Dim WindowName As String
Dim Value As Long
Offset = &Hxxxxxx 'Put start address to read from here
'To read from memory by useing ClassName as pointer, uncomment these lines..
'GameClass = ""
'Value = ReadLong(Offset, GameClass)
'To read from memory by useing WindowName as pointer, uncomment these lines..
WindowName = "Bingo"
Value = ReadLong(Offset, WindowName)
'What ever has been read gets returned to the Value buffer
TextBox1.Text = Value
End Sub
I also get this error when I try to run the program:
Quote:
Cast from string "Bingo" to type 'Long' is not valid.