By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,601 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,601 IT Pros & Developers. It's quick & easy.

ReadProcessMemory (VB2005)

P: 63
Hi all,

I got a problem with my code to check a game's chat position and write text to the game when a command is written by someone on the chat. I haven't figured out yet how to make it send keys to the gamewindow when it's not focussed, and WriteProcessMemory, but that's for a later issue.

This is my current code:

Expand|Select|Wrap|Line Numbers
  1. Public Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
  2. Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
  3. Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Byte, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
  4. Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
  5. Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As IntPtr) As Integer
  6. Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As IntPtr
  7.  
  8.     Public Sub ReadChat(ByVal Command As String)
  9.  
  10.         Dim hwnd As Integer
  11.         Dim hprocess As Integer
  12.         Dim readprocess
  13.         Dim chataddress As Integer
  14.         Dim votesneeded As String = txtvotesneeded.Text
  15.  
  16.         If hwnd = FindWindow(vbNullString, Game1) = True Then
  17.             chataddress = &H698726
  18.         ElseIf hwnd = FindWindow(vbNullString, Game2) = True Then
  19.             chataddress = &H685381
  20.         Else
  21.             MsgBox("Please Startup the game first before clicking the Start button", MsgBoxStyle.Critical, "Error!")
  22.         End If
  23.  
  24.         On Error Resume Next
  25.         MsgBox("Error #17 occured. Please ask for help at support forum.", MsgBoxStyle.Critical, "Error!")
  26.  
  27.         If hwnd >= 0 Then
  28.             hprocess = OpenProcess(PROCESS_ALL_ACCESS, False, hwnd)
  29.             readprocess = ReadProcessMemory(hprocess, ChatAddress, 78, 78, vbNullString)
  30.             CloseHandle(hprocess)
  31.         End If
  32.  
  33.         If readprocess = Command Then
  34.             SendKeys.Send("{T}")
  35.             Wait(100)
  36.             SendKeys.Send("There are " & votesneeded & " more votes needed to skip map.")
  37.             Wait(100)
  38.             SendKeys.Send("{ENTER}")
  39.         End If
  40.  
  41.     End Sub
  42.  
The game consists of 2 different versions, that's why I want it to change the chataddress to suit each version.
I'm not sure if I done all this code the right way. The only error it gave me during runtime was something with "readprocess". A conversion from type String to type Double failed.

I hope someone can help me get this code right and help me taking any errors out which could prevent it from working perfect.

Thanks in advance !
Evolution445
Sep 12 '07 #1
Share this Question
Share on Google+
5 Replies


Expert 5K+
P: 8,434
Um... what data type is readprocess supposed to be?
Sep 13 '07 #2

P: 63
Um... what data type is readprocess supposed to be?
Expand|Select|Wrap|Line Numbers
  1. Dim readprocess
  2.  
  3. readprocess = ReadProcessMemory(hprocess, ChatAddress, 78, 78, vbNullString)
  4.  
Would the problem be solved if I Dim readprocess as Double ?
Sep 13 '07 #3

Expert 5K+
P: 8,434
Would the problem be solved if I Dim readprocess as Double ?
I don't know, but it wouldn't hurt to try.

I guess the main questions to be answered would be...
  • What data type does ReadProcessMemory() function return?
  • What are the specific details of the error?
  • Exactly where in the code does the error occur?

If this were VB6, I'd advise against calling a variable Command, since that's the name under which command-line parameters are retrieved. But in VB2005, I don't know how that works.
Sep 13 '07 #4

hariharanmca
100+
P: 1,977
I think this link will help you.

Write/ReadProcessMemory errors of 487 and 299
Sep 13 '07 #5

P: 63
I don't know, but it wouldn't hurt to try.

I guess the main questions to be answered would be...
  • What data type does ReadProcessMemory() function return?
  • What are the specific details of the error?
  • Exactly where in the code does the error occur?

If this were VB6, I'd advise against calling a variable Command, since that's the name under which command-line parameters are retrieved. But in VB2005, I don't know how that works.
ReadProcessMemory should only read the chat position and see if there's a specified word written by someone. I think it should only return either True or False.

I think this is how it should go, or what it suposes to do:
------------------
* Read the chataddress with ReadProcessMemory
* If "......." is written Then
* Respond using SendKeys
------------------

This is where the error occured:
Expand|Select|Wrap|Line Numbers
  1.         If readprocess = Command Then
  2.             SendKeys.Send("{T}")
  3.             Wait(100)
  4.             SendKeys.Send("There are " & votesneeded & " more votes needed to skip map.")
  5.             Wait(100)
  6.             SendKeys.Send("{ENTER}")
  7.         End If
  8.  
I'm not sure if I done this right. Infact, I'm not sure about whole my code.
Any help is appreciated.
Sep 15 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.