Question

I'm designing a modular software infrastructure from the ground up, where different DLL's hold different business logic, and application logic. Each DLL has its own mechanism of initialization / uninitialization through common DLL calls.

Let's say I have a host application which uses these various different DLL's. All those DLL's are loaded and initialized by the host application via LoadLibrary. When one DLL initializes, it instantiates some internal global variables. Can I use another DLL to connect to this one and access the same instance without routing through the host? Surely calling LoadLibrary from within the other DLL would create another instance, and calling the DLL directly would also not be initialized / instantiated?

How do I access instantiated data from one DLL to another which were initialized by the same host application?

For example, a database connection. I encapsulate an ADO connection inside one DLL with methods of fetching / executing, etc. I would like one DLL to use the same connection which was instantiated from the host app in this DB DLL.

Était-ce utile?

La solution

Libraries (DLL modules) are shared within a process. The global variables of a library have a single instance. When you call LoadLibrary on a DLL that is already loaded, you are returned a module handle to the already loaded module. A single DLL can be loaded once only into a process.

So, it's perfectly fine for you to use LoadLibrary and then call that library's functions.

As an alternative you could use GetModuleHandle if you were sure that the library was already loaded. For example, you never need to call LoadLibrary for kernel32 since it's always loaded.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top