天天看点

VB6.0超级模块函数.GetProcessModuleHandleByPid得到目标进程的模块地址-用PID

Public Function GetProcessModuleHandleByPid(ByVal GamePid As String, ByVal ModuleName As String) As Long
 
            Dim pr As PROCESSENTRY32
            Dim lp As Long
            Dim mo As MODULEENTRY32
            Dim LM As Long
            Dim i As Long
            Dim Temp As Variant
          '  If ModuleName = "" Then GetProcessModuleHandle = 0: Exit Function
            pr.dwSize = Len(pr)

            LM = CreateToolhelp32Snapshot(TH32CS_SNAPmodule, GamePid)
            If LM > 0 Then
            mo.dwSize = Len(mo)
            If Module32First(LM, mo) Then
            Do
            Temp = Left(mo.szExePath, InStr(mo.szExePath, Chr(0)) - 1)
            Temp = Mid(Temp, InStrRev(Temp, "\") + 1)
            If UCase(Temp) = UCase(ModuleName) Then
            GetProcessModuleHandleByPid = mo.modBaseAddr
            Exit Function
            End If
            i = i + 1
            Loop Until Module32Next(LM, mo) = 0
            End If
            CloseHandle (LM)
            End If
End Function
           

函数调用如下

假设某游戏的进程PID为890,那么我们要获取其模块Game.dll 这个模块的地址,代码如下

Dim a as long 

a = GetProcessModuleHandleByPid(890,"Game.dll ")

VB交流站 www.zai996.com  q1016058890

继续阅读