C#, The Language For All Platforms – Now Including Windows 3.11 And DOS

The Microsoft .NET framework has been with us in one form or another since the millennium, and though it has remained largely the preserve of the Microsoft universe, it has found its way since then through a variety of implementations to other platforms including MacOS and GNU/Linux. In Microsoft terms though its history goes back only as far as Windows 98, earlier MS operating systems remain off-limits.

Just a glimmer of .NET in DOS and Windows 3.11 comes courtesy of [Michal Strehovský], who has successfully compiled .net C# code for both Windows 3.11 and DOS. An in-depth explanation comes courtesy of [Scott Hanselman], and it involves some tricks spanning the decades since the early 1990s. The .NET Core compiler’s object files can be fed into the linker that shipped with an ancient version of Microsoft’s C++ compiler, which when used with Microsoft’s Win32s compatibility layer that brought some of Windos NT’s APIs to the 16-bit OS, allows C# from 2020 to run as though it were 1992 again. Meanwhile the DOS version uses .NET Core’s ability to produce self-contained executables along with some very significant tricks to pare down the size of the finished program from many megabytes to an eventual DOS-suitable 27k. Remember the apocryphal Bill Gates quote, that “640k should be enough for anyone“, that refers to the maximum memory available to DOS without extra memory-extending tricks.

Neither piece of software is especially useful, and we can’t see a rush of C# coders to these new platforms. But we applaud him for his ingenuity, and getting old hardware to do new tricks is right up our alley. It’s certainly dredged up a few memories from back in the day for us. Meanwhile we’ve featured .NET in a few projects over the years, most recently on an FPGA.

33 thoughts on “C#, The Language For All Platforms – Now Including Windows 3.11 And DOS

        1. Which is fine if you want to write every tiny little piece of code yourself, from scratch. But as soon as you want to use a library made by someone else, you’re headed straight for dependency hell.

      1. Win32 CLI and simple GDI/DDraw applications technically can be run under pure DOS, though.
        By using HX Extender, for example. DOSBox is kinda popular here. It can run on DOS itself that way.

      2. Partially true. MIchal achived this by using 16-bit part of the PE file that typically prings “This program can not be run in DOS mode” by injecting his own binary into this section. If you know that 32/64 bit PE file contains 16-bit section then you are back in the game to inject your 16-bit binary into this section. Michal is using https://github.com/Baron-von-Riedesel/Dos64-stub to inject his 16-bit payload there.

      3. MIchal Strehovsky actually achieved this by injecting 16-bit code in the PE section that typically displays error message “This program can not be run in DOS mode'” when user attempts to run Windows EXE in DOS. Leveraging information that 32/64 bit PE file contains 16-bit section puts him back in the game with compiler and linker. He is using https://github.com/Baron-von-Riedesel/Dos64-stub project to inject his 16-bit payload that then switches CPU to 64-bit mode and executes 64 bit code compiled with C#/IL.

  1. MS/PC DOS is still a very important component of industry computers.. why? It is a RTOS. Apps have full access to hardware, no such thing as hardware abstraction layer. Win 3.11 [Windows for Playgroups] played an important transition to the disaster known as Windows 95… I successfully booted Win 3.1 off a Linux server, never could netboot 3.11, or Win 95, oh well it was fun trying

      1. Yes N MS-Dos was marketed thru a very difficult system, where you had to submitt and pay for the “upgrades” to the next level, if iheard it it 7.11, only accesible to military

    1. Oooh, you probably forgot that while your DOS is running, the industrial machine can still be running something in the System Management Mode interrupt if it has 386SL or newer. And it probably does, because most hardware power controls are or at least used to be accessed this way. In some embedded x86 processors, some functions/peripherals may be emulated by the SMI – the processor may have memory windows corresponding with the peripheral space registered to SMI. Then, trying to access that memory triggers the SMI which secretly emulates the peripheral without you knowing. And this may make the DOS non-RTOS system. There was a processor which emulated a SoundBlaster (not very well) this way. Was it VIA C5?

      1. I cut my teeth learning the 8085 on an SDK-85, no assembler, hand coded everything, moved easily the 8088 on the PC using debug. This stuff out since Intel moved to cheap,low power laptops,etc is a truly bane to anyone ever trying to stay up with the herd. I only own old fashioned PC’s that have P5’s and such, but I never had problems reading the 8254 timer registers in realtime, or bitbanging out the parallel port to get stuff done

  2. C still working fine on all platforms. Never did warm up to C#. We support C/C++, Python, Perl, some Fortran in my area. Between them we have everything we need. On the ‘other side’ (IT) they do quite a bit of C# programming. But then they have M$ marked on their backs :) . However that is changing. We see glimmers, that they are slowing coming around to using some open source tools though… Slowly…..

    Never saw the need for ‘yet another language’ by M$ when it was created, but M$ followers seemed to glom onto it.

  3. I learned C# a couple of years ago and let’s just say it’s not my language of choice. It feels like they basically took the good parts of C++, then removed pointers, then added hundreds of little workarounds to solve the problem that you can’t use pointers.

    1. The best way to think of C# is that it’s a less psychotic Java with a healthy dose of MS platform lock-in. Personally I like working with it, it’s great for throwing together business applications quickly, but if it’s performance or optimization that you’re after there are better tools in the shed.

  4. I sense a great disturbance in the force. As if millions of voices had shrieked in panic at the concept of the C# virus now infecting an even larger set of previously pure computing platforms.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.