Read and Write Process Memory functions

In all windows system (I think from WindowsXP) there are funcions that allow to access, read and modify the memory of running processes. These functions are: ReadProcessMemory and WriteProcessMemory. First function allow to read bytes from an area of memory in a specified process. Second function allow to write bytes to an area of memory in a specified process. This two functions require Kernel32.lib to be declared and used.
The syntax of the two functions:

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

BOOL WINAPI WriteProcessMemory(
    __in HANDLE hProcess,
    __in LPVOID lpBaseAddress,
    __in LPCVOID lpBuffer,
    __in SIZE_T nSize,
    __out SIZE_T *lpNumberOfBytesWritten
);


Declarations of these functions are:

Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer
Public Declare Function ReadProcessMemory Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Integer, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, ByRef lpNumberOfBytesWritten As Integer) As Integer

* Note: there may be variations of these two declarations

These functions have to be applicated to a process and for this reason you need to use anothers functions to find and open process. In VB.net you can find process using the class 'Process'. You can get process by name and nextly get its 'ID'.
A small example may help:

Dim myProcesses As Process() = Process.GetProcessesByName("MyApplication")
Dim addr As Long = 0
If myProcesses.Length = 0 Then
    MsgBox("MyApplication isn't in execution.")
    Exit Sub
End If

Now you have attached your application and you can open the process. To open the process you need another function:

HANDLE WINAPI OpenProcess(
    __in DWORD dwDesiredAccess,
    __in BOOL bInheritHandle,
    __in DWORD dwProcessId
);


Declaration of OpenProcess:

Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer


Now we are ready to open process; below another smallest example:

processHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, myProcesses(0).Id)
If processHandle = IntPtr.Zero Then
    MsgBox("Unable to open the process.")
    Exit Sub
End If

* Note: PROCESS_ALL_ACCESS is a Const with value: &H1F0FFF
Now our process is open and ready to be read and written.
Example that explain both functions:

Dim RBuff As Long
Dim Address As Integer
Dim Value As Long
Dim Bytes As Integer
Address = &HAB0000
ReadProcessMemory(processHandle, Address, RBuff, 4, Nothing) ' Read 4 bytes and store in RBuff
Address = &HAD0101
Value = RBuff
WriteProcessMemory(processHandle, Address, Value, 4, Nothing) ' Write 4 bytes in another Address