|
-
Jul 19th, 2004, 11:04 AM
#1
Thread Starter
New Member
Toolhelp32 API
I am using VB.NET 2003 and need to do the following:
Find the Base Address of a .dll file using Toolhelp32 API (Module32First/Next Calls). Of course, before doing that I need to get the ProcessID of the .exe that is using that .dll file and do a CreateToolhelp32Snapshot() Call.
So, what code whould I need to perform the above? I assume it would be a Module that I would add and then add the commands to a Form?
Thanks in advance!
P.S. I am a total Noob, so please be nice.
-
Jul 20th, 2004, 11:49 AM
#2
Registered User
Re: Toolhelp32 API
i have write in vb6 some times ago.maybe it will be some of the use.
Private Function ListProcess() As Long
On Error GoTo ListErr
ListProcess = 0
Dim lngIndex As Long
Dim strExe As String
Dim lngHSnapShot As Long
Dim upenProcess As PROCESSENTRY32
lngIndex = 1
ReDim uPenInfo(1 To 1)
lstProcess.Clear
lngHSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If lngHSnapShot = -1 Then
ListProcess = 2
Exit Function
End If
upenProcess.dwSize = Len(upenProcess)
lngAPIReturn = Process32First(lngHSnapShot, upenProcess)
If lngAPIReturn = 0 Or lngAPIReturn = ERROR_NO_MORE_FILES Then
lngAPIReturn = CloseHandle(lngHSnapShot)
ListProcess = 3
Exit Function
End If
Do
uPenInfo(lngIndex).cntThreads = upenProcess.cntThreads
uPenInfo(lngIndex).cntUsage = upenProcess.cntUsage
uPenInfo(lngIndex).dwFlags = upenProcess.dwFlags
uPenInfo(lngIndex).dwSize = upenProcess.dwSize
uPenInfo(lngIndex).pcPriClassBase = upenProcess.pcPriClassBase
uPenInfo(lngIndex).szExeFile = upenProcess.szExeFile
uPenInfo(lngIndex).th32DefaultHeapID = upenProcess.th32DefaultHeapID
uPenInfo(lngIndex).th32ModuleID = upenProcess.th32ModuleID
uPenInfo(lngIndex).th32ParentProcessID = upenProcess.th32ParentProcessID
uPenInfo(lngIndex).th32ProcessID = upenProcess.th32ProcessID
If InStr(uPenInfo(lngIndex).szExeFile, Chr(0)) > 1 Then
strExe = ""
If tWindowsVersion.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then
strExe = Left(uPenInfo(lngIndex).szExeFile, InStr(uPenInfo(lngIndex).szExeFile, Chr(0)) - 1)
If InStrRev(strExe, "\") > 0 Then
strExe = Right(strExe, Len(strExe) - InStrRev(strExe, "\"))
End If
ElseIf tWindowsVersion.dwPlatformId = VER_PLATFORM_WIN32_NT Then
strExe = Left(uPenInfo(lngIndex).szExeFile, InStr(uPenInfo(lngIndex).szExeFile, Chr(0)) - 1)
End If
End If
lstProcess.AddItem strExe, lngIndex - 1
ReDim Preserve uPenInfo(1 To UBound(uPenInfo) + 1)
lngIndex = lngIndex + 1
upenProcess.szExeFile = Space(MAX_PATH)
lngAPIReturn = Process32Next(lngHSnapShot, upenProcess)
Loop While (lngAPIReturn <> 0 And lngAPIReturn <> ERROR_NO_MORE_FILES)
lngAPIReturn = CloseHandle(lngHSnapShot)
If UBound(uPenInfo) > 0 Then
lstProcess.ListIndex = 0
End If
Exit Function
ListErr:
ListProcess = 1
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|