无法在vb.net中调用get 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是进程名。所以我想我需要一些帮助。我将不胜感激!

`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.

相关内容

最新更新