Download the same dll several times

I want to load the same DLL. Lib.dll several times!

-> you need to create a new process (CreateProcess function) for each LoadLibrary!

Does anyone have an example or some tips ?!

thanks and welcomes

+7
source share
3 answers

It looks like you want each instance of the DLL to have separate data segments. This is the only reason I can think.

The only way to achieve this is to make sure that every time you call LoadLibrary , the DLL has a different file name. Copy the DLL to a temporary file each time you need to load it, making sure that the name you use is different from any loaded instance of the DLL.

I repeat the comments above that force you to reverse engineer the system architecture.

+9
source

You cannot load the same DLL several times in one process (or not and have some effect).

From your comments, the DLL performs different actions depending on one of the function calls, so you will need to use a "session" system, where you save separate data sets for each and create them as needed (via another call) and pass a descriptor or similar for every function call. This is how most Win32 APIs work (files, window handles, GDI objects, etc.)

If you make the DLL a COM host and use COM objects, this is automatically processed by each instance of the class.

If you want to use a separate process, then you can do this by simply starting a new process to host the DLL and using one of the many IPC forms to communicate with it.

+5
source

You process the DLL as an instance of the object. This is not at all how DLLs work. DLLs are not objects; they are a bunch of code and resources. These things do not change, no matter how many times you could theoretically load DLLs. Thus, it would not make sense to have multiple instances of the DLL loaded in the same process.

This is a great example of why global variables tend to be a bad idea. Data should be created if necessary.

So, if you need multiple instances of an object to work, you must design a DLL to do just that. As others have said, some kind of session or just some kind of object that you can create whenever you want.

This is an abstract answer to an abstract question. This would help LOT if you could explain more what exactly this DLL does and why you need multiple instances.

+4
source

All Articles