|
-
Dec 24th, 2008, 08:08 AM
#1
Thread Starter
New Member
Late binding of a DLL
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!
-
Dec 27th, 2008, 09:43 PM
#2
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.
-
Dec 30th, 2008, 09:48 AM
#3
Thread Starter
New Member
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.
-
Dec 30th, 2008, 10:21 AM
#4
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.
-
Dec 30th, 2008, 04:31 PM
#5
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|