visual-c++dllimport-libraries

Determining existence of DLL before using it


Using Visual C++ 2008 Express Edition. I'm linking my application with an import library (.lib) for a DLL that might or might not be present on the target system. Before you ask: I cannot distribute the DLL with my application.

If the DLL is not present, as soon as I call a function from the DLL (but not sooner!), I get a message like

This application has failed to start because SomeLibrary.dll was not found. Re-installing the application may fix this problem.

What I want to happen instead, is that the application detects that the DLL is not there, and simply disables functionality that depends on it. I could make a call to LoadLibrary and see whether it succeeded, but I'm not sure whether this is sufficient. Maybe the import library does more work behind the scenes?

Is a simple LoadLibrary call sufficient? If not, what else do I need to do? Can this even be done?

Update: Of course I can use LoadLibrary, and then GetProcAddress for each of the functions I want to use. But that's a hassle, and I was hoping to avoid that and simply use the provided import library instead.


Solution

  • This is what the DelayLoad linker option is for, but I don't know whether the Express edition supports it.