Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Project referencing DLL that may not be there

Project referencing DLL that may not be there

Scheduled Pinned Locked Moved Visual Basic
dotnethelptutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rahvyn6
    wrote on last edited by
    #1

    I am developing an app in VS2005. I need to put in a reference to an existing dll. The issue is, that dll may or may not exist on the machines that the app gets installed on. The app will have branching code depending on if the machine uses the dll or not, but I am unsure if this will work. I have read that the CLR will not invoke the dll unless it is called. So if I have the dll on my dev machine, have it referenced in the project, have a Try / Catch block around the call to NEW of the dll, but have the dll dimensioned in the class, install the app on another machine without the dll, will it blow up on me? Or will the Try / Catch block stop it from blowing up? Simple code Example: Public Class myClass Private dll as dllMayNotExist Public Function Execute() Try dll = New dllMayNotExist Catch 'do nothing here, if dll does not exist, it is not needed End Try End Function

    D 1 Reply Last reply
    0
    • R rahvyn6

      I am developing an app in VS2005. I need to put in a reference to an existing dll. The issue is, that dll may or may not exist on the machines that the app gets installed on. The app will have branching code depending on if the machine uses the dll or not, but I am unsure if this will work. I have read that the CLR will not invoke the dll unless it is called. So if I have the dll on my dev machine, have it referenced in the project, have a Try / Catch block around the call to NEW of the dll, but have the dll dimensioned in the class, install the app on another machine without the dll, will it blow up on me? Or will the Try / Catch block stop it from blowing up? Simple code Example: Public Class myClass Private dll as dllMayNotExist Public Function Execute() Try dll = New dllMayNotExist Catch 'do nothing here, if dll does not exist, it is not needed End Try End Function

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      That won't work. The .DLL has to be there otherwise your app will fail when the JIT compiler goes to compile the METHOD that tried to call that library. Using a Try/Catch block will have no effect because that method that contains it will never run. All external references are resolved upon JIT compile, not at execution of a class' constructor. You'll have to check for the existance of the .DLL at the start of your code and set a flag as to whether or not it's there. Then, you'll need to write a wrapper around your two methods, one that uses the .DLL and one that doesn't, plus a dispatcher method to choose between the two methods. The Dispatcher will be the function that your outside call actually calls. The dispatcher will check this flag to see if the .DLL exists, then pass the parameters to the version that's appropriate and pass any return values back to the caller.

                       Caller
                         ^ |
                         | |
                         | v
      .DLL flag------>Dispatcher
                      ^ |    ^ |
                      | |    | |
                      | v    | v
                    Method  Method
      

      Dave Kreskowiak Microsoft MVP - Visual Basic

      R 1 Reply Last reply
      0
      • D Dave Kreskowiak

        That won't work. The .DLL has to be there otherwise your app will fail when the JIT compiler goes to compile the METHOD that tried to call that library. Using a Try/Catch block will have no effect because that method that contains it will never run. All external references are resolved upon JIT compile, not at execution of a class' constructor. You'll have to check for the existance of the .DLL at the start of your code and set a flag as to whether or not it's there. Then, you'll need to write a wrapper around your two methods, one that uses the .DLL and one that doesn't, plus a dispatcher method to choose between the two methods. The Dispatcher will be the function that your outside call actually calls. The dispatcher will check this flag to see if the .DLL exists, then pass the parameters to the version that's appropriate and pass any return values back to the caller.

                         Caller
                           ^ |
                           | |
                           | v
        .DLL flag------>Dispatcher
                        ^ |    ^ |
                        | |    | |
                        | v    | v
                      Method  Method
        

        Dave Kreskowiak Microsoft MVP - Visual Basic

        R Offline
        R Offline
        rahvyn6
        wrote on last edited by
        #3

        So the dll will not be declared in one function, and declared in the other?

        D 1 Reply Last reply
        0
        • R rahvyn6

          So the dll will not be declared in one function, and declared in the other?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Yes.

          Dave Kreskowiak Microsoft MVP - Visual Basic

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups