Re: Late binding of a DLL
Which language? VB6, VB.net or something else?
If nwdirauth.dll is an activeX dll, you should be able to do late binding. If the user's system doesn't have the DLL, are you distributing it? If so, use early binding and include the DLL to the setup package. Maybe I might be misunderstanding the scenarios.
Welcome to the forums.
Re: Late binding of a DLL
Yes, my apologies - it is VB6.
The DLL is not something that I will be distributing - I just want to use it if it is present and registered.
Re: Late binding of a DLL
Then try something like
Code:
Private Declare Function SearchTreeForFile Lib "imagehlp" _
(ByVal RootPath As String, _
ByVal InputPathName As String, _
ByVal OutputPathBuffer As String) As Long
Private Const MAX_PATH = 260
Private blnIsFound As Boolean
Private Sub Form_Load()
Dim BufferString As String
Dim FindIt As Long
'create a buffer string
BufferString = String(MAX_PATH, 0)
'Typically, FindIt will return 1 if successfull, 0 if not
FindIt = SearchTreeForFile("c:\", "nwdirauth.dll" , BufferString)
If FindIt <> 0 Then
blnIsFound = True
End If
End Sub
Now you can wrap your use of this library in an If blnIsFound = True structure.
Re: Late binding of a DLL
Hack's method will work, using LoadLibrary will be faster, assuming the DLL is a standard vs Active-X DLL. If Active-X, then CreateObject with error checking can be faster than a search. Determining if the DLL is there or not, isn't a major problem.
The search method will not inform you if it is installed or not
Code:
Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32.dll" (ByVal hLibModule As Long) As Long
' only works if DLL is non-ActiveX (standard)
Dim lb As Long
lb = LoadLibrary("nwdirauth.dll")
If lb Then
FreeLibrary lb
' it exists and is registered
Else
' doesn't exist in DLL path or not registered
End If
' only works if DLL is an Active-X DLL
On Error Resume Next
Dim tObject As Object ' late binding
Set tObject = CreateObject([class name], [server name])
If tObject Is Nothing Then
' doesn't exist or not registered
Else
' it exists & is registered
' set to nothing or set to public variable
' and in your routines, you can check if the public variable is Nothing before trying to use it
End If