I try your function and dont works for me.
following that link
http://czepekpage.pl/index.php?page=threads&tid=21
I traduce function and make some changes to use in VB6.
that is the code.
Code:
Public Declare Function Module32First Lib "kernel32" (ByVal hSnapshot As Long, uProcess As MODULEENTRY32) As Long
Public Declare Function Module32Next Lib "kernel32" (ByVal hSnapshot As Long, uProcess As MODULEENTRY32) As Long
Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Public Const TH32CS_SNAPMODULE = &H8
Private Type MODULEENTRY32
dwSize As Long
th32ModuleID As Long
th32ProcessID As Long
GlblcntUsage As Long
ProccntUsage As Long
modBaseAddr As Long
modBaseSize As Long
hModule As Long
szModule As String * 256
szExePath As String * 260
End Type
Public Function ObtenerBase() As Long
Dim tibiaclient As Long
Dim pid As Long
Dim SnapShot As Long
Dim Base As Long
Dim ModuleEntry As MODULEENTRY32
Dim CurrentModule As Long
Base = 0
tibiaclient = FindWindow("tibiaclient", vbNullString)
GetWindowThreadProcessId tibiaclient, pid
If pid = 0 Then
ObtenerBase = Base
Exit Function
End If
SnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid)
ModuleEntry.dwSize = Len(ModuleEntry)
CurrentModule = Module32First(SnapShot, ModuleEntry)
If Right(Left(ModuleEntry.szModule, InStr(ModuleEntry.szModule, Chr(0)) - 1), 4) = ".exe" Then
Base = ModuleEntry.modBaseAddr
Else
Do While CurrentModule
If Right(Left(ModuleEntry.szModule, InStr(ModuleEntry.szModule, Chr(0)) - 1), 4) = ".exe" Then
Base = ModuleEntry.modBaseAddr
Exit Do
End If
CurrentModule = Module32Next(SnapShot, ModuleEntry)
Loop
End If
CloseHandle (SnapShot)
ObtenerBase = Base
End Function
Public Function PreparaMemoria(Memoria As Long) As Long
Dim Base As Long
Dim XPBase As Long
XPBase = &H400000
Base = ObtenerBase
If Base = 0 Then
Exit Function
End If
Memoria = Memoria + (Base - XPBase)
PreparaMemoria = Memoria
End Function
sorry for my bad english, i hope that function will be useful.