windows 为什么 .dll 文件中会出现“此程序无法在 DOS 模式下运行”文本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2577545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is "This program cannot be run in DOS mode" text present in .dll files?
提问by sharptooth
Recently I opened a .dll file produced by Visual Studio 9 while compiling a native C++ DLL project and was surprised to see the "This program cannot be run in DOS mode" text near the beginning.
最近我在编译本机 C++ DLL 项目时打开了一个由 Visual Studio 9 生成的 .dll 文件,并惊讶地看到开头附近的“此程序无法在 DOS 模式下运行”文本。
Why have this text in .dll files?
为什么在 .dll 文件中有此文本?
采纳答案by lexu
A dll is very much like an executable with a different extension. The text you saw is part of the 'standard' executable header on windows. It is (was) used to gracefully abort the attempt to run a windows executable from DOS.
dll 非常类似于具有不同扩展名的可执行文件。您看到的文本是 Windows 上“标准”可执行文件头的一部分。它(曾经)用于优雅地中止从 DOS 运行 Windows 可执行文件的尝试。
回答by Petr Hude?ek
The Portable Executable format specification states the following:
Portable Executable 格式规范声明如下:
The MS-DOS stub is a valid application that runs under MS-DOS. It is placed at the front of the EXE image. The linker places a default stub here, which prints out the message “This program cannot be run in DOS mode.” when the image is run in MS-DOS. The user can specify a different stub by using the /STUB linker option.
At location 0x3c, the stub has the file offset to the PE signature. This information enables Windows to properly execute the image file, even though it has an MS-DOS stub. This file offset is placed at location 0x3c during linking.
MS-DOS 存根是在 MS-DOS 下运行的有效应用程序。它位于 EXE 图像的前面。链接器在此处放置一个默认存根,它会打印出消息“此程序不能在 DOS 模式下运行”。当图像在 MS-DOS 中运行时。用户可以使用 /STUB 链接器选项指定不同的存根。
在位置 0x3c,存根具有到 PE 签名的文件偏移量。此信息使 Windows 能够正确执行映像文件,即使它具有 MS-DOS 存根。在链接期间,此文件偏移量位于位置 0x3c。
回答by nategoose
Win32 programs run from DOS mode (ie, single user, no graphics) print that text. DLLs probably print that message too if you try to use them without Windows running.
Win32 程序在 DOS 模式下运行(即单用户,无图形)打印该文本。如果您尝试在不运行 Windows 的情况下使用 DLL,则它们也可能会打印该消息。