mark
mark

Reputation: 62816

How to run without a dependent DLL when that DLL is not used?

I have a VC++ application compiled against a third party DLL (using their LIB file, of course).

The thing is that not every scenario involves the code of that DLL, but Windows refuses to start the application, if the particular DLL is missing.

I am wondering, how can I workaround this constraint. I would like the application to crash only if the aforementioned DLL is really needed.

Please, ignore the question, whether it is a good taste when an application crashes after it has successfully started - I will take care of it.

How can I defer the DLL resolution until that DLL actually needs to be loaded?

Thanks.

Upvotes: 0

Views: 319

Answers (1)

NPE
NPE

Reputation: 500663

See the /DELAYLOAD linker option:

The Visual C++ linker now supports the delayed loading of DLLs. This relieves you of the need to use the Windows SDK functions LoadLibrary and GetProcAddress to implement DLL delayed loading.

Before Visual C++ 6.0, the only way to load a DLL at run time was by using LoadLibrary and GetProcAddress; the operating system would load the DLL when the executable or DLL using it was loaded.

Beginning with Visual C++ 6.0, when statically linking with a DLL, the linker provides options to delay load the DLL until the program calls a function in that DLL.

An application can delay load a DLL using the /DELAYLOAD (Delay Load Import) linker option with a helper function (default implementation provided by Visual C++). The helper function will load the DLL at run time by calling LoadLibrary and GetProcAddress for you.

Upvotes: 3

Related Questions