c++ - 文件能否同时是可执行文件 (EXE) 和动态链接库 (DLL)?

标签 c++ windows dll exe

文件是否可以同时是可执行文件 (EXE) 和动态链接库 (DLL)? (即它可以作为 EXE 文件执行并在运行时作为共享库加载。)

我不明白为什么不可能,但也许有人可以给出解释?

最佳答案

来自 LoadLibrary 文档:

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.

编辑:当我写这个答案时,我预计会有反对票。我知道很多人认为这是不可能的(所以评论中的问题和答案证实了这一点)。但是对于那些感兴趣的人,我可以提供 POC(或者简单地查看众所周知的“流程浏览器”资源)

请注意,如果您需要从模块中导出符号,则需要在 .def 文件中使用这些 EXPORT 语句。然后就可以使用GetProcAddress

实际上,我看到评论中也提到了这个 SO question 的答案指向文章 "Load EXE as DLL: Mission Possible" ,我也打算引用它。该答案不被接受,接受的答案说“不”,甚至被视为社区维基。嗯 "SO doesn't claim to be (in part) a library reference"

关于c++ - 文件能否同时是可执行文件 (EXE) 和动态链接库 (DLL)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39131185/

相关文章:

c++ - 在 GameStart 上更改 GameMode

.net - 安装 3.5 后卸载 .NET Framework 2.0 和 1.0 是否安全?

c++ - 基本 dll 地址总是不同且哈希不匹配

C# dll 求解简单方程

c++ - 在 OpenGL 中加载纹理时颜色错误

c++ - 引用预定义的 QMediaPlayer

c++ - 我需要初始化 std::string 吗

c++ - 类错误 : argument of type 'DWORD (windows_thread::)(void*)' does not match 'DWORD (*)(void*)' ? 中的 CreateThread

c++ - win32::WaitForSingleObject 期间 Windows 上的 Boost.Thread 断言/崩溃

wpf - 从 ViewPort 中删除 ScreenSpaceLines3D 对象?