Tipp 4.12 - Ist Funktion in DLL vorhanden
Wie kann ich prüfen, ob in einer DLL eine bestimmte Funktion vorkommt?
Mit dieser Funktion können Sie prüfen, ob in einer DLL eine bestimmte Funktion vorkommt. Kopieren Sie einfach nachfolgenden Quellcode in die Zwischenablage und fügen Sie anschließend den Inhalt der Zwischenablage in ein neues Modul ein. Die Aufrufparameter finden Sie im Quellcode beschrieben.
Verwendete Win32-Api-Aufrufe und Typen: LoadLibrary, GetProcAddress, FreeLibrary
Beispiel:
Option Explicit Declare Function LoadLibrary Lib "kernel32" Alias _ "LoadLibraryA" _ (ByVal lpLibFileName As String) As Long Declare Function GetProcAddress Lib "kernel32" _ (ByVal hModule As Long, _ ByVal lpProcName As String) As Long Declare Function FreeLibrary Lib "kernel32" _ (ByVal hLibModule As Long) As Long Function FunctionPresent(ByVal sDllName As String, _ ByVal sFunctionName As String) As Boolean '// ----------------------------------------------------- '// Methode: | Prüfen, ob in einer DLL eine bestimmte '// | Funktion vorhanden ist '// ----------------------------------------------------- '// Parameter: | sDllName - Name der DLL '// | sFunctionName - Name der Funktion '// ----------------------------------------------------- '// Beispielausruf: '// ?FunctionPresent("kernel32.dll", "FreeLibrary") '// ----------------------------------------------------- '// Rückgabe: | True, bei erfolgreicher Suche '// ----------------------------------------------------- '// Autor: | Stefan Kulpa '// | EDV Innovation & Consulting - Dormagen '// ----------------------------------------------------- Dim lFuncAddr As Long Dim lDLLHandle As Long lDLLHandle = LoadLibrary(sDllName) If lDLLHandle <> 0 Then lFuncAddr = _ GetProcAddress(lDLLHandle, sFunctionName) FreeLibrary lDLLHandle End If FunctionPresent = CBool(lFuncAddr <> 0) End Function