ReadProcessMemory (VB2005)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Evolution445
    New Member
    • Jul 2007
    • 63

    ReadProcessMemory (VB2005)

    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 WriteProcessMem ory, but that's for a later issue.

    This is my current code:

    [code=vb]
    Public Const PROCESS_ALL_ACC ESS As Long = &H1F0FFF
    Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    Public Declare Function ReadProcessMemo ry Lib "kernel32" (ByVal hProcess As IntPtr, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Byte, ByVal nSize As Integer, ByRef lpNumberOfBytes Written As Integer) As Integer
    Public Declare Function WriteProcessMem ory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytes Written As Integer) As Integer
    Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As IntPtr) As Integer
    Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As IntPtr

    Public Sub ReadChat(ByVal Command As String)

    Dim hwnd As Integer
    Dim hprocess As Integer
    Dim readprocess
    Dim chataddress As Integer
    Dim votesneeded As String = txtvotesneeded. Text

    If hwnd = FindWindow(vbNu llString, Game1) = True Then
    chataddress = &H698726
    ElseIf hwnd = FindWindow(vbNu llString, Game2) = True Then
    chataddress = &H685381
    Else
    MsgBox("Please Startup the game first before clicking the Start button", MsgBoxStyle.Cri tical, "Error!")
    End If

    On Error Resume Next
    MsgBox("Error #17 occured. Please ask for help at support forum.", MsgBoxStyle.Cri tical, "Error!")

    If hwnd >= 0 Then
    hprocess = OpenProcess(PRO CESS_ALL_ACCESS , False, hwnd)
    readprocess = ReadProcessMemo ry(hprocess, ChatAddress, 78, 78, vbNullString)
    CloseHandle(hpr ocess)
    End If

    If readprocess = Command Then
    SendKeys.Send(" {T}")
    Wait(100)
    SendKeys.Send(" There are " & votesneeded & " more votes needed to skip map.")
    Wait(100)
    SendKeys.Send(" {ENTER}")
    End If

    End Sub
    [/code]

    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 "readproces s". 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
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Um... what data type is readprocess supposed to be?

    Comment

    • Evolution445
      New Member
      • Jul 2007
      • 63

      #3
      Originally posted by Killer42
      Um... what data type is readprocess supposed to be?
      [code=vb]
      Dim readprocess

      readprocess = ReadProcessMemo ry(hprocess, ChatAddress, 78, 78, vbNullString)
      [/code]

      Would the problem be solved if I Dim readprocess as Double ?

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by Evolution445
        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 ReadProcessMemo ry() 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.

        Comment

        • hariharanmca
          Top Contributor
          • Dec 2006
          • 1977

          #5
          I think this link will help you.

          Write/ReadProcessMemo ry errors of 487 and 299

          Comment

          • Evolution445
            New Member
            • Jul 2007
            • 63

            #6
            Originally posted by Killer42
            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 ReadProcessMemo ry() 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.
            ReadProcessMemo ry 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 ReadProcessMemo ry
            * If "......." is written Then
            * Respond using SendKeys
            ------------------

            This is where the error occured:
            [code=vb]
            If readprocess = Command Then
            SendKeys.Send(" {T}")
            Wait(100)
            SendKeys.Send(" There are " & votesneeded & " more votes needed to skip map.")
            Wait(100)
            SendKeys.Send(" {ENTER}")
            End If
            [/code]

            I'm not sure if I done this right. Infact, I'm not sure about whole my code.
            Any help is appreciated.

            Comment

            Working...