I am trying to get value from memory. Memory's address is 1AD98845170. This area contains 'd' letter, so it's value is 64. I got this information from Cheat Engine. But in my C# application I am using ReadProcessMemory to get this value. When I am running code it's failing with the exception.The exception is System.AccessViolationException. I have no idea about solving this problem and I can't find any information about this problem. Thanks for your attention.
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory(IntPtr hProcess, Int64 lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);
public void button_Click(object sender, EventArgs e)
{
Process process = Process.GetProcessesByName("notepad")[0];
IntPtr processHandle = OpenProcess(0x0010, false, process.Id);
int bytesRead = 0;
byte[] buffer = new byte[12];
ReadProcessMemory(processHandle, 0x1AD98845170, buffer, buffer.Length, ref bytesRead); // problem is here
string res = Encoding.Unicode.GetString(buffer) + " (" + bytesRead.ToString() + "bytes)";
textBox.Text = res.ToString();
}