###User Defined Function###
_MemoryOpen

###Description###
Opens a process and sets the access rights for the process.  The Process ID of the process is used to specify which process to access.  You must call this function before calling any of the other _Memory functions.

###Syntax###
_MemoryOpen($iv_Pid, [$iv_DesiredAccess[, $if_InheritHandle]])

###Parameters###
@@ParamTable@@
$iv_Pid
	The process ID of the process to open.
$iv_DesiredAccess
	This is the access rights handle used by OpenProcess.  The default setting enables all possible access rights for the process specified by $iv_Pid.
$if_InheritHandle
	If this value is TRUE, processes created by the process whose process ID was set as $iv_Pid will inherit the $iv_DesiredAccess handle. Otherwise, the processes do not inherit the handle.  The value is TRUE (1) by default.
@@End@@

###ReturnValue###
@@ReturnTable@@
Success:	An array containing the Dll handle and an open handle to the specified process.
Failure:	0.
@Error:		0 = No error.
		1 = Invalid $iv_Pid.
		2 = Failed to open Kernel32.dll.
		3 = Failed to open the specified process.
@@End@@


###Remarks###
	The optional parameter $iv_DesiredAccess is set to 0x1F0FFF by default.  This setting enables all possible access rights to the specified process.  There should be no need to change this value unless limited access to the specified process is desired.

	The optional parameter $if_InheritHandle is set to TRUE (1) by default.  This setting allows all processes created by the process whose process ID was set as $iv_Pid to inherit the $iv_DesiredAccess handle.  Changing this value is not recommended.
	If, for example, the address to be read is being accessed by a Dll created specifically for the specified process, and this Dll requires the $iv_DesiredAccess handle to allow memory access, and $if_InheritHandle is set to FALSE (0), the access to the memory address will be denied and will not be open for reading or writing since the Dll will not inherit the $iv_DesiredAccess handle.


###Related###
_MemoryClose, _MemoryRead, _MemoryWrite, _MemoryPointerRead, _MemoryPointerWrite


###Example###
@@IncludeExample@@
;This example creates a sample GUI and shows how to use _MemoryOpen
;and _MemoryClose to open and close access to it's memory data.
#include <Memory.au3>

;create a sample GUI 
GUICreate("Sample", 160, 80)
GUICtrlCreateLabel("Dll Handle = ", 5, 5)
GUICtrlCreateLabel("Open Process Handle = ", 5, 25)
$CloseGUI = GUICtrlCreateButton("Close", 55, 55, 50, 20)
GUISetState()

;get the process ID of the process
$ProcessID = WinGetProcess("Sample")

;obtain the Dll handle, the process handle, and enable memory access
$ProcessInformation = _MemoryOpen($ProcessID)

GUICtrlCreateLabel($ProcessInformation[0], 70, 5) ; Open process handle
GUICtrlCreateLabel($ProcessInformation[1], 125, 25) ; Dll handle

;close the process handle and disable memory access
_MemoryClose($ProcessInformation)

While(1)
	Sleep(50)
	$msg = GUIGetMsg()
	If $msg = $CloseGUI Then Exit
WEnd
@@End@@