Dynamic Link Library,
What is a database?
To build an application, we will not keep writing from the underlying driver to the front-end. The existence of the library is just filled with this, so we can avoid repeating the wheel. Libraries are reusable and stable set of functions.
Windows API has three most important Libraries: Kernel32.dll, User32.dll, and GDI32.dll. Various languages also encapsulate their own libraries: C/C ++ runtime libraries, and C # FCL.
Database category
Static and Dynamic databases are divided into static chunks (.a%.lib%and dynamic chunks (.so%.dll%.exe). Static and Dynamic databases refer to the link action and timing. The static link directly links the function code in the static library to the target program. The link is completed during application compilation, and the library file is not required when the program is running. Dynamic Links link information such as the location of the dynamic library and the called function in the library file where the called function is located to the target program. During the running process, the program searches for corresponding functions from the dynamic library, the link is completed when the application is running.
Both dynamic and static libraries have code reusability and promote application modularization. Why do dynamic libraries need to be used?
Advantages of dynamic libraries:
(1) Ability to dynamically expand applications
Applications can display and load the dynamic link library (the above statements are implicitly loaded to the Dynamic Link Library), and perform some operations to extend the functions of the application. For example, if A company A develops A product and the product develops to A stage, it needs to provide remote networking and monitoring functions. In this case, he wants another team or company to expand the product, at this time, DLL is very useful.
(2) helps to save memory space
If a static library is reused by 100 applications, 100 of the applications are opened at the same time, which is equivalent to copying the static library 100 times in the memory. However, the dynamic library is loaded only once in the memory.
(3) Easy application updates, deployment, and release
A large application references a static library. If the static library is modified, the entire application must be re-compiled and released. For gamers, the software is re-installed. The application that references the dynamic library only needs to modify the dynamic library, which is a simple upgrade for players.
(4) promotes Localization
DLL is often used to localize applications. For example, an application can only contain code (Language-culture-neutral), but does not contain language-culture differences components and resources such as user interfaces. DLL is used to store the content affected by language-culture differences, the supplied program is loaded and used.
Dynamic library disadvantages:
(1) transplantation
Applications that reference dynamic libraries are not as convenient as applications that reference static libraries
(2) initialization
The application that references the dynamic library has a long initialization time.
How to build a dynamic library
Using VS2013 to build a C ++ dynamic library as an Example
1. Create a project MyDLL, select the DLL and export symbol in the Wizard (used to automatically generate the basic file for the exported content)
2. The MyDLL. h header file is automatically generated to export functions, variables, and classes in the DLL.
3. Compile the above project to generate the following file
How to Use Dynamic Link Library
Three files that require a dynamic library: MyDLL. h, MyDLL. lib, and MyDLL. dll. These files must be deployed during use.
1. Create a console application MyAPP
2. Right-click the project "property"
(1) Deploy. H files and select the directory where MyDLL. H files are located.
(2) Deploy the. lib File
Select the directory where the. lib file is located
Enter the name of the additional library MyAPP. lib
(3) Deploy the. dll file
Copy the MyDLL. dll file to the output directory of the MyAPP project.
3. Add # include "MyDLL. h" to the function, variable, and type source file to be exported using MyDLL. dll to use the exported content.
PS: if you are interested in the import and export principles of the dynamic library and related compilation processes, please refer to the subsequent articles.