Recent

Author Topic: How can I make an external DLL "optional" ?  (Read 562 times)

Sander

  • New Member
  • *
  • Posts: 14
How can I make an external DLL "optional" ?
« on: May 21, 2025, 01:16:03 am »
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

  • Hero Member
  • *****
  • Posts: 4377
Re: How can I make an external DLL "optional" ?
« Reply #1 on: May 21, 2025, 01:29:47 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?
Unit dynlibs. Small simplified example in wiki.
Today is tomorrow's yesterday.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1530
    • Lebeau Software
Re: How can I make an external DLL "optional" ?
« Reply #2 on: May 21, 2025, 01:46:13 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.

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

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.

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.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Sander

  • New Member
  • *
  • Posts: 14
Re: How can I make an external DLL "optional" ?
« Reply #3 on: May 21, 2025, 09:51:14 pm »
Thank you gentlemen, I shall make it so.
Sander

 

TinyPortal © 2005-2018