Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在vb.net中调用获取快照函数。如果有任何h-e-l-p,我将不胜感激_Vb.net - Fatal编程技术网

无法在vb.net中调用获取快照函数。如果有任何h-e-l-p,我将不胜感激

无法在vb.net中调用获取快照函数。如果有任何h-e-l-p,我将不胜感激,vb.net,Vb.net,我希望我的问题足够好。有些人说他们有时不是我有快照功能,但无法调用它。编译器说:由于其保护级别,函数未声明或my可能不可访问。。。这是我的函数 Private Function getShapshot(ByVal strModule As String) As Integer Dim strName As String = Empty.ToString Dim p() As Process = Process.GetProcessesByName(str

我希望我的问题足够好。有些人说他们有时不是我有快照功能,但无法调用它。编译器说:由于其保护级别,函数未声明或my可能不可访问。。。这是我的函数

   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
是进程名。所以我想我需要一些帮助。我们将不胜感激

`私有类myProcessEx
`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.
'内部枚举仅在内部使用 作为UInteger的私有枚举快照标志 HeapList=&H1 进程=&H2 线程=&H4 [模块]=&H8 模块32=&H10 继承=&H80000000UI 全部=&H1F无堆=&H40000000 结束枚举 '内部结构仅在内部使用 私有结构PROCESSENTRY32 常量最大路径为整数=260 友元DWSIZEAS UInt32 作为UInt32使用的朋友 友元th32ProcessID作为UInt32 Friend th32DefaultHeapID作为IntPtr 友元th32ModuleID As UInt32 友元线程作为UInt32 好友th32ParentProcessID作为UInt32 Friend pcPriClassBase作为Int32 友元标记为UInt32 以字符串形式显示文件 端部结构 将函数Module32First Lib“kernel32.dll”(ByVal hSnapshot作为Long,lppe作为MODULEENTRY32)声明为Long 私有声明函数module32下一个库“kernel32”(ByVal hSnapShot为Long,ByVal lpMe32为MODULEENTRY32)为Long 共享函数CreateToolhelp32Snapshot(dwFlags为UInt32,th32ProcessID为UInt32)作为IntPtr 端函数 作为整数的公共函数getShapshot(ByVal strModule作为字符串) Dim strName As String=Empty.ToString Dim p()作为Process=Process.getProcessByName(strName) 将hSnapshot作为IntPtr=CreateToolhelp32Snapshot(&H10,CUInt(p(0).Id))进行调整 如果hSnapshot=IntPtr.Zero,则不返回任何内容 Dim ME32模块作为新模块Entry32 me32Modules.U32Size=CUInt(Marshal.SizeOf(me32Modules)) 如果模块32第一个(hSnapshot、ME32模块),则 做 如果strModule=(me32Modules.U32Size),则返回me32Modules.HModule 循环时(模块32下一步(hSnapshot、me32模块)) 如果结束 一无所获 端函数 End Class`这是类代码,接下来是调用函数…`私有函数getShapshot(ByVal strModule作为字符串)作为整数 Dim strName As String=Empty.ToString Dim p()作为Process=Process.getProcessByName(strName) 将hSnapshot作为IntPtr=CreateToolhelp32Snapshot(&H10,CUInt(p(0).Id))进行调整 如果hSnapshot=IntPtr.Zero,则不返回任何内容 Dim ME32模块作为新模块Entry32 me32Modules.U32Size=CUInt(Marshal.SizeOf(me32Modules)) 如果模块32第一个(hSnapshot、ME32模块),则 做 如果strModule=(me32Modules.U32Size),则返回me32Modules.HModule 循环时(模块32下一步(hSnapshot、me32模块)) 如果结束 一无所获 端函数 End Class`调用代码`私有函数getShapshot(ByVal strModule作为字符串)作为整数 Dim strName As String=Empty.ToString Dim p()作为Process=Process.getProcessByName(strName) 将hSnapshot作为IntPtr=CreateToolhelp32Snapshot(&H10,CUInt(p(0).Id))进行调整 如果hSnapshot=IntPtr.Zero,则不返回任何内容 Dim ME32模块作为新模块Entry32 me32Modules.U32Size=CUInt(Marshal.SizeOf(me32Modules)) 如果模块32第一个(hSnapshot、ME32模块),则 做 如果strModule=(me32Modules.U32Size),则返回me32Modules.HModule 循环时(模块32下一步(hSnapshot、me32模块)) 如果结束 一无所获 端函数 这会让你对正在发生的事情有一个更好的了解。
您是从其他类调用它吗?如果是这样,请删除方法声明中的“Private”关键字。不,我不是从另一个类调用它。我试着公开这个功能,但没有成功。谢谢你的帮助。另外,谢谢你帮我修改帖子(我猜是你修改的)。我无法获取代码块中的第一行代码。请向我们展示包含执行调用的方法和正在调用的方法的类。我必须将代码放入答案中,因为注释不允许代码有足够的空间…我找到了解决问题的方法。我把所有的代码放在一个模块中,现在它可以工作了。谢谢你们的帮助。我真的很感激。只在内联代码周围使用反引号。对于其他的格式,只需将所有内容放在新行并缩进4。此外,请不要将所有内容都放在模块中。。。它只是让一切变得全球化,并不是很好的OOP实践。最好解决你的实际问题。我仍然在这里查看您的代码,您有3个(几乎)相同的
getShapshot
函数(一个公共函数和两个私有函数),我们仍然看不到从何处调用它。你的类也是私有的,所以你是说你把类变成了一个模块?“你是不是先把它公之于众了?”蒙蒂,我道歉。我没有看到你的最后2条评论。感谢您提供有关添加代码的提示。此外,你在模块中塞满东西的想法是对的。这不是好的做法。我想我总是把模块看作是其他项目的工具箱。感谢所有的帮助…这就是dll的作用:)