Executable stubs can be used by a compiler to create the header section (the beginning section) of an outputted executable by adding the “/stub” switch to the linker.
#pragma comment(linker, "/stub:Stub.exe")
The MSDN Library for MSVC6 has the following to say about it:
The MS-DOS Stub File Name (/STUB:filename) option attaches an MS-DOS stub program to a Win32 program.
A stub program is invoked if the file is executed in MS-DOS. It usually displays an appropriate message; however, any valid MS-DOS application can be a stub program.
Specify a filename for the stub program after a colon (:) on the command line. The linker checks filename to be sure that it is a valid MS-DOS executable file, and issues an error message if the file is not valid. The program must be an .EXE file; a .COM file is invalid for a stub program.
If this option is not used, the linker attaches a default stub program that issues the following message:
This program cannot be run in MS-DOS mode.
For the stub to work in
XP, the following guidelines must be met:
- The stub should be at least 64 bytes long
- The first 2 bytes of the stub (Bytes 0-1) need to be “MZ”
- Bytes 60-63 (4 bytes) are replaced by the compiler (I have a note that you might want to set this to 0x60000000 [big endian] for some reason)
As long as these guidelines are met, the rest of the stub can be whatever you want :-). For
Small Projects, you can even put information here like strings for the executable, which are accessible through the executable virtual address space starting at 0x400000.