When I want to use the variable I defined with its memory address, it's ok. When I want to read it using memoryread api in windows, the result fails. Where am I going wrong or what should I do? I would be glad if you share your ideas and suggestions. Respects.Handle in your example refers to the form's window handle. You need to pass the handle off the process to ReadProcessMemory:
Will that work with stack allocations? Simple local variables are allocated on the stack, not the heap!It will work with stack allocations or any other memory block as long as the process that attempts to read it has the right to read the location and, of course, there actually is memory there. As long as those two conditions are true the read will succeed.
Process memory is heap...
So you must read it inside a method or procedure, otherwise the stack allocations go out of scope / is released on exit?What you said is remarkable, and thank you very much for your warning.
So you must read it inside a method or procedure, otherwise the stack allocations go out of scope / is released on exit?The lifetime of the values read that way varies significantly in just about all cases. What you pointed out is right, reading local variables, the memory will still be accessible after the function/procedure returns (the stack memory isn't released back to the O/S when a function/procedure returns) but, the contents of those locations will vary in unpredictable ways.