且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么是DLL文件,它们如何工作?

更新时间:2023-11-22 23:46:28

什么是DLL?

动态链接库(DLL)类似于EXE,但不能直接执行。它们与Linux / Unix中的.so文件类似。也就是说,DLL是MS实现的共享库。

Dynamic Link Libraries (DLL)s are like EXEs but they are not directly executable. They are similar to .so files in Linux/Unix. That is to say, DLLs are MS's implementation of shared libraries.

DLL非常像EXE,文件格式本身是一样的。 EXE和DLL均基于便携式可执行文件(PE)文件格式。 DLL还可以包含COM组件和.NET库。

DLLs are so much like an EXE that the file format itself is the same. Both EXE and DLLs are based on the Portable Executable (PE) file format. DLLs can also contain COM components and .NET libraries.

DLL包含什么?

一个DLL包含EXE或其他DLL使用的功能,类,变量,UI和资源(如图标,图像,文件...)。

A DLL contains functions, classes, variables, UIs and resources (such as icons, images, files, ...) that an EXE, or other DLL uses.

库的类型

在几乎所有的操作系​​统上,有两种类型的库。静态库和动态库。在Windows中,文件扩展名如下:静态库(.lib)和动态库(.dll)。主要的区别是静态库在编译时被链接到可执行文件;而动态链接库直到运行时才被链接。

On virtually all operating systems, there are 2 types of libraries. Static libraries and dynamic libraries. In windows the file extensions are as follows: Static libraries (.lib) and dynamic libraries (.dll). The main difference is that static libraries are linked to the executable at compile time; whereas dynamic linked libraries are not linked until run-time.

有关静态和动态库的更多信息:

在计算机上通常不会看到静态库,因为静态库直接嵌入在模块(EXE或DLL)内。动态库是一个独立文件。

You don't normally see static libraries though on your computer, because a static library is embedded directly inside of a module (EXE or DLL). A dynamic library is a stand-alone file.

可以随时更改DLL,只有当EXE显式加载DLL时,才会在运行时加载DLL。一旦在EXE中编译,静态库就无法更改。
可以在不更新EXE本身的情况下单独更新DLL。

A DLL can be changed at any time and is only loaded at runtime when an EXE explicitly loads the DLL. A static library cannot be changed once it is compiled within the EXE. A DLL can be updated individually without updating the EXE itself.

加载DLL:

程序在启动时通过Win32 API LoadLibrary加载DLL,或者当它是另一个DLL的依赖项时加载DLL。程序使用GetProcAddress加载一个函数或LoadResource来加载资源。

A program loads a DLL at startup, via the Win32 API LoadLibrary, or when it is a dependency of another DLL. A program uses the GetProcAddress to load a function or LoadResource to load a resource.

进一步阅读:

请检查 MSDN ***进一步阅读。也是这个答案的来源。

Please check MSDN or Wikipedia for further reading. Also the sources of this answer.