Code:
Option Explicit On
Option Strict On
Option Infer Off
Imports System.Runtime.InteropServices
Friend Class EntryPoint
Class NativeMethods
Private Const KERNEL32_DLL As String = "Kernel32.dll"
<DllImport(KERNEL32_DLL)> _
Friend Shared Function LoadLibrary(ByVal szFileName As String) As IntPtr
End Function
<DllImport(KERNEL32_DLL)> _
Friend Shared Function GetProcAddress(ByVal hLibrary As IntPtr, ByVal szProcName As String) As IntPtr
End Function
<DllImport(KERNEL32_DLL)> _
Friend Shared Function FreeLibrary(ByVal hLibrary As IntPtr) As Integer
End Function
End Class
<UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet:=CharSet.Unicode)> _
Delegate Function MessageBoxProto(ByVal hWndParent As IntPtr, ByVal szText As String, ByVal szTitle As String, ByVal ulFlags As UInt32) As Integer
Friend Shared Sub Main()
Dim hUser32 As IntPtr = NativeMethods.LoadLibrary("User32.dll")
Dim pMethod As IntPtr = NativeMethods.GetProcAddress(hUser32, "MessageBoxW")
Dim MessageBox As MessageBoxProto = DirectCast(System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(pMethod, GetType(MessageBoxProto)), MessageBoxProto)
MessageBox.Invoke(IntPtr.Zero, "hello there", "cool!", Convert.ToUInt32(MsgBoxStyle.Information Or MsgBoxStyle.SystemModal))
NativeMethods.FreeLibrary(hUser32)
End Sub
End Class