Forum > Windows

How can I make an external DLL "optional" ?

(1/1)

Sander:
I have run into a situation which could use some help from an experienced WIN32 programmer.

I have discovered that it is mandatory that an external .DLL file actually exists if my program
has declared external functions to it, even when these functions will never be actually called.
If the .DLL file does not exist, Windows (or the RTL?)  puts up a box which says that there is a component missing and my program needs to be re-installed.

My program can work with many devices, some of which have an interface via a DLL.
However, the DLL is only needed for one particular device which the user may not even have.
The way it stands, I would need to supply all DLL's for all supported devices with my software,
because if I don't, it won't even run.

I would like to be able to see which devices a user wants support for (config file), and on the basis of that load the appropriate DLL's myself.
The user would after all have the DLL for the device already, since he has it installed on his computer.
Is there a way to do this?

Any tips would be greatly appreciated.

Sander

TRon:

--- Quote from: Sander on May 21, 2025, 01:16:03 am ---I would like to be able to see which devices a user wants support for (config file), and on the basis of that load the appropriate DLL's myself.
The user would after all have the DLL for the device already, since he has it installed on his computer.
Is there a way to do this?

--- End quote ---
Unit dynlibs. Small simplified example in wiki.

Remy Lebeau:

--- Quote from: Sander on May 21, 2025, 01:16:03 am ---I have discovered that it is mandatory that an external .DLL file actually exists if my program
has declared external functions to it, even when these functions will never be actually called.
If the .DLL file does not exist, Windows (or the RTL?)  puts up a box which says that there is a component missing and my program needs to be re-installed.

--- End quote ---

That happens if you statically link to a DLL function at compile-time using the external directive.


--- Quote from: Sander on May 21, 2025, 01:16:03 am ---I would like to be able to see which devices a user wants support for (config file), and on the basis of that load the appropriate DLL's myself.

--- End quote ---

You would need to load the DLLs dynamically at runtime instead of linking to them statically at compile-time.  Use LoadLibrary() to load a DLL into memory, and GetProcAddress() to get a pointer to an function exported by a loaded DLL.

Sander:
Thank you gentlemen, I shall make it so.
Sander

Navigation

[0] Message Index

Go to full version