文件是否可以同时是可执行文件 (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/