About dynamic link library
Dynamic link allows a module to load or execute an exported DLL function. Dynamic links are different from the static link we are familiar with. When using a static link, the linker copies the library function code into each required module.
Dynamic link type
There are two ways to call a DLL:
Dynamic links when loaded, the module is very clear to call an export function so that they are just like local functions. This requires links to link the import library of those functions where those functions are located, and the import library provides information and DLL function positioning when loading the DLL. For more information, please refer to "Dynamic Link Time Link". Running dynamic links, running the DLL through the LoadLibrary or LoadLibraryEx function at runtime. After the DLL is loaded, the module can get the exit address of the DLL function by calling getProcAddress, and then call the DLL function by the returned function pointer. This will avoid importing library files. For more information, please refer to "Use Running Dynamic Link Library".
DLL and memory management
When each program is loaded into the DLL, it will be mapped to the virtual address space before you can call the DLL's exit function.
The system maintains a thread-level reference count for each DLL, once a thread loads the DLL, the reference count will add 1. The program termination or reference count becomes 0 (only when the running dynamic link library), the DLL will release the virtual address space of the occupant.
As with other functions, a DLL outlet function is executed in the context of the thread (or called), so the following cases apply:
The program thread that calls the DLL can use the handle that opens through the DLL function. Similarly, the handle of any thread in the program can be used by the DLL function. DLL uses the virtual location space of the stack space and calling program that call the thread. DLL allocates memory from the virtual address space of the calling program.
Dynamic link advantages
For static links, dynamic links have the following advantages:
Multiple programs load the same DLL into the same base address to share unique copies in physical memory. This saves system memory and reduces exchange. When the function changes in the DLL, as long as it is not a function parameter change, the call mode changes or the return value change, calling their applications does not need to recompile or re-link. In contrast, static link object code requires an application to re-link. DLL can provide (convenient) after-sales service. For example, modify the display driven DLL to support the display that does not support when loading. Procedures written in different programming languages You can call the same DLL function as long as you follow the function call agreement. Call conventions (such as C, PASCAL or standard call) control the order of parameters when the call is called, without tube is a function or calling function is responsible for the stack, or whether the parameter is in the register. For more information, you can refer to your compiler's related documentation.
A potential defect with DLL is that the application is not self-confident, it needs to rely on additional DLL modules. If the dynamic link is used in load, the program is found when the program starts, and the system will terminate the program and give an error message. When using runtime dynamic links, the system will not terminate, but the export function in the lost DLL is also not available.