[英]Difference between .dll and .exe?
我想知道 dll 和 exe 文件之间的确切区别。
I don't know why everybody is answering this question in context of .NET.我不知道为什么每个人都在 .NET 的上下文中回答这个问题。 The question was a general one and didn't mention .NET anywhere.
这个问题很笼统,并没有在任何地方提到 .NET。
Well, the major differences are:嗯,主要的区别是:
EXE可执行程序
DLL动态链接库
The file format of DLL and exe is essentially the same. DLL 和 exe 的文件格式本质上是一样的。 Windows recognizes the difference between DLL and EXE through PE Header in the file.
Windows 通过文件中的 PE Header 来识别 DLL 和 EXE 之间的区别。 For details of PE Header, You can have a look at this Article on MSDN
有关 PE Header 的详细信息,您可以查看 MSDN 上的这篇文章
EXE:可执行程序:
DLL:动态链接库:
For More Details: http://www.c-sharpcorner.com/Interviews/Answer/Answers.aspxQuestionId=1431&MajorCategoryId=1&MinorCategoryId=1 http://wiki.answers.com/Q/What_is_the_difference_between_an_EXE_and_a_DLL更多详情: http : //www.c-sharpcorner.com/Interviews/Answer/Answers.aspxQuestionId=1431&MajorCategoryId=1&MinorCategoryId=1 http://wiki.answers.com/Q/What_is_the_difference_between_an_EXE_and_a_DLL
Reference: http://www.dotnetspider.com/forum/34260-What-difference-between-dll-exe.aspx参考: http : //www.dotnetspider.com/forum/34260-What-difference-between-dll-exe.aspx
The difference is that an EXE has an entry point, a "main" method that will run on execution.不同之处在于 EXE 有一个入口点,一个将在执行时运行的“主”方法。
The code within a DLL needs to be called from another application. DLL 中的代码需要从另一个应用程序调用。
There are a few more differences regarding the structure you could mention.关于您可以提到的结构,还有一些不同之处。
Characteristics
member of IMAGE_FILE_HEADER
inside IMAGE_NT_HEADERS
.IMAGE_NT_HEADERS
中IMAGE_FILE_HEADER
的Characteristics
成员。 For a DLL, it has the IMAGE_FILE_DLL
(0x2000) flag turned on.IMAGE_FILE_DLL
(0x2000) 标志。 For a EXE it's the IMAGE_FILE_EXECUTABLE_IMAGE
(0x2) flag.IMAGE_FILE_EXECUTABLE_IMAGE
(0x2) 标志。IMAGE_OPTIONAL_HEADER
) is the ImageBase
member.IMAGE_OPTIONAL_HEADER
) 中还有ImageBase
成员。 It specifies the virtual address at which the PE assumes it will be loaded..reloc
..reloc
。 This directory contains a list of places in the DLL that need to be rebased/patched so they'll point to the right memory. You can read more on this topic @ MSDN .您可以在@MSDN上阅读有关此主题的更多信息。
This answer was a little more detailed than I thought but read it through.这个答案比我想象的要详细一些,但请通读一遍。
DLL:动态链接库:
In most cases, a DLL file is a library .在大多数情况下,DLL 文件是一个库. There are a couple of types of libraries, dynamic and static - read about the difference .
有几种类型的库,动态的和静态的 - 阅读区别。 DLL stands for dynamic link library which tells us that it's a part of the program but not the whole thing.
DLL 代表动态链接库,它告诉我们它是程序的一部分,而不是整个程序。 It's made of reusable software components ( library ) which you could use for more than a single program .
它由可重用的软件组件(库)组成,您可以将其用于多个程序。 Bear in mind that it's always possible to use the library source code in many applications using copy-paste, but the idea of a DLL/Static Library is that you could update the code of a library and at the same time update all the applications using it - without compiling.
请记住,始终可以使用复制粘贴在许多应用程序中使用库源代码,但 DLL/静态库的想法是您可以更新库的代码,同时使用它 - 无需编译。
For example:例如:
Imagine you're creating a Windows GUI component like a Button .想象一下,您正在创建一个类似于Button的Windows GUI 组件。 In most cases you'd want to re-use the code you've written because it's a complex but a common component - You want many applications to use it but you don't want to give them the source code You can't copy-paste the code for the button in every program, so you decide you want to create a DL-Library (DLL) .
在大多数情况下,您希望重新使用您编写的代码,因为它是一个复杂但通用的组件 - 您希望许多应用程序使用它,但又不想向它们提供源代码 您无法复制- 在每个程序中粘贴按钮的代码,以便您决定要创建一个DL-Library (DLL) 。
This "button" library is required by EXE cutables to run, and without it they will not run because they don't know how to create the button, only how to talk to it.这个“按钮”库是EXE cutables 运行所必需的,没有它它们将无法运行,因为它们不知道如何创建按钮,只知道如何与它对话。
Likewise, a DLL cannot be executed - run, because it's only a part of the program but doesn't have the information required to create a "process" .同样,DLL 不能被执行 - 运行,因为它只是程序的一部分,但没有创建“进程”所需的信息。
EXE:可执行程序:
An executable is the program .可执行文件是程序。 It knows how to create a process and how to talk to the DLL.
它知道如何创建进程以及如何与 DLL 对话。 It needs the DLL to create a button, and without it the application doesn't run - ERROR.
它需要DLL 来创建一个按钮,如果没有它,应用程序将无法运行 - 错误。
hope this helps....希望这可以帮助....
Both DLL and EXE are Portable Executable(PE) Formats DLL 和 EXE 都是可移植的可执行 (PE) 格式
A Dynamic-link library (DLL) is a library and therefore can not be executed directly.动态链接库 (DLL)是一个库,因此不能直接执行。 If you try to run it you will get an error about a missing entry point.
如果您尝试运行它,您将收到有关缺少入口点的错误。 It needs an entry point (main function) to get executed, that entry point can be any application or exe.
它需要一个入口点(主函数)来执行,入口点可以是任何应用程序或 exe。 DLL binding occurs at run-time.
DLL 绑定发生在运行时。 That is why its called "Dynamic Link" library.
这就是为什么它被称为“动态链接”库。
An Executable (EXE) is a program that can be executed.可执行文件 (EXE)是可以执行的程序。 It has its own entry point.
它有自己的入口点。 A flag inside the PE header indicates which type of file it is (irrelevant of file extension).
PE 标头内的标志指示它是哪种类型的文件(与文件扩展名无关)。 The PE header has a field where the entry point for the program resides.
PE 标头有一个字段,程序的入口点位于该字段中。 In DLLs it isn't used (or at least not as an entry point).
在 DLL 中不使用它(或至少不用作入口点)。
There are many software available to check header information.有许多软件可用于检查标题信息。 The only difference causing both to work differently is the bit in header as shown in below diagram.
导致两者工作方式不同的唯一区别是标题中的位,如下图所示。
EXE file has only single main entry means it is isolated application, when a system launches exe, a new process is created while DLLs have many entry points so when application use it no new process started, DLL can be reused and versioned. EXE 文件只有一个主入口意味着它是一个独立的应用程序,当系统启动 exe 时,会创建一个新进程,而 DLL 有许多入口点,因此当应用程序使用它时,不会启动新进程,DLL 可以重用和版本化。 DLL reduces storage space as different programs can use the same dll.
DLL 减少了存储空间,因为不同的程序可以使用相同的 dll。
Dll v/s Exe dll v/s exe
1)DLL file is a dynamic link library which can be used in exe files and other dll files. 1)DLL文件是一个动态链接库,可以在exe文件和其他dll文件中使用。
EXE file is a executable file which runs in a separate process which is managed by OS. EXE 文件是一个可执行文件,它在由操作系统管理的单独进程中运行。
2)DLLs are not directly executable . 2)DLL 不能直接执行。 They are separate files containing functions that can be called by programs and other DLLs to perform computations and functions.
它们是单独的文件,其中包含可由程序和其他 DLL 调用以执行计算和函数的函数。
An EXE is a program that can be executed . EXE 是可以执行的程序。 Ex :Windows program
例如:Windows 程序
3)Reusability 3)可重用性
DLL: They can be reused for some other application. DLL:它们可以重用于其他应用程序。 As long as the coder knows the names and parameters of the functions and procedures in the DLL file .
只要编码人员知道 DLL 文件中的函数和过程的名称和参数。
EXE: Only for specific purpose . EXE:仅用于特定目的。
4)A DLL would share the same process and memory space of the calling application while an 4) DLL 将共享调用应用程序的相同进程和内存空间,而
EXE creates its separate process and memory space. EXE 创建其单独的进程和内存空间。
5)Uses 5)用途
DLL: You want many applications to use it but you don't want to give them the source code You can't copy-paste the code for the button in every program, so you decide you want to create a DL-Library (DLL). DLL:您希望许多应用程序使用它,但又不想向它们提供源代码 您无法在每个程序中复制粘贴按钮的代码,因此您决定要创建一个 DL-Library (DLL )。
EXE: When we work with project templates like Windows Forms Applications, Console Applications, WPF Applications and Windows Services they generate an exe assembly when compiled. EXE:当我们使用 Windows 窗体应用程序、控制台应用程序、WPF 应用程序和 Windows 服务等项目模板时,它们会在编译时生成一个 exe 程序集。
6)Similarities : 6)相似之处:
Both DLL and EXE are binary files have a complex nested structure defined by the Portable Executable format, and they are not intended to be editable by users. DLL 和 EXE 都是二进制文件,具有由 Portable Executable 格式定义的复杂嵌套结构,并且它们不能被用户编辑。
Two things: the extension and the header flag stored in the file.两件事:文件中存储的扩展名和标头标志。
Both files are PE files.这两个文件都是PE文件。 Both contain the exact same layout.
两者都包含完全相同的布局。 A DLL is a library and therefore can not be executed.
DLL 是一个库,因此无法执行。 If you try to run it you'll get an error about a missing entry point.
如果您尝试运行它,您将收到有关缺少入口点的错误。 An EXE is a program that can be executed.
EXE 是可以执行的程序。 It has an entry point.
它有一个入口点。 A flag inside the PE header indicates which file type it is (irrelevant of file extension).
PE 标头内的标志指示它是哪种文件类型(与文件扩展名无关)。 The PE header has a field where the entry point for the program resides.
PE 标头有一个字段,程序的入口点位于该字段中。 In DLLs it isn't used (or at least not as an entry point).
在 DLL 中不使用它(或至少不用作入口点)。
One minor difference is that in most cases DLLs have an export section where symbols are exported.一个微小的区别是,在大多数情况下, DLL都有一个导出部分,用于导出符号。 EXEs should never have an export section since they aren't libraries but nothing prevents that from happening.
EXE 永远不应该有导出部分,因为它们不是库,但没有什么可以阻止这种情况发生。 The Win32 loader doesn't care either way.
Win32 加载程序不关心任何一种方式。
Other than that they are identical.除此之外,它们是相同的。 So, in summary, EXEs are executable programs while DLLs are libraries loaded into a process and contain some sort of useful functionality like security, database access or something.
因此,总而言之,EXE 是可执行程序,而 DLL 是加载到进程中的库,包含某种有用的功能,例如安全性、数据库访问等。
The .exe is the program. .exe 是程序。 The .dll is a library that a .exe (or another .dll) may call into.
.dll 是一个 .exe(或另一个 .dll)可以调用的库。
What sakthivignesh says can be true in that one .exe can use another as if it were a library, and this is done (for example) with some COM components. sakthivignesh 所说的可能是正确的,因为一个 .exe 可以像使用库一样使用另一个 .exe,并且这是(例如)使用某些 COM 组件完成的。 In this case, the "slave" .exe is a separate program (strictly speaking, a separate process - perhaps running on a separate machine), but one that accepts and handles requests from other programs/components/whatever.
在这种情况下,“从” .exe 是一个单独的程序(严格来说,一个单独的进程 - 可能运行在一台单独的机器上),但它接受和处理来自其他程序/组件/任何东西的请求。
However, if you just pick a random .exe and .dll from a folder in your Program Files, odds are that COM isn't relevant - they are just a program and its dynamically-linked libraries.但是,如果您只是从 Program Files 中的文件夹中随机选择一个 .exe 和 .dll,则很可能与 COM 无关——它们只是一个程序及其动态链接的库。
Using Win32 APIs, a program can load and use a DLL using the LoadLibrary and GetProcAddress API functions, IIRC.使用 Win32 API,程序可以使用 LoadLibrary 和 GetProcAddress API 函数 IIRC 加载和使用 DLL。 There were similar functions in Win16.
Win16中也有类似的功能。
COM is in many ways an evolution of the DLL idea, originally concieved as the basis for OLE2, whereas .NET is the descendant of COM. COM 在许多方面是 DLL 思想的演变,最初被认为是 OLE2 的基础,而 .NET 是 COM 的后代。 DLLs have been around since Windows 1, IIRC.
DLL 从 Windows 1、IIRC 开始就已经存在。 They were originally a way of sharing binary code (particularly system APIs) between multiple running programs in order to minimise memory use.
它们最初是一种在多个正在运行的程序之间共享二进制代码(特别是系统 API)以最小化内存使用的方式。
An EXE is visible to the system as a regular Win32 executable. EXE 作为常规 Win32 可执行文件对系统可见。 Its entry point refers to a small loader which initializes the .NET runtime and tells it to load and execute the assembly contained in the EXE.
它的入口点是指一个小的加载器,它初始化 .NET 运行时并告诉它加载和执行包含在 EXE 中的程序集。 A DLL is visible to the system as a Win32 DLL but most likely without any entry points.
DLL 作为 Win32 DLL 对系统可见,但很可能没有任何入口点。 The .NET runtime stores information about the contained assembly in its own header.
.NET 运行时将有关包含的程序集的信息存储在其自己的标头中。
dll is a collection of reusable functions where as an .exe is an executable which may call these functions
dll 是可重用函数的集合,其中 .exe 是可以调用这些函数的可执行文件
exe 是可执行程序,而 DLL 是可以由程序动态加载和执行的文件。
● .exe and dll are the compiled version of c# code which are also called as assemblies. ● .exe 和 dll 是 C# 代码的编译版本,也称为程序集。
● .exe is a stand alone executable file, which means it can executed directly. ● .exe 是一个独立的可执行文件,这意味着它可以直接执行。
● .dll is a reusable component which cannot be executed directly and it requires other programs to execute it. ● .dll 是一个可重用的组件,不能直接执行,需要其他程序来执行。
For those looking a concise answer,对于那些寻求简洁答案的人,
If an assembly is compiled as a class library and provides types for other assemblies to use, then it has the ifle extension .dll
(dynamic link library), and it cannot be executed standalone.如果程序集编译为类库并提供类型供其他程序集使用,则它具有 ifle 扩展名
.dll
(动态链接库),并且不能独立执行。
Likewise, if an assembly is compiled as an application, then it has the file extension .exe
(executable) and can be executed standalone.同样,如果程序集被编译为应用程序,则它的文件扩展名为
.exe
(可执行文件)并且可以独立执行。 Before .NET Core 3.0, console apps were compiled to .dll fles and had to be executed by the dotnet run command or a host executable.在 .NET Core 3.0 之前,控制台应用程序被编译为 .dll 文件,并且必须由 dotnet run 命令或主机可执行文件执行。 - Source
- 来源
1) DLL is an In-Process Component which means running in the same memory space as the client process. 1) DLL 是进程内组件,这意味着与客户端进程在相同的内存空间中运行。 EXE is an Out-Process Component which means it runs in its own separate memory space.
EXE 是一个进程外组件,这意味着它在自己独立的内存空间中运行。
2) The DLL contains functions and procedures that other programs can use (promotes reuability) while EXE cannot be shared with other programs. 2) DLL 包含其他程序可以使用的函数和过程(提高可重用性),而 EXE 不能与其他程序共享。
3) DLL cannot be directly executed as they're designed to be loaded and run by other programs. 3) DLL 不能直接执行,因为它们被设计为由其他程序加载和运行。 EXE is a program that is executed directly.
EXE是直接执行的程序。
The major exact difference between DLL and EXE that DLL hasn't got an entry point and EXE does. DLL 和 EXE 之间的主要确切区别在于 DLL 没有入口点而 EXE 有。 If you are familiar with c++ you can see that build EXE has main() entry function and DLL doesn't :)
如果您熟悉 c++,您可以看到 build EXE 具有 main() 入口函数而 DLL 没有 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.