Checking if a DLL is present

Started by
3 comments, last by DividedByZero 5 years, 7 months ago

Hi Guys,

If your application requires a DLL, is there a way to check that the DLL is present gracefully rather than the typical error that gets thrown?  For example - 'The code execution cannot proceed because xxxxxxxx.dll was not found. Reinstalling the program may fix this problem'.

In my case the DLL is my own, if that makes any difference.

Thanks in advance.

 

Advertisement

If the DLL is your own (as in you have the source) maybe you can statically link it instead of use a DLL?

Assuming you need to go with DLL, one way might be to use a small loader program that calls 'LoadLibrary' to dynamically load DLLs and check they are there, then if all is well load the main program. Or you could use LoadLibrary in the main program. (I forget the pros and cons of this, it is a while since I did this. There may be a better way! :) )

Static linking seems the easiest choice.

You could have a separate launcher program that verifies the installation before running the main program.

Or you could do dynamically loading. I cant remember if delay loaded DLL's avoid the startup check, but if they do that is simple, just try a LoadLibrary before you call any function in the DLL.

If not you would have to not link with it at all and GetProcAddress everything which is a pain unless you have an interface based design with minimum exported functions (similar to COM, so just a "CreateFactory" or such to GetProcAddress).

 

 

 

I would question why this is needed though? A user should almost never be able to get into a situation that a DLL is missing and if your trying to cover "all things" then that is basically never ending.

Thanks guys. This is probably a case of me over thinking things - LOL

This topic is closed to new replies.

Advertisement