-1

I have written the simple Hello World Application on windows xp file Name "hello.c" as:

 #include<stdio.h>
 int main(){
      printf("Hello World\n");
      return 0;
 }

compiled with the following command:

gcc hello.c

Now on another Machine with Windows Vista Installed the DosBox Application and tried to run a.exe compiled by gcc

The application doesn't run and provided the following message:

This Program cannot be run in DOS mode.

But when I double clicked on a.exe file in windows explorer it runs and said:

 Hello World

Why this message is coming.....

3 Answers3

1

You compiled this app for Windows not for DOS. It will not work. You need to compile the app to work on DOS. Why are you using Dosbox for that?

logoff
  • 3,347
  • 5
  • 41
  • 58
1

You have compiled a Windows program, which can only run in Windows and not in DOS or emulated DOS. Run the program directly, without DosBox.

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
0

The Windows and DOS consoles look alike and share some of the same typed commands, but they are built on two completely different operating systems.

A Windows console-mode application runs modern 32-bit or 64-bit code and has access to all of the vast Windows API.

The DOS command line is part of DOS, an older operating system, which (mainly) runs 16-bit code. It has its own separate APIs and conventions for things like file handling, memory management, and hardware support. This is the platform that DOSBox emulates. So, DOSBox will not run Windows programs. (That said, it can run early versions of Windows itself, since those were plain DOS programs).

  • If you want to compile a program to run on DOS you'll need a compiler from that era for that operating system. Turbo C++ is a good one (search for 'turbo c++ 3.0 abandonware').

  • If you want to compile a Windows application that runs in a console, then your existing compiler is perfect, but then you don't want DOSBox. Open the Windows command prompt/line/thing instead (Start -> Run -> cmd -> Enter).

Boann
  • 48,794
  • 16
  • 117
  • 146