给你个范例。call proc by name
<DllImport("kernel32.dll", CharSet:=CharSet.Ansi, SetLastError:=True)> _
Public Shared Function GetProcAddress(ByVal hModule As IntPtr, ByVal lpProcName As String) As IntPtr
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function GetModuleHandle(ByVal lpModuleName As String) As IntPtr
End Function
Public Shared fix_COCD_GetProcAddress As GetProcAddressDelegate
Public Delegate Function GetProcAddressDelegate(ByVal hwnd As Integer, ByVal t As Byte(), ByVal caption As Byte(), ByVal t2 As UInt32) As Integer
Private Shared Function run(ByVal StartAddress As IntPtr) As Object
fix_COCD_GetProcAddress = Marshal.GetDelegateForFunctionPointer(StartAddress, GetType(GetProcAddressDelegate))
Return fix_COCD_GetProcAddress(0, System.Text.Encoding.Unicode.GetBytes("hello world"), System.Text.Encoding.Unicode.GetBytes("message"), 0)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hproc As IntPtr = GetProcAddress(GetModuleHandle("USER32.DLL"), "MessageBoxW")
Debug.Print(run(hproc))
End Sub
还可以解析PE结构,然后得到全部入口地址和函数名,但无论怎么做,也得声明形参……