Download two instances of the same DLL in Delphi

Here is my problem: I would like to create two separate instances of the same DLL.

The following does not work because Handle1 and Handle2 will get the same address

Handle1 := LoadLibrary('mydll.dll'); Handle2 := LoadLibrary('mydll.dll'); 

The following works, but I have to make a copy of the DLL and rename it to something else (which seems a little silly)

  Handle1 := LoadLibrary('mydll.dll'); Handle2 := LoadLibrary('mydll2.dll'); 

Is there a way to have only one dll file but load multiple instances of it?

+4
source share
3 answers

I do not think that's possible.

You need to write a .exe file that loads the dll. Then you can span several processes (.exe), and each of them will start its own instance of dll. You will need to use the IPC (inter process communication) methods to communicate with .exes. Of course, doable, but not entirely simple.

+3
source

It will not work with LoadLibrary because Windows checks if the dll has already been loaded and will return the same handle again and again.

I have some code that was originally intended to load a dll from a resource associated with an executable file, but I assume that one could also do the same for the memory area that was filled with the contents of the file. I see no reason why it will not work twice, but I have not tested it.

You can find it here: http://svn.berlios.de/viewvc/dzchart/utilities/dzLib/trunk/src/u_dzResourceDllLoader.pas?view=markup

This is part of my jlib library, available under MPL.

+1
source

Windows XP introduced side-by-side for the Win32 DLL ( these guys know a lot about this).

With lots of hoops you can now:

0
source

Source: https://habr.com/ru/post/1307454/


All Articles