What is the DLL file?

Source: Internet
Author: User

A dll file (Dynamic Linkable Library) is a file that cannot be run independently. It allows programs to share the code and other resources necessary to execute special tasks. Large applications are composed of many modules that complete relatively independent functions and collaborate with each other to complete the work of the entire software system. Some modules may have common functions and will still be used when constructing other software systems. When constructing a software system, if the source code of all modules is statically compiled into the entire application EXE file, some problems will occur:

1. An increase in the application size will occupy more disk space and consume a large amount of memory during program running, resulting in a waste of system resources;

2. When compiling a large EXE program, you must adjust and compile all the source code each time you modify and reconstruct the program. This increases the complexity of the compilation process and is not conducive to periodic unit tests;

In Windows, many applications are not a complete executable file. They are divided into relatively independent Dynamic Link Libraries. When we execute a program, the corresponding DLL file will be called. An application may have multiple DLL files, and a DLL file may be shared by several applications. Such a DLL file is calledShare DLL files. For example, in Windows, Comdlg32 DLL executes common functions related to the dialog box. Therefore, each program can use the functions included in the DLL to implement the "open" dialog box. This helps promote code reuse and effective memory usage.

By using DLL, the program can be modularized by relatively independentComponents. For example, an accounting program can be sold by module. Each module can be loaded into the main program at runtime (if the corresponding module is installed ). Because modules are independent from each other, the program loading speed is faster, and the module is loaded only when the corresponding functions are requested.

In addition, it is easier to apply updates to each module without affecting other parts of the program. For example, you may have a salary calculation program, and the tax rate is changed every year. After these changes are isolated into the DLL, you can apply updates without re-generating or installing the entire program.

In general, a DLL is a disk file. dll,. DRV,. FON,. SYS, and many system files with. EXE extension can be DLL. It consists of global data, service functions, and resources, and is loaded into the virtual space of the calling process by the system at runtime, becoming part of the calling process. If there is no conflict with other DLL, the file is usually mapped to the same address of the virtual space of the process. The DLL module contains various export functions for external services. A dll can have its own data segment but does not have its own stack. It uses the same stack mode as the application that calls it. a dll has only one instance in the memory; DLL implements code encapsulation. DLL compilation is independent of the specific programming language and compiler.

DLL has the following advantages:

1,Use fewer resources: When multiple programs use the same function library, DLL can reduce the repeated amount of code loaded in disk and physical memory. This not only can greatly affect the programs running on the foreground, but also can greatly affect other programs running on the Windows operating system.

2,Modular architecture of promotion: DLL facilitates the development of modular programs. This helps you develop large programs that require multiple language versions or require a modular architecture. An example of a modular program is a program with multiple modules that can be dynamically loaded at runtime.

3, Simplified deployment and Installation: When the functions in the DLL need to be updated or repaired, you do not need to re-establish the link between the program and the DLL to deploy and install the DLL. In addition, if multiple programs use the same DLL, multiple programs will benefit from the update or repair. This issue may occur more frequently when you use a third-party DLL that is regularly updated or repaired.

There are two calling methods:

1,Static call Method: The compilation system loads the DLL and the encoding of the DLL uninstallation when the application ends. (if other programs use the DLL, the Windows application record for the DLL is reduced by 1, it will not be released until all related programs end using the DLL. This method is simple and practical, but not flexible enough to meet General requirements ).

2,Dynamic call Method: The programmer uses API functions to load and uninstall the DLL to call the DLL. The usage is complicated, but the memory can be used more effectively, is an important way to compile large-scale applications.

When you load a DLL in an application, you can use two link methods to call the exported DLL function. These two link methods are dynamic links during loading and dynamic links during runtime:

1,Dynamic Link during loading: In the dynamic link during loading, the application explicitly calls the exported DLL function just like calling a local function. To use dynamic links during loading, provide the header file (. h) and import file (. lib) when compiling and linking the application ). When you do this, the linker will provide the system with the information required to load the DLL and parse the location of the exported DLL function during loading.

2,Dynamic Link during running: In the dynamic link at runtime, the application calls the LoadLibrary function or LoadLibraryEx function to load the DLL at runtime. After successfully loading the DLL, you can use the GetProcAddress function to obtain the address of the exported DLL function to be called. When using dynamic links during running, you do not need to use import/export files.

Many computer viruses are DLL files because DLL files occupy a small amount of memory and are easy to edit. However, it cannot be run independently. The dynamic link library usually cannot run directly or receive messages. They are independent files that contain functions that can be executed or called by other DLL to complete a job. It only works when other modules call functions in the dynamic link library.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.