Dynamic Link Library - Principle

xiaoxiao2021-03-06  53

Understanding

The library is a file that contains functions or other resources that can be used in applications.

These resources are generally versatile, allowing many different applications that can be easily shared with code or resources.

Static link library

It is part of the application executable file that cannot be shared with other applications that use the same function.

Usually used for relatively small stable functions, such as C Standards because it is easy to create and maintain.

It is added to the executable when compiling and linking.

Dynamic link library

It is an executable file that contains things available for other applications such as functions, data, or resources.

It can be loaded at any time when needed, or when loading or run.

When an application requires a loaded DLL:

1. Map the DLL to the address space of the new process.

2. Let Windows 2000 add 1 to the reference counter left by the DLL.

Note: The path of the DLL is part of its identity.

The pros and cons of DLL

Benefits: Reduce the executable code size, reuse code, and large projects can be divided into easy management small projects, and achieve new features easier

Disadvantages: Handling multiple files, increasing the complexity of the project, user wants to process DLL version issues

Initialization DLL

The timing of the entry point function is called:

When the process calls the DLL for the first time

Create a new process with the process associated with the DLL

A thread of the process associated with the DLL destroyed

Process release DLL

Import and export DLL functions and data

All functions, data and resources must be exported from the DLL:

In the Export section of the library's .def file, fill in the name of the export project

Use tool-related methods, such as __declspec (dllexport) keywords in VC

DEF: It is more important in 16 Windows development, not so important at 32-bit

For 32-bit DLL, it includes at least two library and exports

Export symbols in the DEF file:

If the user wants to use the export section of the DEF:

You can use the DLL as C work and compile to close Name Mangling

Or fill in Exports or through the information in MAP

Loading a DLL during loading

Implicit load: When you start executing EXE, Winows2000 is responsible for finding the DLL you need to apply,

And the address resolution is responsible for each DLL call.

Import library when link

Running DLL

LoadLibrary (), getProcaddress (), FreeELibrary ()

DLL version control

Create a DLL shared memory

Using the Sections keyword in DEF, the user can define the memory area used by the DLL as shared.

Place the shared memory in the area (by compiling indication) and initialize

Use MFC and DLL

Dynamic link regular DLL

DLL and MFC DLL dynamic link

Static link regular DLL

DLL and MFC DLL static link

Expand DLL (most common)

DLL expands the MFC library

转载请注明原文地址:https://www.9cbs.com/read-116936.html

New Post(0)