|
-
Jan 14th, 2004, 01:06 PM
#1
Thread Starter
New Member
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:
Cast from string "Bingo" to type 'Long' is not valid.
Last edited by Tortle; Jan 14th, 2004 at 01:39 PM.
-
Jan 14th, 2004, 02:25 PM
#2
Frenzied Member
Well, your last question is easy. You're passing a string variable, WindowName, when the function you wrote requires a Long variable in the second argument. Switch your variables around when you call ReadLong, or switch them in the function declaration.
-
Jan 14th, 2004, 04:54 PM
#3
Thread Starter
New Member
Thanks that worked.
But now it is giving another error: "Object reference not set to an instance of an object."
-
Jan 14th, 2004, 07:30 PM
#4
Frenzied Member
I don't know all the API calls. It looks like you're not setting values for pId or Value; I suppose they'd default to 0 as a Long, but maybe that doesn't give you the result you need, so your later calculations don't work.
In your call to ReadProcessMem, you have one & before an argument, one after. Don't know if that gives an error.
Try stepping through, or Try/Catch, or msgbox, or something, to examine the values as it runs. What Object Reference isn't set?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|