Kernel32WriteProcessMemory(IntPtr, UIntPtr, IntPtr, IntPtr, IntPtr) Method

Writes data to an area of memory in a specified process.

The entire area to be written to must be accessible or the operation fails.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("Kernel32.dll", ExactSpelling = true, SetLastError = true)]
public static bool WriteProcessMemory(
	IntPtr hProcess,
	UIntPtr baseAddress,
	IntPtr buffer,
	IntPtr size,
	out IntPtr refNumberOfBytesWritten
)

Parameters

hProcess  IntPtr
A handle to the process memory to be modified.

The handle must have VirtualMemoryWrite and VirtualMemoryOperation access to the process.

baseAddress  UIntPtr
A pointer to the base address in the specified process to which data is written.

Before data transfer occurs, the system verifies that all data in the base address and memory of the specified size is accessible for write access, and if it is not accessible, the function fails.

buffer  IntPtr
A pointer to the buffer that contains data to be written in the address space of the specified process.
size  IntPtr
The number of bytes to be written to the specified process.
refNumberOfBytesWritten  IntPtr
A pointer to a variable that receives the number of bytes transferred into the specified process.

This parameter is optional.

If refNumberOfBytesWritten is Zero, the parameter is ignored.

Return Value

Boolean
If the function succeeds, the return value is .

If the function fails, the return value is .

To get extended error information, call GetLastWin32Error.

Remarks

See Also