Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a file both be an executable (EXE) and a dynamic-link library (DLL) at the same time?

Tags:

c++

windows

dll

exe

Is it possible for a file to be both an executable (EXE) and a dynamic-link library (DLL) at the same time? (I.e. it can be executed as an EXE and loaded at run-time as a shared library.)

I can't see why it shouldn't be possible, but maybe someone can give an explanation?

like image 456
Shuzheng Avatar asked Aug 24 '16 19:08

Shuzheng


People also ask

Can a EXE link to DLL and static library at the same time?

Yes, the Core and Utils code will be duplicated. Instead of building them as static libs you can build them as dlls and use anywhere.

What is the difference between an executable .exe file and a library .DLL file?

Difference between exe and dll-1. EXE is an extension used for executable files while DLL is the extension for a dynamic link library. 2.An EXE file can be run independently while a DLL is used by other applications. 3.An EXE file defines an entry point while a DLL does not.

Can a DLL be an executable?

A DLL file is not by it self executable, though it may contain executable code. A DLL (Dynamic-Link Library) contains code, data, resources etc. usable by other programs. You need an EXE file for the operating system to execute code within DLL files, like "RUNDLL.

What is a dynamic link library (DLL)?

What is a dynamic link library (DLL)? A dynamic link library (DLL) is a collection of small programs that larger programs can load when needed to complete specific tasks. The small program, called a DLL file, contains instructions that help the larger program handle what may not be a core function of the original program.

How do I link a DLL to an executable file?

An executable file links to (or loads) a DLL in one of two ways: Implicit linking, where the operating system loads the DLL when the executable using it is loaded. Explicit linking, where the operating system loads the DLL on demand at runtime.

What are the two methods of linking DLLs?

The two methods of linking are load-time dynamic linking and run-time dynamic linking. In load-time dynamic linking, an application makes explicit calls to exported DLL functions like local functions. To use load-time dynamic linking, provide a header (.h) file and an import library (.lib) file when you compile and link the application.

What is the difference between an EXE and a DLL?

What is the difference between an EXE and a DLL and how is it getting generated? If an assembly is compiled as a class library and provides types for other assemblies to use, then it has the file extension .dll (dynamic link library),


1 Answers

From LoadLibrary documentation:

The name of the module. This can be either a library module (a .dll file) or an executable module (an .exe file). The name specified is the file name of the module and is not related to the name stored in the library module itself, as specified by the LIBRARY keyword in the module-definition (.def) file.

EDIT: I expected downvotes when I wrote this answer. I know many people think it is not possible (SO questions and answers from comments confirm it). But for those who are interested I can provide POC (or simply look at well known "process explorer" sources)

Note that if you need to export symbols from module you need to use those EXPORT statements in .def file. Then you can use GetProcAddress

Actually, I see that this SO question, also mentioned in comments, has answer that points to article "Load EXE as DLL: Mission Possible", which I also was going to quote. That answer is not accepted, accepted answer says "no" and even is taken as community wiki. Well "SO doesn't claim to be (in part) a library reference"

like image 107
mvidelgauz Avatar answered Sep 27 '22 16:09

mvidelgauz