What is a dll file?

Source: Internet
Author: User

DLLIt is short for Dynamic Link Library, which is a Dynamic Link Library. DLL files are generally stored in the C: WindowsSystem directory. DLL is a library that contains code and data that can be used by multiple programs at the same time.

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 be shared by several applications. Such DLL files are called shared 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 and composed of relatively independent components. For example, an accounting program can be sold by module. You can load each module to 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.

Some files implemented as DLL in Windows

1. ActiveX Control (. ocx) File

An example of the ActiveX control is the calendar control, which enables you to select a date from the calendar.

2. Control Panel (. cpl) File

An example of the cpl file is an item located in the control panel. Each item is a dedicated DLL.

3. Device Driver (. drv) File

An example of a device driver is a printer driver that controls printing to a printer.

Advantages of Using DLL in programs

1. Use fewer resources

When multiple programs use the same function library, the DLL can reduce the amount of code duplicated in the 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. Promote modular architecture

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.

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 go to the HKEY_LOCAL_MACHINESoftwareMicrosrftWindowsCurrentVersionSharedDlls subkey. the right window shows all DLL files and related data. 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 it in the 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.

Rundll Uses command columns to call Windows dynamic link libraries.

The difference between rundll32.exeand rundll.exe is that the former is used for 32-bit link database, and the latter is used for 16-bit link database. Rundll32.exe is a program used to call dll files.

If win98is used, rundll32.exe is generally stored in the Windows directory;

For Windows XP, rundll32.exe is usually stored in the WindowsSystem32 directory.

If it is in its external directory, it can be a Trojan program, which may be pseudo-packaged as rundll32.exe.

DLL troubleshooting Tool

You can use multiple tools to solve the DLL problem. The following are some of the tools.

1. Dependency Walker

The Dependency Walker tool can recursively scan all the dependent DLL used by the program. When you open a program in Dependency Walker, Dependency Walker performs the following checks:

  • Dependency Walker checks whether the DLL is lost.
  • Dependency Walker checks whether an invalid program file or DLL exists.
  • Dependency Walker checks whether the import and export functions match.
  • Dependency Walker checks whether there is a loop Dependency error.
  • Dependency Walker checks whether there are modules that are invalid for another different operating system.

By using Dependency Walker, you can record all the DLL used by the program. This may help avoid and correct possible DLL problems in the future. When you install Microsoft Visual Studio 6.0, Dependency Walker is located in the following directory:
Drive \ Program Files \ Microsoft Visual Studio \ Common \ Tools

2. DLL Universal Problem Solver

The DLL Universal Problem Solver (DUPS) tool is used to review, compare, record, and display DLL information. The following table describes the utilities used to form DUPS:

  • Dlister.exe: This utility enumerates all DLL files on a computer and records this information to a text file or database file.
  • Dcomp.exe: This utility compares the DLL listed in two text files and generates a third text file containing the difference.
  • Dtxt2DB.exe: This utility loads text files created by using the Dlister.exe utility and Dcomp.exe utility into the dllHell database.
  • DlgDtxt2DB.exe: This utility provides the graphical user interface (GUI) version of Dtxt2DB.exe.

DLL type

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 the dynamic link during loading, provide the header file (. h) and imported 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 the 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.

Win32 DLL features

Win32 DLL differs greatly from Win16 DLL, which is mainly determined by the operating system design philosophy. On the one hand, in Win16 DLL, the program entry point function and exit point function LibMain and WEP are implemented respectively, but in Win32 DLL, the same function DLLMain is implemented. This function is called whenever a process or thread loads and detaches a DLL. Its prototype is

 
 
  1. BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason, LPVOID lpvReserved); 

The first parameter indicates the DLL instance handle, and the third parameter is retained;

The second parameter has four possible values:

  • DLL_PROCESS_ATTACH process loading ),
  • DLL_THREAD_ATTACH thread loading ),
  • DLL_THREAD_DETACH ),
  • DLL_PROCESS_DETACH process uninstall)

In the DLLMain function, you can identify the value of the passed parameter, and perform necessary initialization or cleanup for the DLL based on different parameter values. For example, when a process loads a DLL, the second parameter assigned to the DLL by the system is DLL_PROCESS_ATTACH. In this case, you can initialize specific data based on this parameter.

In Win16, all applications are in the same address space. In Win32, all applications have their own private space, the space of each process is independent of each other, which reduces the interaction between applications, but also increases the programming difficulty. As you know, in the Win16 environment, the global data of DLL is the same for every process that loads it. In the Win32 environment, the situation has changed, when a process loads a DLL, the system automatically maps the DLL address to the private space of the process and copies the global data of the DLL to the process space, that is to say, the global data values of the same DLL owned by each process are not necessarily the same.

Therefore, to share data among multiple processes in a Win32 environment, you must make necessary settings. That is, the data to be shared is separated and placed in an independent data segment, and the attribute of this segment is set to share.

We hope that the above content will give you a better understanding of DLL files.

Related Article

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.