Home > Common Problem > body text

What is the file format of dll?

藏色散人
Release: 2020-02-15 09:51:01
Original
24872 people have browsed it

What is the file format of dll?

What is the file format of dll?

DLL file (Dynamic Linkable Library) is a file that cannot be run alone. It allows programs to share code and other resources necessary to perform special tasks

Relatively large applications are composed of many modules. These modules complete relatively independent functions. They cooperate with each other to complete the work of the entire software system. There may be some modules whose functions are more general 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 arise: One disadvantage is that it increases the size of the application, which takes up more disk space and the program runs It will also consume a large amount of memory space, causing a waste of system resources; another disadvantage is that when writing a large EXE program, all source codes must be adjusted and compiled every time it is modified and rebuilt, which increases the complexity of the compilation process. , which is also not conducive to staged unit testing.

The Windows system platform provides a completely different and more effective programming and running environment. You can create independent program modules as smaller DLL files, and compile and test them separately. At runtime, the system will load these DLL modules into the memory space only if the EXE program really wants to call them. This approach not only reduces the size of the EXE file and the memory space requirements, but also allows these DLL modules to be used by multiple applications at the same time. Windows itself implements some major system functions in the form of DLL modules.

Generally speaking, a DLL is a disk file. System files with .dll, .DRV, .FON, .SYS and many .EXE extensions can be DLLs. It consists of global data, service functions and resources. It is loaded into the virtual space of the calling process by the system at runtime and becomes part of the calling process. If there are no conflicts with other DLLs, the file is usually mapped to the same address in the process's virtual space. The DLL module contains various exported functions for providing services to the outside world. A DLL can have its own data segment, but does not have its own stack, and uses the same stack mode as the application that calls it; a DLL has only one instance in the memory; the DLL implements code encapsulation; the preparation of the DLL is related to the specific programming language It has nothing to do with the compiler.

In a Win32 environment, each process copies its own read/write global variables. If you want to share memory with other processes, you must use a memory mapped file or declare a shared data segment. The stack memory required by DLL modules is allocated from the stack of the running process. Windows matches process function calls to the DLL file's exported functions when it loads a DLL module. The operation of the Windows operating system on the DLL is only to map the DLL into the virtual address space of the process that needs it. Any objects (including variables) created by code within a DLL function are owned by the thread or process that calls it.

Calling method:

1. Static calling method: The compilation system completes the loading of the DLL and the encoding of the DLL unloading when the application program ends (if there are other programs When the DLL is used, Windows' application record of the DLL is decremented by 1, and it is not released until all related programs have finished using the DLL. It is simple and practical, but not flexible enough and can only meet general requirements.

hidden Implicit calling: The .LIB file generated when generating the dynamic link library needs to be added to the application project. When you want to use the functions in the DLL, you only need to explain it. Implicit calling does not require calling LoadLibrary() and FreeLibrary() When a programmer creates a DLL file, the linker will automatically generate a corresponding LIB import file. This file contains the symbolic name and optional identification number of each DLL exported function, but does not contain the actual code. The LIB file is compiled into the application project as a replacement file for the DLL.

When the programmer compiles and generates the application through static linking, the calling functions in the application match the exported symbols in the LIB file. These The symbol or identification number enters the generated EXE file. The LIB file also contains the corresponding DLL file name (but not the full path name), and the linker stores it inside the EXE file.

When When an application needs to load a DLL file while the application is running, Windows discovers and loads the DLL based on this information, and then dynamically links the DLL function through the symbol name or identification number. All DLL files called by the application will be loaded in the application EXE file is loaded into memory. The executable program is linked to an input library file (.LIB file) that contains the function information output by the DLL. The operating system loads the DLL when the executable program is loaded. The executable program calls the DLL directly through the function name The output function, the calling method is the same as other functions inside the program.

2. Dynamic calling method: The programmer uses API functions to load and unload the DLL to achieve the purpose of calling the DLL, which is more complicated to use. , but it can use memory more efficiently and is an important way to compile large applications.

Explicit calling:

refers to using LoadLibrary or AfxLoadLibrary provided by MFC in the application to explicitly call in the dynamic link library you have made. The file name of the dynamic link library is the above. Parameters of the two functions, and then use GetProcAddress() to get the function you want to introduce. From now on, you can call this imported function just like a custom function in this application. Before the application exits, the dynamic link library should be released using FreeLibrary or AfxFreeLibrary provided by MFC. Call the Win32 LoadLibary function directly and specify the path to the DLL as a parameter. LoadLibary returns the HINSTANCE parameter that the application uses when calling the GetProcAddress function. The GetProcAddress function converts a symbolic name or identification number to an address inside the DLL. The programmer can decide when a DLL file is loaded or not, explicit linking determines which DLL file is loaded at runtime. Programs that use DLL must load (LoadLibrary) before use to load the DLL to obtain a handle to the DLL module, and then call the GetProcAddress function to obtain the pointer of the output function. The DLL must be unloaded (FreeLibrary) before exiting.

Because DLL has the characteristics of small memory usage and easy editing, many computer viruses are files in DLL format. But it cannot be run alone.

Dynamic link libraries usually cannot run directly and cannot receive messages. They are independent files that contain functions that can be called by an executable program or other DLL to complete a certain job. It only works when other modules call functions in the dynamic link library.

The above is the detailed content of What is the file format of dll?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
dll
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template