Is DLL Registered

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

You might also like...

Comments

Mike Bender

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila” - Mitch Ratcliffe