DLL: Microsoft Dynamically Linked Libraries
Index: Requirements
Problems Companies
Platforms Languages
Software Research
- DLL -- Dynamically Linked Library
- Used to store object code and resources in dynamically loaded files
under Win32.
- A DLL exports a flat API, a one-dimensional list of function calls
and data. You can refer to them by index or name. This isn't high level
enough for component software, a problem that higher level frameworks like
COM and OLE address. OLE
defines Type Libraries that provide metadata
describing the contents of the DLL, and functions to automatically register
objects and services in the system registry.
There are two interface definition languages that describe the contents
of DLL's to COM and OLE: MIDL and ODL.
- Self Registering DLLs have a string resource that declares that they
are self-registering, which means they have a couple of functions to call
that register and unregister their classes in the windows registry:
DLLRegisterServer and DLLUnregisterServer.
- OLE allows object servers to be completely
implemented inside of a DLL. This type of server is called an "in-proc
server". MFC does not completely support in-proc
servers for all the features of visual editing, mainly because OLE
does not provide a way for a server to hook into the container's main message
loop. MFC requires access to the container application's
message loop to handle accelerator keys and idle-time processing. If you
are writing an OLE Automation server and your server
has no user interface, you can make your server an in-proc server and put
it completely into a DLL.
- Multithreading Issues
- A DLL can keep track of thread specific data using TlsAlloc and
TlsGetValue (part of the Win32 thread local storage
API).
- DLLs notified of threads attaching and detaching in their DLLMain
function, so they can keep track of all threads in the process and allocate
local storage as necessary.
- Windows uses the "apartment model" of multithreading,
where only the thread that created an object is allowed to send messages
to it. All other messages from other threads are serialized via the Windows
message queue, that the thread must service. This makes it possible to "kind
of" multithread code that is not thread safe, since only one thread
will ever be executing the code of a particular object. You can explicitly
program around this threading model if it doesn't meet your needs, but it
is the default behavior.
- Extension DLL
- Extend the Microsoft Foundation Classes.
- If you need to pass an MFC or MFC-derived object pointer to or from
an MFC DLL, the DLL should be an Extension DLL. The member functions associated
with the passed object exist in the module where the object was created.
Since these functions are properly exported when using the Shared DLL version
of MFC, you can freely pass MFC or MFC-derived object
pointers between an application and the Extension DLLs it loads.
- An extension DLL creates a CDynLinkLibrary object to export CRuntimeClass
objects or resources to the application.