Below is the source code. Simply calls IsDLLAvailable with the appropriate filename of the DLL
'Constants
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Private Const MAX_MESSAGE_LENGTH = 512
'API declarations
Private Declare Function GetLastError Lib "kernel32" () As Long
Private
Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (
_
ByVal dwFlags As Long, _
lpSource As Any, _
ByVal dwMessageId As Long, _
ByVal dwLanguageId As Long, _
ByVal lpBuffer As String, _
ByVal nSize As Long, _
Arguments As Long) 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
Function IsDLLAvailable(ByVal DllFilename As String) As Boolean
Dim hModule As Long
hModule = LoadLibrary(DllFilename) 'attempt to load DLL
If hModule > 32 Then
FreeLibrary hModule 'decrement the DLL usage counter
IsDLLAvailable = True 'Return true
Else
IsDLLAvailable = False 'Return False
End If
End Function
Private Function GetAPIErrorMessageDescription(ByVal
ErrNumber As Integer) As String
'Purpose: To locate and return the error message definition per
' the systems message table.
'Params: ErrNumber as the 32 bit message identifier.
'Returns: Formatted error message.
Dim sError As String * MAX_MESSAGE_LENGTH 'declare message buffer
Dim lErrMsgLen As Integer '32 bit message identifier
'Make API call to retrieve the system message
lErrMsgLen = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, _
0, ErrNumber, 0, sError, MAX_MESSAGE_LENGTH, 0)
If lErrMsgLen > 0 Then 'check the length of the return buffer
GetAPIErrorMessageDescription = sError 'return the
error message
End If
End Function
Comments