Note that there are some explanatory texts on larger screens.

plurals
  1. POReadProcessMemory keeps returning 0
    primarykey
    data
    text
    <p>I'm currently developing a little hobby project to display health information in a game on my G15 keyboard through VB.NET.</p> <p>When I use ReadProcessMemory via an API call, it keeps returning zero. The MSDN documentation referred me to use the Marshal.GetLastWin32Error() call to find out what is wrong and it returns 1400: INVALID WINDOW HANDLE.</p> <p>I am now confused about whether the first argument of the function wants a window handle or a process id. Regardless, I have tried both with FindWindow and hardcoding the process id while the application is running (getting it from task manager).</p> <p>I have tried three different games, Urban Terror, Grand Theft Auto: SA and 3D pinball for windows, getting the memory addresses from an application called Cheat Engine; they all seem to fail.</p> <p>Here is the code I'm using to do it:</p> <p>API Call:</p> <pre><code>Private Declare Function ReadProcessMemory Lib "kernel32" ( _ ByVal hProcess As Integer, _ ByVal lpBaseAddress As Integer, _ ByRef lpBuffer As Single, _ ByVal nSize As Integer, _ ByRef lpNumberOfBytesWritten As Integer _ ) As Integer </code></pre> <p>Method:</p> <pre><code>Dim address As Integer address = &amp;HA90C62&amp; Dim valueinmemory As Integer Dim proc As Process = Process.GetCurrentProcess For Each proc In Process.GetProcesses If proc.MainWindowTitle = "3D Pinball for Windows - Space Cadet" Then If ReadProcessMemory(proc.Handle.ToInt32, address, valueinmemory, 4, 0) = 0 Then MsgBox("aww") Else MsgBox(CStr(valueinmemory)) End If End If Next Dim lastError As Integer lastError = Marshal.GetLastWin32Error() MessageBox.Show(CStr(lastError)) </code></pre> <p>Could somebody please explain to me why it is not working? Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload