views:

1289

answers:

9

Hi all,

I was reading up about NTVDM.exe as I build a quick test console app and it crashed on a friends machine complaining about this EXE.

As I understand it all DOS cmd windows (C# console apps included) run as 16bit not 32bit.

Is this true? Does this mean all my works console app back office apps are running as 16bit rather than making the most of the 32bit available?

What about Windows services? As I believe we wrote it as a console app then made it run as a windows service?

Thanks

+9  A: 

Any .NET app that is compiled for x86 will be 32-bit

C# console apps aren't running in "real" dos - they run in a 32-bit or 64-bit environment - depending on your OS and .NET framework.

Joe R
+2  A: 

A .NET console app. (or any other .NET app) will run as whatever targeted hardware it is JIT'ed to is. So for x86 it will be 32 bit.

Mitch Wheat
+5  A: 

As I understand it all DOS cmd windows (C# console apps included) run as 16bit not 32bit.

Is this true?

No, not at all.

You can run DOS applications under Windows, and they are 16-bit, but the fact that they look a bit console-like is pretty much just coincidence.

There are no 16-bit .NET applications, and whether an application is console mode or not makes no difference to whether it's 16 or 32 bit.

Will Dean
A: 

There is nothing special about a console exe; it is just a PE file. So regardless of console vs winform exe vs windows service, it is just going to run in whatever mode it was compiled.

Visual Studio etc will never generate a 16-bit exe. x86 vs x64 is more interesting ;-p

Probably, your friend doesn't have the .NET framework installed (or only has 1.1).

Marc Gravell
+1  A: 

As I understand it all DOS cmd windows (C# console apps included) run as 16bit not 32bit.

You are wrong. All cmd.exe Windows are 32 or 64-Bit, depending on the architecture.

DOS died together with Windows ME almost a decade ago.

Michael Stum
+1  A: 

I don't know about any .NET VM implementation that is capable of running in 16-bit mode. The Microsoft .NET runtime and Mono are both 32/64 bits only. I don't know about the other smaller ones, but I would be surprised if they could work in 16-bit mode.

Also, cmd.exe runs in 32 bit mode as cmd.exe is a 32-bit Windows application. On the other hand, command.com runs in 16-bit mode.

Actually, console applications are far from being inherently 16-bit. This is just simply not true, it wasn't even true before Windows, as the x86 protected mode is 32-bits, so any game or application for DOS running in portected mode is 32-bits.

In .NET, your type of UI (or lack of UI as in Windows Services) does not affect the word length of the application. By default, .NET binaries are platform independent, and get executed as 32-bit or 64-bit application depending the type of .NET Framework, kernel, etc. of the host machine. Although they can be compiled directly to 64-bits too.

DrJokepu
A: 

Even under DOS, ".EXE" could be 16-bit or 32-bit (with appropriate coding or DOS extender library).

Brian Knoblauch
A: 

NTVDM.EXE is the DOS emulator that supports running 16-bit .COM and .EXE files in an environment where they can assume the CPU is 16-bit and that DOS system calls are available. Its only association with command prompts is that text-mode DOS programs use the Console window to supply the emulation of a VGA screen in text mode.

As noted, there is no .NET VM available that can run under DOS. However, it might fun to start from the Mono project sources and build one that runs under FreeDOS... just to scare your friends ;-)

RBerteig
i like the scaring part ;)
moogs
+2  A: 

MS-DOS Apps run as 16-bit apps under the ntvdm.

"Windows Console" Applications are not DOS applications, and run as a native Windows Process (where a bit in the PE Header of the EXE File identifies it as a Console Application, so that Windows can create/prep a Windows Console for the application if one does not already exist, e.g. running your Console Application from CMD or PowerShell will re-use the Console Window already created, whereas double-clicking the EXE in Explorer will create a new Console Window for the Application.)

CMD != DOS Console != DOS

Likewise, there is a full Windows Console API that has been present in Windows since at least Windows 2000 (NT5) if not sooner (though probably NT3/4 only.)

Shaun Wilson