Search code examples
multithreadingdlldelphi-7loadlibrary

Load multiple DLLs through thread in Delphi 7


My application has separeted modules (modal forms) as dlls. Through application main menu, I access those dlls, calling LoadLibrary and FreeLibrary when the form closes. Everything works fine.

A new module that has been created used a new aproach, he itslef uses others plugins (dlls) to work. As I load this module, those plugins are loaded as well. But it takes time.

So to prevent this load time during the opening of this module, I tried to previously load those plugins in my application initialization through thread, but I noticed that even in thread, windows LoadLibrary do not execute simultaneously, I mean, after my application starts, if I try to open any module (other than that witch uses those plugins), it waits until the thread finishs to then load the module.

So, is there a way to make loadlibrary to work "simultaneously"?


Solution

  • When you load a module the system loader serializes the task using what is known as the loader lock. Consequently multiple calls to LoadLibrary cannot execute in parallel.

    The real problem is probably that these DLLs are performing time consuming work whilst loading. The only way to speed things up will be to change the DLLs to postpone that work.