1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to handle "*.dll" not found ?

Discussion in 'Visual Basic ( VB )' started by SaswatPadhi, May 5, 2009.

  1. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Hi all,

    I don't know if this has been asked before, but I could not find anything relevant by searching. So, decided to start new thread.

    THE PROBLEM
    I am writing a VB.NET program that includes a COM component, which (i guess) might not be available on all target machines. As the component just adds bells and whistles to my app, and does not have anything to do with the main purpose, I wanted to find a way to continue execution of the app on the systems without the dll.

    The problem is, the app crashes with a "*.dll" not found error.

    EXAMPLE
    I want something that would fit this format :

    Code:
    ' Pseudo-code
    
    If DllFound() Then              ' DllFound checks the existence of the Dll
         TextToSpeech(Msg)
    Else
         TextBox1.Text = Msg
    End If
    
    Please help me figure out the DllFound() function.

    Thanx in advance.
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Sorry, my mistake -- I posted the thread twice !
    MODS, please delete this one.

    People, please reply on the other thread.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    Deleted the other one.

    For the Dll to exist or not just check using the File Operations methods
     
  4. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Sorry, if you could not follow; but that was not what i wanted !

    I wanted the app to execute normally even if the dll is not found. If a dll component is not present on the target system, the app won't start at all. It would report a "dll not found error !".

    For the example i've given above consider "XVoice.dll" that converts text to speech. If XVoice.dll is missing, the app would fail to start on target system. What's the use of checking dll's existence then ???
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    File.exists should do it for you
     
  6. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Could you just make it clear with an example ?
    I still don't think that would work 'cuz I've already tried that.

    The program would execute the statement File.Exists, if it's able to run !
    The program would exit with "dll not found" error before executing *ANY* instruction !

    Please make yourself clearer.
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    if(File.Exists("/path/to/your/dll/file") == true)
    {
    We know the file exists
    }

    Read this
     
  8. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Hey, that is obvious and i know that. And that's applicable not only to dlls, but also to all files.
    Why do you think I started this thread then?

    Just try making a new VB.NET project and add a COM component, let's say the "FoxItReader.dll" file. Now declare an object of that type say : "Dim XFox As FOXITREADEROCXLib". Now put your dll check in form load event and output in a text-box if the dll is available or not.

    Run on a system *without* the specified dll and see if the app informs the dll's absence correctly. I tried to make this.. but the app crashes with dll not found error instead of running!

    If your check works, please attach the source-code and I would be really grateful to you for the time and energy you've spent for me. Thanx in advance .. :)
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    Now what you are trying to do is create an object of a class which does not exist on the PC and so it should not be done the way you are doing it. The way it should be done is as follows.

    Create your own wrapper dll for FoxItReader.dll and I would call it MyFoxItReader.dll which does all the needed object initialization and variable declaration.
    Then in your app you do the checking if you have the needed DLL extension
    If yes then you load your own dll ( MyFoxItReader.dll )

    I hope you got what I meant.
     
  10. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Many thanx shabbir :)
     
  11. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    The pleasure is all mine.
     

Share This Page