我希望我的问题足够好。有些人说他们有时候不会。 :)我有我的SnapShot功能,但我无法调用它。编译说:由于其保护级别,函数未声明或我无法访问...这是我的功能......
Private Function getShapshot(ByVal strModule As String) As Integer
Dim strName As String = Empty.ToString
Dim p() As Process = Process.GetProcessesByName(strName)
Dim hSnapshot As IntPtr = CreateToolhelp32Snapshot(&H10, CUInt(p(0).Id))
If hSnapshot = IntPtr.Zero Then Return Nothing
Dim me32Modules As New MODULEENTRY32
me32Modules.U32Size = CUInt(Marshal.SizeOf(me32Modules))
If Module32First(hSnapshot, me32Modules) Then
Do
If strModule = (me32Modules.U32Size) Then Return me32Modules.HModule
Loop While (Module32Next(hSnapshot, me32Modules))
End If
Return Nothing
End Function
可能是我的函数调用:getShapshot(strName)
其中strName
是进程名称。所以我想我需要一些帮助。非常感谢!
答案 0 :(得分:0)
`Private Class myProcessEx
'inner enum used only internally
<Flags>
Private Enum SnapshotFlags As UInteger
HeapList = &H1
Process = &H2
Thread = &H4
[Module] = &H8
Module32 = &H10
Inherit = &H80000000UI
All = &H1F NoHeaps = &H40000000
End Enum
'inner struct used only internally
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)>
Private Structure PROCESSENTRY32
Const MAX_PATH As Integer = 260
Friend dwSize As UInt32
Friend cntUsage As UInt32
Friend th32ProcessID As UInt32
Friend th32DefaultHeapID As IntPtr
Friend th32ModuleID As UInt32
Friend cntThreads As UInt32
Friend th32ParentProcessID As UInt32
Friend pcPriClassBase As Int32
Friend dwFlags As UInt32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_PATH)>
Friend szExeFile As String
End Structure
Declare Function Module32First Lib "kernel32.dll" (ByVal hSnapshot As Long, lppe As MODULEENTRY32) As Long
Private Declare Function Module32Next Lib "kernel32" (ByVal hSnapShot As Long, ByVal lpMe32 As MODULEENTRY32) As Long
<DllImport("kernel32", SetLastError:=True, CharSet:=System.Runtime.InteropServices.CharSet.Auto)>
Shared Function CreateToolhelp32Snapshot(<[In]> dwFlags As UInt32, <[In]> th32ProcessID As UInt32) As IntPtr
End Function
Public Function getShapshot(ByVal strModule As String) As Integer
Dim strName As String = Empty.ToString
Dim p() As Process = Process.GetProcessesByName(strName)
Dim hSnapshot As IntPtr = CreateToolhelp32Snapshot(&H10, CUInt(p(0).Id))
If hSnapshot = IntPtr.Zero Then Return Nothing
Dim me32Modules As New MODULEENTRY32
me32Modules.U32Size = CUInt(Marshal.SizeOf(me32Modules))
If Module32First(hSnapshot, me32Modules) Then
Do
If strModule = (me32Modules.U32Size) Then Return me32Modules.HModule
Loop While (Module32Next(hSnapshot, me32Modules))
End If
Return Nothing
End Function
End Class` This is the class code, next comes the calling function... ` Private Function getShapshot(ByVal strModule As String) As Integer
Dim strName As String = Empty.ToString
Dim p() As Process = Process.GetProcessesByName(strName)
Dim hSnapshot As IntPtr = CreateToolhelp32Snapshot(&H10, CUInt(p(0).Id))
If hSnapshot = IntPtr.Zero Then Return Nothing
Dim me32Modules As New MODULEENTRY32
me32Modules.U32Size = CUInt(Marshal.SizeOf(me32Modules))
If Module32First(hSnapshot, me32Modules) Then
Do
If strModule = (me32Modules.U32Size) Then Return me32Modules.HModule
Loop While (Module32Next(hSnapshot, me32Modules))
End If
Return Nothing
End Function
End Class` calling code.. `Private Function getShapshot(ByVal strModule As String) As Integer
Dim strName As String = Empty.ToString
Dim p() As Process = Process.GetProcessesByName(strName)
Dim hSnapshot As IntPtr = CreateToolhelp32Snapshot(&H10, CUInt(p(0).Id))
If hSnapshot = IntPtr.Zero Then Return Nothing
Dim me32Modules As New MODULEENTRY32
me32Modules.U32Size = CUInt(Marshal.SizeOf(me32Modules))
If Module32First(hSnapshot, me32Modules) Then
Do
If strModule = (me32Modules.U32Size) Then Return me32Modules.HModule
Loop While (Module32Next(hSnapshot, me32Modules))
End If
Return Nothing
End Function
End Class` this should give you a better idea of what is going on.