Windows versions¶
i8086-pc-win16 with no version makes programs for protected mode, the
only mode of Windows 3.1 and later: the NE header expects Windows 3.0 and
is marked protected mode only, so Windows 3.0 runs the program in standard
or 386 enhanced mode and refuses to start it in real mode. A version after
win16 sets the version the header expects, and Windows refuses a program
that expects a newer one. The minor version has two digits, as Windows
writes it: 3.10 is Windows 3.1.
| Triple | Windows | Header |
|---|---|---|
i8086-pc-win16 |
3.0 (standard, 386 enhanced), 3.1, 3.11, 9x, NT | expects 3.0, protected mode only |
i8086-pc-win163.10 |
3.1 and later | expects 3.10, protected mode only |
i8086-pc-win163.00 |
3.0 in any mode, 3.1 and later | expects 3.0, real-mode safe |
i8086-pc-win162.03 |
2.x (2.03, 2.1, /286, /386), 3.x | expects 2.03, real-mode safe |
i8086-pc-win161.01 |
1.x, 2.x, 3.x | expects 1.01, real-mode safe |
Windows 3.x gives a program that expects a version before 3.0 the fixed system font it was made for, and Windows 3.0 warns before it starts one.
Before 3.10 a program must also work in real mode, which Windows 1.x and
2.x always use and Windows 3.0 uses on an 8086 or with win /r. Real-mode
Windows moves and discards segments to make room, and only updates the
references it knows about: entry points, far pointers to them, and the
frames on the stack. So for these versions:
- Code segments are fixed, so they never move, and so are data segments in
the compact and large models and in DLLs, where far pointers or code
hold the data segment's address. clang asks the linker for this
explicitly, although JWlink and wlink make a program's segments fixed
unless told otherwise; a
-Wl,segmentdirective that makes code moveable breaks real mode. - Every far call is a single far-pointer relocation (also in the other targets), which real-mode Windows points at a thunk that loads the target's segment if it was discarded.
- A program lists only the modules it imports from. (JWlink used to list
every module named in
windows.lnk, so every program needed SHELL, TOOLHELP, MMSYSTEM and the other Windows 3.1 DLLs to load. This needs the fix in clang-dos/jwlink#3.) - Before Windows 3.0, Windows loads an imported module from
MODULE.EXE, notMODULE.DLL, so name a DLL for Windows 1.x and 2.xMYLIB.EXE(clang -shared ... -o MYLIB.EXE). tools/ne-check.py --real-mode PROGRAM.EXEchecks a program for this: no moveable code, no protected-mode flag, and no separate segment or offset relocation to an import or a moveable segment.--version 2.03checks the expected version and--protmodethe flag. It also lists the imported modules, and notes the ones that came with Windows 3.1 (SHELL, COMMDLG, TOOLHELP, VER, LZEXPAND, MMSYSTEM, ...).
The API follows the version too:
__WIN16_VERSION__is the version from the triple (0x0203forwin162.03,0x030Awithout one), and<windows.h>makes itWINVERunless the program sets that itself. Functions that came later are not declared (GetWinFlags,wsprintfandlstrcmpineed 3.0, for one).- clang links a program for 1.x with
lib/win16/windows100.lnk, one for 2.x withwindows200.lnkand one for 3.0 withwindows300.lnk, which have the functions of that version, so a call to one that came later fails to link instead of failing to load on the old Windows. They also import the functions where the old version has them: in 1.x and 2.x,AnsiNext,AnsiPrev,AnsiUpper,AnsiLowerandlstrcmpare KERNEL functions (Windows 3.0 moved them to USER), and up to 3.0RectVisibleis GDI.104, not GDI.465. The lists come from the import libraries of the Windows 1.04, 2.03 and 3.0 SDKs (SLIBW.LIB,LIBW.LIB):python3 tools/gen-win16-imports.py --from-lib <SDK>/LIB/SLIBW.LIB <wine-src>/dlls. (The 1.01 and 1.03 SDKs have the same list as 1.04.) llvm-rc -win16-version 2.03(orllvm-windres --target=i8086-pc-win162.03) writes resources for Windows 1.x and 2.x, and its preprocessor sees the sameWINVER. Menus have no header and a byte of flags per item. Icons, cursors and bitmaps are the files of the 1.x and 2.x SDK's icon editor (ICONEDIT), each one resource, with no icon or cursor groups; a Windows 3.x.ico,.curor.bmpfile is refused. Dialogs have noFONTor combo boxes, which it refuses too, and aLISTBOXis sorted and has a scroll bar (LBS_STANDARD) unless its style says otherwise, as the old resource compilers make it. Menus, dialogs, strings, accelerators, raw data, icons, cursors and bitmaps come out byte for byte as the resource compilers of the 1.04 and 2.03 SDKs write them, run in DOSBox, on the samples of the 2.03 SDK. Where they differ, the 2.03 one is wrong: it leaves the last two bytes off a bitmap (llvm-rc writes all of it, as the 1.04 one does), and gives aLISTBOXthe text of the control before it. The old compilers let a script leave out commas, as inCTEXT "Hello" -1, 0, 5, 154, 8, which llvm-rc does not; add them. Wine does not load 1.x and 2.x icons, cursors or bitmaps, so these are checked as data only.
All of this is checked only in Wine, which runs every 16-bit program in protected mode (it does load imported modules and reads menus the way the expected version says, and reports the closest Windows version it has); the programs have not been run on real Windows 1.x, 2.x or 3.0.