Results 1 to 4 of 4

Thread: Why is the textbox empty?

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    13

    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:
    1. Private Const PROCESS_ALL_ACCESS = &H1F0FFF
    2.     Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, ByVal lpdwProcessId As Long) As Long
    3.     Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    4.     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
    5.     Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    6.     Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal ClassName As String, ByVal WindowName As String) As Long
    7.     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
    8.  
    9.  
    10.     Public Function ReadLong(ByVal strName As String, ByVal Offset As Long) 'no point in useing this ByVal valBuffer As Long)
    11.         Dim hWnd As Long
    12.         Dim pId As Long
    13.         Dim pHandle As Long
    14.         Dim Value As Long   'Place to store our data.
    15.  
    16.  
    17.         'To get window handle by useing the ClassName as a pointer, uncomment this..
    18.         'hWnd = FindWindow(strName, vbNullString)
    19.  
    20.         'To get window handle by useing the Window name as a pointer, uncomment this..
    21.          hWnd = FindWindow(vbNullString, strName)
    22.         If hWnd = 0 Then
    23.             MsgBox("Sorry, couldn't get handle", vbExclamation, "Error")
    24.             Exit Function
    25.         End If
    26.  
    27.         'notice I didn't use the "()" since this isn't a call..
    28.         GetWindowThreadProcessId(hWnd, pId)
    29.  
    30.  
    31.         pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pId)
    32.         If pHandle = 0 Then
    33.             MsgBox("Couldn't get ProcessId", vbCritical, "Error")
    34.             Exit Function
    35.         End If
    36.         ReadProcessMem(pHandle, Offset, Value, &H4, 0&)
    37.         ReadLong = Value 'Return with what we read
    38.  
    39.         CloseHandle(pHandle)
    40.  
    41.     End Function

    Now here is my Form:

    VB Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2.         Dim Offset As Long
    3.         Dim GameClass As String
    4.         Dim WindowName As String
    5.         Dim Value As Long
    6.  
    7.         Offset = &Hxxxxxx 'Put start address to read from here
    8.  
    9.        'To read from memory by useing ClassName as pointer, uncomment these lines..
    10.        'GameClass = ""
    11.        'Value = ReadLong(Offset, GameClass)
    12.  
    13.         'To read from memory by useing WindowName as pointer, uncomment these lines..
    14.          WindowName = "Bingo"
    15.          Value = ReadLong(Offset, WindowName)
    16.  
    17.         'What ever has been read gets returned to the Value buffer
    18.         TextBox1.Text = Value
    19.  
    20.     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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width