• Please review our updated Terms and Rules here

WIN32s and WIN32 command line programs

bocke

Experienced Member
Joined
Mar 28, 2016
Messages
68
Location
Belgrade, Serbia
People claim WIN32s doesn't support WIN32 console applications. This is partially true. As Windows 3.1 doesn't have appropriate subsystem, they are only stubbed in WIN32s. The main effect of this is that console applications don't have any output (no stdout or stderr). But that doesn't mean they can't "run".

I came to this conclusion after seeing nconvert (a win32 console application) in the list of WIN32s compatible software from Stephan Großklaß (nowadays maintained by Gabby Chaudry) and then trying a few older WIN32 command line tools. An older version of gzip compiled for NT 3.1 worked, Zip 5.31 for WIN95 worked, Rar 2.00 worked. 7za (7-zip) didn't work. Rar 2.90-4.20 didn't work.

7za didn't work because relocations were stripped from the binary. WIN32s supports only WIN32 binaries with .reloc section. Rar (for WIN32) after 2.90 didn't work as some kernel function was not implemented in WIN32s.

The way this works... Windows apps can't be started from DOS prompt, but they can be started from Windows apps. The most convenient would be a command line program like TakeCommand/16 (formerly shareware, now freeware):

krnl386_002.pngkrnl386_003.png

The first image shows compressing files with rar. The second image shows decompressing files from a zip archive. While the programs don't output anything, they do what they are supposed to.

Another example: Using Digital Mars compiler to compile a simple C program.
krnl386_000.png

Funnily enough, by default, the generated program is WIN32 console app. So, you can't actually see "Hello World!". But it seems to run. This needs further testing, but it seems Digital Mars C compiler output (at least in WIN32 console mode) is by default WIN32s compatible. :)

I ran the binary on a more complete WIN32 platform (in this case WINE 10.0RC3) and "Hello World!" is there.

hello.png

Of course, the biggest problem with using WIN32 console apps here is the missing output which makes debugging really awkward.

For open source applications that might not be such a big problem as you can easily hack most programs to output stderr and stdin into a file on disk. Or you can solve it in a way contemporary compilers for WIN16 solved the problem of porting command line programs to WIN16 - by using a stdio wrapper that redirects all output into a window. Both Microsoft and Borland had their own solutions that came with their respective compilers. There were also 3rd party implementations.

For compiling WIN32s programs you can use Open Watcom or Digital Mars C/C++. Or one of contemporary development environments. LCC-WIN32 did, at some time, unofficially support generating WIN32s apps. MinGW32 was used to compile some WIN32s ports at the time, although this is largely undocumented. Borland's free command line tools (BCC 5.5) released in early 2000 are also WIN32s compatible.

Anyway, after this short exploration I can conclude that WIN32 console apps work on WIN32s, but don't have any output. Those that don't work either don't have .reloc section or use something that is not available in WIN32s. The tools from 90s are more likely to work than modern WIN32 tools as in example of Rar WIN32 command line utility.

I have seen claims to otherwise so I decided to document this somewhere where people could find it when searching for information on this.

How to see if WIN32 console app might be supported under WIN32s? You can use an EXE exploring or dumping program. I use Semblance Disassembler as it lets me easily see the basic file and platform data. But you can use any tool you like or suits you. Semblance might have advantage only in that it also show information on relocations inside the executable which some other tools might not show (at least by default).

This is the output of dump -f Rar.exe on Rar 2.60:
Code:
File: Rar.exe
Module type: PE (Portable Executable)
Module name: rar.exe

Flags: 0x818e (executable, line numbers stripped, local symbols stripped, little-endian, 32-bit, big-endian)
Image type: 32-bit
File version: 0.0
Linker version: 2.25
Program entry point: 0x401000
Base of code section: 0x1000
Base of data section: 0x27000
Preferred base address: 0x400000
Required OS version: 1.0
Subsystem: CUI
Subsystem version: 3.10
DLL flags: 0x0000 ()
Stack size (reserve): 1048576 bytes
Stack size (commit): 8192 bytes
Heap size (reserve): 1048576 bytes
Heap size (commit): 4096 bytes

Here we don't get any information on stripped relocations. This means this binary might work on WIN32s.

This is the output of dump ran on 7z.exe from 7zip 4.60:
Code:
File: 7z.exe
Module type: PE (Portable Executable)

Flags: 0x010f (relocations stripped, executable, line numbers stripped, local symbols stripped, 32-bit)
Image type: 32-bit
File version: 0.0
Linker version: 6.0
Program entry point: 0x41a6f6
Base of code section: 0x1000
Base of data section: 0x1e000
Preferred base address: 0x400000
Required OS version: 4.0
Subsystem: CUI
Subsystem version: 4.0
DLL flags: 0x0000 ()
Stack size (reserve): 1048576 bytes
Stack size (commit): 4096 bytes
Heap size (reserve): 1048576 bytes
Heap size (commit): 4096 bytes

We can clearly see that the relocations are stripped. This binary won't work on WIN32s.
 
VC6, which 7z is compiled with, doesn't issue "/fixed:no" by default. as a result, there is no reloc section will be written into result binary.
 
BearWindows has a very detailed write-up on WIN32s support in different versions of VC++:

This page actually also document how to generate WIN32s binaries with MinGW:
MinGW/gcc can automaticly generate .reloc section only for dll libraries. But there is a special key -pie or --pic-executable to make position independent executable with .reloc section:
But this has to be tested with newer MinGW releases or MinGW-w64.

Also, it mentions older 1.x releases of FreePascal:
  • Using Version 1.0.10 is OK! (2.0.x and later may also work) :?
  • In compiler options set conditional define -WR option to generate .reloc section in exe-file needed for Win32s.

But he didn't test the later versions (2.0 and higher).

I have mentioned Digital Mars. This is a former Zortech (later Symantec) C/C++ compiler. The compiler has been open sourced a few years ago and the previously commercial distribution of Digital Mars C/C++ is now available here:

Although, there was and still exist the freeware version that targets only WIN32 (although you can add the DOS addon separately). This is available from here:

The dowload is much smaller and should be enough for WIN32 (and WIN32s) development.

According to LCC-Win32 linker documentation, it still has a reloc option:
-reloc

This option instructs the linker to build a .reloc section. This section is a table of relocations to apply if the executable cannot be loaded at its preferred load address. This option is necessary under Win32s.

But the author (Jacob Navia) has said elsewhere that WIN32s is not officialy supported. So, this support is considered unofficial. I guess that means: don't ask - if it works, works. But there isn't a real reason to not work if you don't use anything that WIN32s doesn't support.
 
Last edited:
Oh, I forgot something...

Beside redirecting the output to a local file or to a window, there is also an option to redirect it to dialogs. WIN32 console programs support showing dialogs (info, warning and error dialogs - for example). I think msiexec is an example of this - when run without arguments it will show the usage dialog.
 
I recently found and downloaded something for 16-bit DOS which allows you to run certain 32-bit programs at the command line. 7za462 works, which gives 7zip capability to DOS 6.2 . But sadly I've already forgotten what the utility is called (I'm not at that location atm).
 
If you mean DOS extenders that enable you to run WIN32 console apps from pure dos (or WIN 3.1 dos box), there is HX DOS extender:

There were a few similar projects before (although less powerful), like WDOSX.

Well, the question here would be if HX is (and in what amount) compatible with Windows 3.1 dos box, as Windows already uses its own memory management extenders (himem and emm386). They can be replaced with alternatives, but with varying degrees of success.

It was several years that I tested this, so I can't really remember.

That's an interesting alternative that is more compatible with wider range of executables and is worth investigating. Though, not strictly on topic, but still very closely related.

Talking about alternatives... Thanx to FreeDOS and DJGPP, there are DJGPP and Open Watcom ports of much more updated versions of many utilities to DOS itself like 7za, gzip, xz and unrar that work great under Windows 3.1 dos boxen.
 
Last edited:
TKERN (Troy's Kernel) provided a way to compile a 16-bit DOS application as a 16-bit Windows application with a (very dumb) console window and with support for Unix-style pipes (as opposed to DOS-style ones where data is written to a temporary file). If I recall correctly, it was yet another stdio wrapper, but it also provided a central process which owned all the file handles to enable them to be shared between TKERN applications.

I've wondered for some time whether it could be used in a 32-bit mode somehow. If it is incompatible with Win32s, perhaps it would work with Watcom's Win386 (I think that's the name?).
 
I've wondered for some time whether it could be used in a 32-bit mode somehow. If it is incompatible with Win32s, perhaps it would work with Watcom's Win386 (I think that's the name?).

Tkern itself was open source, so it might be possible.

Tkern and utility ports are available in old shareware CD-ROM archives. Like this one:

It's in the 3rd zip archive in subdirectory /INFO/PC/WIN3/PROGRAMR, alongside several tkern utility ports.
 
Talking about 32-bit command lines there was also RSXWIN: it allowed you to run DOS EMX 32-bit executables (EMX is dev environment for DOS and OS/2) directly in WIN16 window (works without WIN32s installed). There seemed to be TEX and Emacs port at the time, alongside full EMX GCC development package.

Although, while rest of the EMX bundle was open source, RSXWIN wasn't. So it comes without source.

rsxwin.png
 
Last edited:
You can download it from here (for example):

More info from rsxwin31.txt:
RSXWIN3e can run EMX+GCC compiled programs in a MSW 3.1 window. RSXWIN
doesn't need a DOS Box - all stdin, stdout, keyboard and ANSI.SYS calls
are mapped to window functions. RSXWIN only needs 100 KB memory. Since
a DOS-box needs up to 1 MB you have more memory for your applications.
Paging is reduced and your programs are faster.

Supported programs:
TeX386 - from the EmTeX package
GCC - and tools
Emacs - 19.27 emx port
Info - Termcap and ansi.sys output programs

More info from the docs:
Program Archive Name (example, xyz23.zip): rsxwin31.zip
Program Name/Title, 25 characters or less
(example, Super PacNerd): RSXWIN
Program Version, 12 characters or less (example, 2.01C): 3.10
Program Description
(55 chars or less): running emx programs (gcc,emacs) in a window
Does this program require Win32s? (yes/no): no
Is this a crippled demo version? (yes/no): no
Suggested directory for placement
(example, programr/vbasic): programr or util
If this replaces an older version, what is the name
of the outdated program (example, xyz21.zip): rsxwin3c.zip
 
Oh, I forgot something...

Beside redirecting the output to a local file or to a window, there is also an option to redirect it to dialogs. WIN32 console programs support showing dialogs (info, warning and error dialogs - for example). I think msiexec is an example of this - when run without arguments it will show the usage dialog.
and of course you can redirect output to a text file (not by "> somefile.txt" in command prompt) and open that file upon finish, you can check this out: https://github.com/roytam1/ntldd/commit/225485dd861af96576df3b0d9c458d56929556ff
 
Oh, yes. That is what I meant by "redirecting the output to a local file", just without "opening that file upon finish" part. :)

A variant of the same solution. ;)
 
I was intending to try Imposter too eventually (TCMD/16 was mentioned in the first post), but haven't found the time for "playing" with it. Thanks for confirming it works. :)

Actually, anything non-interactive mostly works fine. Except filters (sort, uniq and similar).

Of course, that is if the binary is compatible with WIN32S (has relocations).
 
Back
Top