Difference between .dll and .exe?

2019-01-16 00:48发布

I want to know the exact difference between the dll and exe file.

标签: windows dll exe
13条回答
来,给爷笑一个
2楼-- · 2019-01-16 01:07

Two things: the extension and the header flag stored in the file.

Both files are PE files. Both contain the exact same layout. A DLL is a library and therefore can not be executed. 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. It has an entry point. A flag inside the PE header indicates which file type it is (irrelevant of file extension). The PE header has a field where the entry point for the program resides. In DLLs it isn't used (or at least not as an entry point).

One minor difference is that in most cases DLLs have an export section where symbols are exported. EXEs should never have an export section since they aren't libraries but nothing prevents that from happening. The Win32 loader doesn't care either way.

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.

查看更多
一夜七次
3楼-- · 2019-01-16 01:11

I don't know why everybody is answering this question in context of .NET. The question was a general one and didn't mention .NET anywhere.

Well, the major differences are:

EXE

  1. An exe always runs in its own address space i.e., It is a separate process.
  2. The purpose of an EXE is to launch a separate application of its own.

DLL

  1. A dll always needs a host exe to run. i.e., it can never run in its own address space.
  2. The purpose of a DLL is to have a collection of methods/classes which can be re-used from some other application.
  3. DLL is Microsoft's implementation of a shared library.

The file format of DLL and exe is essentially the same. Windows recognizes the difference between DLL and EXE through PE Header in the file. For details of PE Header, You can have a look at this Article on MSDN

查看更多
太酷不给撩
4楼-- · 2019-01-16 01:12

An EXE is visible to the system as a regular Win32 executable. 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. A DLL is visible to the system as a Win32 DLL but most likely without any entry points. The .NET runtime stores information about the contained assembly in its own header.

dll is a collection of reusable functions where as an .exe is an executable which may call these functions

查看更多
该账号已被封号
5楼-- · 2019-01-16 01:13

The difference is that an EXE has an entry point, a "main" method that will run on execution.

The code within a DLL needs to be called from another application.

查看更多
Summer. ? 凉城
6楼-- · 2019-01-16 01:13

There are a few more differences regarding the structure you could mention.

  1. Both DLL and EXE share the same file structure - Portable Executable, or PE. To differentiate between the two, one can look in the Characteristics member of IMAGE_FILE_HEADER inside IMAGE_NT_HEADERS. For a DLL, it has the IMAGE_FILE_DLL (0x2000) flag turned on. For a EXE it's the IMAGE_FILE_EXECUTABLE_IMAGE (0x2) flag.
  2. PE files consist of some headers and a number of sections. There's usually a section for code, a section for data, a section listing imported functions and a section for resources. Some sections may contain more than one thing. The header also describes a list of data directories that are located in the sections. Those data directories are what enables Windows to find what it needs in the PE. But one type of data directory that an EXE will never have (unless you're building a frankenstein EXE) is the export directory. This is where DLL files have a list of functions they export and can be used by other EXE or DLL files. On the other side, each DLL and EXE has an import directory where it lists the functions and DLL files it requires to run.
  3. Also in the PE headers (IMAGE_OPTIONAL_HEADER) is the ImageBase member. It specifies the virtual address at which the PE assumes it will be loaded. If it is loaded at another address, some pointers could point to the wrong memory. As EXE files are amongst the first to be loaded into their new address space, the Windows loader can assure a constant load address and that's usually 0x00400000. That luxury doesn't exist for a DLL. Two DLL files loaded into the same process can request the same address. This is why a DLL has another data directory called Base Relocation Directory that usually resides in its own section - .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. Most EXE files don't have this directory, but some old compilers do generate them.

You can read more on this topic @ MSDN.

查看更多
在下西门庆
7楼-- · 2019-01-16 01:14

Dll v/s Exe

1)DLL file is a dynamic link library which can be used in exe files and other dll files.
EXE file is a executable file which runs in a separate process which is managed by OS.

2)DLLs are not directly executable . They are separate files containing functions that can be called by programs and other DLLs to perform computations and functions.
An EXE is a program that can be executed . Ex :Windows program

3)Reusability
DLL: They can be reused for some other application. As long as the coder knows the names and parameters of the functions and procedures in the DLL file .
EXE: Only for specific purpose .

4)A DLL would share the same process and memory space of the calling application while an
EXE creates its separate process and memory space.

5)Uses
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).

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.

6)Similarities :
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.

查看更多
登录 后发表回答