VBiB/ACCB.net - Visual Basic in België | .net Ineta User Group  
(login to hide)
Hoofdmenu

Advertenties

Het Computer Winkeltje HCW


Evenementen

Tips en tricks
U bevindt zich > Tips en Tricks > VB .net > Windows > Processen > Dynamisch aanroepen van unmanaged libraries
Ik wil een tip ingeven

Tip: Dynamisch aanroepen van unmanaged libraries
Vozzie - 08 Jan 2010 - 06:22

 

 

 

 

 

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



2956 x gelezen

Commentaar
U dient ingelogd te zijn om commentaar te posten.
 

Er zijn in totaal 102 tips gepost.

 

 
Postnuke - ADODB Database - PHP 4/5 - pnPhpBB2 - Hosting bij Openminds
Met dank aan Jürgen voor de jarenlange inzet van visualbasic.be (anno 21-12-2000)
vbib.be gestart op 1/03/06 (extra vanaf 1/09: vbnet.be en vbdotnet.be)
VBiB is gerelateerd met wintips.be

Nieuwsbrief RSS Feed: backend.php