Results 1 to 5 of 5

Thread: Late binding of a DLL

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    3

    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!

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    3

    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.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width