' System.Runtime.InteropServices.DllImportAttribute'不能应用于实例方法

时间:2016-03-30 18:49:33

标签: vb.net

我试图使用一些winapi方法。但是,当我尝试使用该功能时,我收到以下错误:

  

' System.Runtime.InteropServices.DllImportAttribute'不能应用于实例方法。   代码:

Public Class Anti
        <DllImport("kernel32.dll", SetLastError:=True)> _
    Public Function ReadProcessMemory(ByVal hProcess As IntPtr, ByVal lpBaseAdress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Integer, Optional ByRef lpNumberOfBytesRead As Integer = 0) As Boolean
    End Function
    <DllImport("kernel32.dll", SetLastError:=True)> _
    Public Sub ZeroMemory(ByVal handle As IntPtr, ByVal length As UInt32)
    End Sub
    <DllImport("kernel32.dll", SetLastError:=True)> _
    Public Function VirtualProtect(ByVal lpAddress As IntPtr, ByVal dwSize As Integer, ByVal flNewProtect As Integer, ByRef lpflOldProtect As UInteger) As Boolean
    End Function
    Public Sub AntiDump()
      Try
      Dim x(0) As Process

1 个答案:

答案 0 :(得分:1)

嗯,信息很清楚。应用DllImport属性的方法必须是类方法(shared)。