How to handle "*.dll" not found ?

SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
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.
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Sorry, my mistake -- I posted the thread twice !
MODS, please delete this one.

People, please reply on the other thread.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Deleted the other one.

For the Dll to exist or not just check using the File Operations methods
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
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 ???
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
File.exists should do it for you
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
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.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
if(File.Exists("/path/to/your/dll/file") == true)
{
We know the file exists
}

Read this
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
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 ..
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.
0
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Many thanx shabbir