为什么ReadProcessMemory总是返回false?

时间:2018-08-13 19:27:06

标签: c#

不知道为什么,但是对于某些ReadProcessMemory总是返回false。总是这样导入它:

[DefaultDllImportSearchPaths(Kernel32.Path)]
[DllImport(Kernel32.Dll)]
private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int nSize, IntPtr lpNumberOfBytesRead);

这是运行ReadProcessMemory(IntPtr HandleWithAllAccess, IntPtr ProcessBaseAddress, byte[] BufferSizeOf500, int TheSize500, IntPtr.Zero);

的结果

https://preview.ibb.co/eK8189/Screenshot_890.png

Note: just so people don't start asking unrelated questions, Kernel32 is a class with the dll name and the path where to find it

1 个答案:

答案 0 :(得分:0)

读取操作进入进程的不可访问区域,这就是为什么它返回false的原因。感谢Jeroen Mostert链接了文档,从现在开始我将SetLastError设置为true。