Difference between .dll and .exe?

后端 未结 15 1080
有刺的猬
有刺的猬 2020-12-02 04:23

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

相关标签:
15条回答
  • 2020-12-02 05:05

    The .exe is the program. The .dll is a library that a .exe (or another .dll) may call into.

    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. 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.

    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.

    Using Win32 APIs, a program can load and use a DLL using the LoadLibrary and GetProcAddress API functions, IIRC. There were similar functions in 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. DLLs have been around since 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.

    0 讨论(0)
  • 2020-12-02 05:07

    EXE:

    1. It's a executable file
    2. When loading an executable, no export is called, but only the module entry point.
    3. When a system launches new executable, a new process is created
    4. The entry thread is called in context of main thread of that process.

    DLL:

    1. It's a Dynamic Link Library
    2. There are multiple exported symbols.
    3. The system loads a DLL into the context of an existing process.

    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

    Reference: http://www.dotnetspider.com/forum/34260-What-difference-between-dll-exe.aspx

    0 讨论(0)
  • 2020-12-02 05:07

    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.

    0 讨论(0)
  • 2020-12-02 05:08

    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.

    0 讨论(0)
  • 2020-12-02 05:11

    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.

    0 讨论(0)
  • 2020-12-02 05:12

    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.

    • Likewise, if an assembly is compiled as an application, then it has the file extension .exe (executable) and can be executed standalone. 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. - Source

    0 讨论(0)
提交回复
热议问题