###User Defined Function###
_MemoryWrite

###Description###
Writes data to a specified memory address.

###Syntax###
_MemoryWrite($iv_Address, $ah_Handle, $v_Data[, $sv_Type])

###Parameters###
@@ParamTable@@
$iv_Address
	The memory address to write to in hex format (0x00000000).
$ah_Handle
	An array containing the Dll handle and the handle of the open process as returned by _MemoryOpen.
$v_Data
	The data to be written.
$sv_Type
	The "Type" of value to write.  This is set to 'dword' by default.
@@End@@

###ReturnValue###
@@ReturnTable@@
Success:	1.
Failure:	0.
@Error:		0 = No error.
		1 = Invalid $ah_Handle.
		2 = $sv_Type was not a string.
		3 = $sv_Type is an unknown data type.
		4 = Failed to allocate the memory needed for the DllStructure.
		5 = Error allocating memory for $sv_Type.
		6 = $v_Data is not in the proper format to be used with the "Type" selected for $sv_Type, or it is out of range.
		7 = Failed to write to the specified process.
@@End@@


###Remarks###
If the "Type" is of the 'char' type, the data to be written should be in ASCII format, otherwise the data to be written should be in Decimal format.  Also, the size ('char[size]') for all 'char' types should be 1 greater than the actual size.

For help on creating "Types", see DllStructCreate.


###Related###
_MemoryOpen, _MemoryClose, _MemoryWrite, _MemoryPointerRead, _MemoryPointerWrite


###Example###
@@IncludeExample@@
;This example creates a sample GUI and shows how to use _MemoryRead
;and _MemoryWrite to read and write to the GUI's memory data.
#include <Memory.au3>

;create the sample GUI
GUICreate("Sample GUI", 170, 85)
GUICtrlCreateLabel('Press "Read" to read the data from memory, or "Write" to write the data to memory.', 5, 5, 160, 55)
$ReadMemory = GUICtrlCreateButton("Read", 5, 60, 50, 20)
$WriteMemory = GUICtrlCreateButton("Write", 60, 60, 50, 20)
$CloseGUI = GUICtrlCreateButton("Close", 115, 60, 50, 20)
GUISetState()

;data to read/write
$DecimalRead = 987654321
$DecimalWrite = 123456789
$ASCIIRead = 'Going Out'
$ASCIIWrite = 'Coming In'

$ProcessID = WinGetProcess("Sample GUI")

While(1)
Sleep(50)
$msg = GUIGetMsg()
Select
	Case $msg = $ReadMemory
		;open the process
		$ProcessInformation = _MemoryOpen($ProcessID)
		
		;read the memory
		$Number = _MemoryRead(0xF13CD8, $ProcessInformation)
		$Text = _MemoryRead(0xF13350, $ProcessInformation, 'char[10]')
		
		;close the process
		_MemoryClose($ProcessInformation)
		
		MsgBox(4096, "Data Read", $Number & @CRLF & $Text)
		
	Case $msg = $WriteMemory
		;open the process
		$ProcessInformation = _MemoryOpen($ProcessID)
		
		;write the memory
		_MemoryWrite(0xF13CD8, $ProcessInformation, $DecimalWrite)
		_MemoryWrite(0xF13350, $ProcessInformation, $ASCIIWrite, 'char[10]')
		
		;read the memory
		$Number = _MemoryRead(0xF13CD8, $ProcessInformation)
		$Text = _MemoryRead(0xF13350, $ProcessInformation, 'char[10]')
		
		;close the process
		_MemoryClose($ProcessInformation)
		
		;reset data to be written
		If $Number = 123456789 Then
			$DecimalWrite = 987654321
		Else
			$DecimalWrite = 123456789
		EndIf
		
		If $Text = 'Coming In' Then
			$ASCIIWrite = 'Going Out'
		Else
			$ASCIIWrite = 'Coming In'
		EndIf
		
	Case $msg = $CloseGUI
		Exit
EndSelect
WEnd
@@End@@