Click to See Complete Forum and Search --> : Late binding of a DLL
CBrianA
Dec 24th, 2008, 07:08 AM
I have a program that can be used in an environment where the end user may or may not have Novell libraries installed. I need to have one program that has conditional compilation, so when I build, the program will either have live subroutines that call the Novell libraries, or stubs.
The problem is that the full program has a Novell component (nwdirauth.dll) that will be missing on some systems. I would like to be able to use the conditional compilation switches so that the compiler might include the component, as long as I had set the switch.
Or, if it is possible, use late binding in the live novell subroutines, so that the routine would perform a createobject on the DLL, so it can be referenced without adding the component at build time.
This is a major piece of my project. Please help!
LaVolpe
Dec 27th, 2008, 08:43 PM
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.
CBrianA
Dec 30th, 2008, 08:48 AM
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.
Hack
Dec 30th, 2008, 09:21 AM
Then try something likePrivate 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 SubNow you can wrap your use of this library in an If blnIsFound = True structure.
LaVolpe
Dec 30th, 2008, 03:31 PM
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
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.