Monday, 9 April 2012

Difference between DLL and EXE Files

.exe is an executable program while .dll is dynamic link library.

Both are assemblies. So whatever the difference lies between program and library, same is between .exe and .dll like:

1. .dll can be shared with many .exe files. Basically it's an external code repository for .exe programs. Since usually several different programs reuse the same DLL instead of having that code in their own file, this dramatically reduces required storage space.

2. Both files are PE (Portable Executable) files. Both contain the exact same layout. A DLL is a library and therefore cannot be executed. If you try to run it you'll get an error about a missing entry point (main function).  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). So, .exe files are used for launching an application (it contains a startup function), whereas DLLs are loaded into an application (i.e. they can't run by themselves).

3. Only one .exe file exists per application but there can be many dlls in applications.

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.

No comments:

Post a Comment