Attribute VB_Name = "modOpenDll"
Option Explicit
Dim hInst As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
'Here we check for DLL (if it's entered and if it's valid)
Private Function CheckDllName(tmpDllName) As Boolean
CheckDllName = True
If Len(tmpDllName) = 0 Or tmpDllName = vbNullString Then
Err.Raise 27000, App.EXEName & ".LoadResDll", "Please input correct DLL name !"
CheckDllName = False
Exit Function
End If
If Dir(tmpDllName) = "" Then
Err.Raise 27005, App.EXEName & ".LoadResDll", "Error" & vbNewLine & tmpDllName & vbNewLine & "File not existed !"
CheckDllName = False
Exit Function
End If
End Function
Public Sub LoadResourceDLL(tmpDllName As String)
If CheckDllName(tmpDllName) = False Then Exit Sub
hInst = LoadLibrary(tmpDllName)
If hInst = 0 Then
Err.Raise 27001, App.Title & ".LoadRes", "Resource DLL could not be loaded."
Exit Sub
End If
End Sub
Public Sub FreeResourceDLL()
FreeLibrary (hInst) 'close library
End Sub