Click to Rate and Give Feedback
MSDN
MSDN Library
Diagnostics
Basic Debugging
Debugging Reference
Debugging Functions
 ReadProcessMemory Function
ReadProcessMemory Function

Reads data from an area of memory in a specified process. The entire area to be read must be accessible or the operation fails.

Syntax

C++
BOOL WINAPI ReadProcessMemory(
  __in   HANDLE hProcess,
  __in   LPCVOID lpBaseAddress,
  __out  LPVOID lpBuffer,
  __in   SIZE_T nSize,
  __out  SIZE_T *lpNumberOfBytesRead
);

Parameters

hProcess [in]

A handle to the process with memory that is being read. The handle must have PROCESS_VM_READ access to the process.

lpBaseAddress [in]

A pointer to the base address in the specified process from which to read. Before any data transfer occurs, the system verifies that all data in the base address and memory of the specified size is accessible for read access, and if it is not accessible the function fails.

lpBuffer [out]

A pointer to a buffer that receives the contents from the address space of the specified process.

nSize [in]

The number of bytes to be read from the specified process.

lpNumberOfBytesRead [out]

A pointer to a variable that receives the number of bytes transferred into the specified buffer. If lpNumberOfBytesRead is NULL, the parameter is ignored.

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is 0 (zero). To get extended error information, call GetLastError.

The function fails if the requested read operation crosses into an area of the process that is inaccessible.

Remarks

ReadProcessMemory copies the data in the specified address range from the address space of the specified process into the specified buffer of the current process. Any process that has a handle with PROCESS_VM_READ access can call the function.

The entire area to be read must be accessible, and if it is not accessible, the function fails.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll

See Also

Debugging Functions
Process Functions for Debugging
OpenProcess
VirtualAllocEx
WriteProcessMemory

 

 

Send comments about this topic to Microsoft

Build date: 1/22/2010

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
What about x86 and x64 compatibility?      AttilaSz   |   Edit   |   Show History
What happens, if I call this function from a 32 bit process to read from a 64 bit process? How can I pass a 64 bit pointer to it?
Re: What about x86 and x64 compatibility?      Wilczek   |   Edit   |   Show History

If you want to start a 64 bit app. from a 32 bit application for debugging (using DEBUG_PROCESS or DEBUG_ONLY_THIS_PROCESS flags) then the CreateProcess will fail and GetLastError() function will return code 50 ("The request is not supported."). If the debugger app. is a 64 bit app. and the debuggee app. is a 64 bit app. too then it will work (assuming you have the necessary rights).

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker