What is dynamic link?

Source: Internet
Author: User
What is a dynamic link library?What is a dynamic link library?

I. Concept of Dynamic Link Library
Dynamic link library (DLL) is a program module that can be shared by other applications. It encapsulates some routines and resources that can be shared. The file extension of the dynamic link library is generally DLL, or DRV, sys, and Fon. It is very similar to the executable file (exe, the difference is that although the dll contains executable code, it cannot be executed independently, but should be called directly or indirectly by a Windows application.

Dynamic Links are relative to static links. The so-called static link refers to linking the function or process to be called to the executable file to become part of the executable file. In other words, the function and process code is in the program's exe file, which contains all the code required for running. When multiple programs call the same function, multiple copies of the function exist in the memory, which wastes valuable memory resources. The function code called by the dynamic link is not copied to the executable file of the application, instead, it only adds the description information of the called function (usually some relocation information ). Only when the application is loaded into the memory and starts to run, the connection between the application and the corresponding DLL is established under Windows Management. When you want to execute the functions in the called DLL, the corresponding function code in the DLL is transferred to Windows based on the relocation information generated by the link.

Generally, if an application uses a dynamic link library, the Win32 system ensures that only one copy of the DLL is in the memory, which is implemented through the memory ing file. The DLL is first transferred to the global stack of the Win32 system, and then mapped to the process address space that calls the DLL. In the Win32 system, each process has its own 32-bit linear address space. If a DLL is called by multiple processes, each process will receive an image of the DLL. Unlike a 16-bit windows, a DLL in Win32 can be considered as the code of each process.

Ii. Advantages of Dynamic Link Library

1. Share code, resources, and data

The main purpose of using DLL is to share the code. The DLL code can be shared by all Windows applications.

2. Hide Implementation Details

The routines in dll can be accessed by the application, but the application does not know the details of these routines.

3. Expand functions of development tools such as Delphi

Because the DLL is language-independent, you can create a DLL and call it by C ++, VB, or any language that supports dynamic link libraries. In this way, if one language is insufficient, it can be compensated by accessing the DLL created in another language.

Iii. Implementation of Dynamic Link Library

1. Load-Time Dynamic Linking

The premise of this usage is that you have clearly known which functions in the DLL to be called before compilation. during compilation, only necessary link information is kept in the target file, excluding the DLL function code; when a program is executed, it uses the link information to load the DLL function code and link it to the execution space of the calling program in the memory. The main purpose is to facilitate code sharing.

2. Run-Time Dynamic Linking

This method means that you do not know which DLL functions will be called before compilation, and decide which function to call based on your needs during the running process, use loadlibrary and getprocaddress to dynamically obtain the DLL function entry address.

Learn about DLL files in the dynamic link library

DLL is short for dynamic link library, meaning dynamic link library. In Windows, many applications are not a complete executable file. They are divided into relatively independent dynamic link libraries, that is, DLL files, which are placed in the system. When we execute a program, the corresponding DLL file will be called. An application may have multiple DLL files, and a DLL file may also be used by several applications. Such DLL files are called shared DLL files. DLL files are generally stored in the C: Windowssystem directory.

1. How to understand which DLL files are used by an application

Right-click the application and choose "Quick View" from the shortcut menu, in the "Import table" column of the "Quick View" window that appears, you will see the usage of DLL files.

2. How to know that the DLL file is used by several programs

Run regedit and enter hkey_local_machinesoftwaremicrosrftwindowscurrent-
View the versionshareddlls subkey. All DLL files and their related data are displayed in the right window. The numbers in the parentheses on the right of the data indicate that they are used by several programs. (2) it indicates that it is used by two programs, and (0) indicates that no program is used. You can delete it.

3. How to Solve DLL file loss

When detaching a file, you are reminded that deleting a DLL file may affect the running of other applications. When you uninstall the software, you may accidentally delete the shared DLL file. Once the DLL file is lost, you can find the DLL file in sysbckup (System Backup folder) and copy it to the system folder. If this is not the case, "*** DLL file loss..." always occurs when the computer is started ......" You can run msconfig in "Start/run". After Entering the System Configuration Utility dialog box, click "system. ini "label to find the DLL file that is prompted to be lost, so that it is not selected, so that no error prompt will appear at boot.

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.