Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load the same dll multiple times [closed]

I want to load the same dll e.g. Lib.dll multiple times!

-> need creating a new process (CreateProcess function) for every LoadLibrary!

Anyone have an example or some hints?!

Thx and greets

like image 578
leon22 Avatar asked Sep 21 '12 11:09

leon22


2 Answers

It sounds like you want each instance of the DLL to have separate data segments. That's the only reason I can think of for the question.

The only way to achieve this is to make sure that each time you call LoadLibrary, the DLL has a different filename. 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 echo the comments above that encourage you to re-design the system architecture.

like image 86
David Heffernan Avatar answered Sep 21 '22 11:09

David Heffernan


You are treating a DLL like an object instance. That's 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 a DLL. Thus there would be no point in having 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 needs to be able to be instantiated as needed.

So if you need multiple instances of an object to work with, you should design the DLL to do exactly that. As others have said, some kind of session, or just some object that you can instantiate whenever you want.

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

like image 27
tenfour Avatar answered Sep 21 '22 11:09

tenfour