2016-03-30 40 views
0

私はいくつかのwinapiメソッドを使用しようとしています。どのようにこれまでに、私は次のエラーを取得する機能を使用しようとすると:'System.Runtime.InteropServices.DllImportAttribute'はインスタンスメソッドに適用できません

'System.Runtime.InteropServices.DllImportAttribute' cannot be applied to instance method. code:

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

'Shared Function ....'、コード解析をうまく使用したい場合は、クラス名を 'NativeMethods'に変更してください – Plutonix

答えて

1

まあが、メッセージは非常に明確です。 DllImport属性を適用するメソッドは、クラスメソッド(shared)でなければなりません。

関連する問題