Im not using a module, just some delcarations at the top, and a couple of subs:
Declarations:
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function CloseWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
Private Declare Function ReadProcessMem Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
SUBS:
Sub WriteAInt(Address As Long, Value As Integer)
Dim hwnd As Long, pid As Long, pHandle As Long
hwnd = FindWindow(vbNullString, "Live For Speed")
If (hwnd <> 0) Then
GetWindowThreadProcessId hwnd, pid
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (pHandle <> 0) Then
WriteProcessMemory pHandle, Address, Value, 1, 0&
End If
CloseHandle pHandle
End If
End Sub
Sub WriteAIntSINGLE(Address As Long, Value As Single)
Dim hwnd As Long, pid As Long, pHandle As Long
hwnd = FindWindow(vbNullString, "Live For Speed")
If (hwnd <> 0) Then
GetWindowThreadProcessId hwnd, pid
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (pHandle <> 0) Then
WriteProcessMemory pHandle, Address, Value, 4, 0&
End If
CloseHandle pHandle
End If
End Sub
then all I do is call the sub when I need something written:
Call WriteAIntSINGLE(GTRimWidthRearAddress, 0.1905)
Call WriteAInt(CarType1MinCylAddress, &H1)
(Really it doesnt matter if I push hex, or an integer, they both work)
BTW, I havent worked with my code in a LOOOONG time, and am stale....
However it appears my WriteAIntSINGLE sub writes 4 bytes, as my WriteAInt only writes 1