I want to find out all dll's a process have. I've found example code on
the page http://www.freevbcode.com/ShowCode.asp?ID=295
The problem is, the sample is written in vb6, but Application is written
in vb.NET.
I've rewritten the code for vb.net, but if I run the application, there
is following runtime error message
System.NullRefe renceException: Object reference not set to an instance
of an object.
at SSAM_Sesam_AddI n.Sesam.Module3 2First(Int64 hSnapShot,
MODULEENTRY32 lpMe32)
I don't know which object is meant, because both objects (hSnapShot,
lpMe32) aren't Null.
Thank you very much for your help.
Jan Jeitziner
My Code
......
'<DECLARATION>
Private Const TH32CS_SNAPMODU LE = &H8
Private Structure MODULEENTRY32
Dim dwSize As Long
Dim th32ModuleID As Long
Dim th32ProcessID As Long
Dim GlblcntUsage As Long
Dim ProccntUsage As Long
Dim modBaseAddr As Long
Dim modBaseSize As Long
Dim hModule As Long
Dim szModule As String
Dim szExePath As String
End Structure
Private Declare Function CreateToolhelpS napshot Lib "kernel32" _
Alias "CreateToolhelp 32Snapshot" _
(ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Module32First Lib "kernel32" _
(ByVal hSnapShot As Long, ByVal lpMe32 As MODULEENTRY32) As Long
Private Declare Function Module32Next Lib "kernel32" _
(ByVal hSnapShot As Long, ByVal lpMe32 As MODULEENTRY32) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Private Declare Function RtlMoveMemory Lib "kernel32" _
(ByVal pDest As Long, ByVal pSource As Long, ByVal ByteLen As Long) As
Long
Private Declare Function GetCurrentProce ssId Lib "kernel32" () As Long
....
'<CODE>
Public Shared Function ListDLL()
Dim Me32 As MODULEENTRY32
Dim lRet As Long
Dim lhSnapShot As Int64
Dim pID As Long
Dim iLen As Integer
Dim sModule As String
pID = GetCurrentProce ssId()
Debug.WriteLine (pID.ToString)
lhSnapShot = CreateToolhelpS napshot(TH32CS_ SNAPMODULE, CLng(pID))
Me32.dwSize = Len(Me32)
lRet = Module32First(l hSnapShot, Me32)
Do While lRet
Try
If Me32.th32Proces sID = CLng(pID) Then
With Me32
iLen = InStr(.szExePat h, Chr(0))
If iLen = 0 Then
sModule = CStr(.szExePath )
Else
sModule = Left(.szExePath , iLen - 1)
End If
Debug.WriteLine (sModule.ToStri ng)
End With
End If
lRet = Module32Next(lh SnapShot, Me32)
Loop
CloseHandle(lhS napShot)
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try
End Function
the page http://www.freevbcode.com/ShowCode.asp?ID=295
The problem is, the sample is written in vb6, but Application is written
in vb.NET.
I've rewritten the code for vb.net, but if I run the application, there
is following runtime error message
System.NullRefe renceException: Object reference not set to an instance
of an object.
at SSAM_Sesam_AddI n.Sesam.Module3 2First(Int64 hSnapShot,
MODULEENTRY32 lpMe32)
I don't know which object is meant, because both objects (hSnapShot,
lpMe32) aren't Null.
Thank you very much for your help.
Jan Jeitziner
My Code
......
'<DECLARATION>
Private Const TH32CS_SNAPMODU LE = &H8
Private Structure MODULEENTRY32
Dim dwSize As Long
Dim th32ModuleID As Long
Dim th32ProcessID As Long
Dim GlblcntUsage As Long
Dim ProccntUsage As Long
Dim modBaseAddr As Long
Dim modBaseSize As Long
Dim hModule As Long
Dim szModule As String
Dim szExePath As String
End Structure
Private Declare Function CreateToolhelpS napshot Lib "kernel32" _
Alias "CreateToolhelp 32Snapshot" _
(ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Module32First Lib "kernel32" _
(ByVal hSnapShot As Long, ByVal lpMe32 As MODULEENTRY32) As Long
Private Declare Function Module32Next Lib "kernel32" _
(ByVal hSnapShot As Long, ByVal lpMe32 As MODULEENTRY32) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Private Declare Function RtlMoveMemory Lib "kernel32" _
(ByVal pDest As Long, ByVal pSource As Long, ByVal ByteLen As Long) As
Long
Private Declare Function GetCurrentProce ssId Lib "kernel32" () As Long
....
'<CODE>
Public Shared Function ListDLL()
Dim Me32 As MODULEENTRY32
Dim lRet As Long
Dim lhSnapShot As Int64
Dim pID As Long
Dim iLen As Integer
Dim sModule As String
pID = GetCurrentProce ssId()
Debug.WriteLine (pID.ToString)
lhSnapShot = CreateToolhelpS napshot(TH32CS_ SNAPMODULE, CLng(pID))
Me32.dwSize = Len(Me32)
lRet = Module32First(l hSnapShot, Me32)
Do While lRet
Try
If Me32.th32Proces sID = CLng(pID) Then
With Me32
iLen = InStr(.szExePat h, Chr(0))
If iLen = 0 Then
sModule = CStr(.szExePath )
Else
sModule = Left(.szExePath , iLen - 1)
End If
Debug.WriteLine (sModule.ToStri ng)
End With
End If
lRet = Module32Next(lh SnapShot, Me32)
Loop
CloseHandle(lhS napShot)
Catch ex As Exception
Debug.WriteLine (ex.ToString)
End Try
End Function
Comment