Computing.Net > Forums > Programming > An exe that runs in dos and widows?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

An exe that runs in dos and widows?

Reply to Message Icon

Name: vilo999
Date: August 20, 2004 at 01:49:03 Pacific
OS: Windows 2000 SP4
CPU/Ram: 256 MB rimm
Comment:

Hello, i was just thinking, how can i compile an exe that runs in both windows and dos? An nice example is windows98's regedit.exe. I dont really need it but i'm just curious how can it be done.

Cheers



Sponsored Link
Ads by Google

Response Number 1
Name: Birdman
Date: August 20, 2004 at 08:40:59 Pacific
Reply:

Not sure what you mean. Regedit is a windows GUI program. Sure, you can start it from the command prompt, but that's not DOS. DOS is an older operating system (that the command prompt is based off of) that used to ship with Windows. Now all that's left is the weak command prompt.

Now if you want to write a program that either runs in GUI style or in text based old school DOS, I seem to remember ways to do that. I think you would just bundle two versions of the program together, one linked with the Windows SDK, and one built for dos, and have the main executable start one or the other depending on the environment. As to determining the environment, I can't remember how its done, but a google search should reveal some info.


0

Response Number 2
Name: StuartS
Date: August 20, 2004 at 08:52:33 Pacific
Reply:

Not possible. Two different environments. It's like putting diesel in a petrol engine.

Regedit.exe may be able to be called from DOS, but it is running from Windows. Try running it from a pure DOS environment. It will probably try to load Windows. DOS has no knowledge of a registry or anything to do with it.

Even Regsver32 which is nearly always called from a DOS command line but it is in fact a Windows programme.

If fact if you call most Windows programme from a DOS prompt within windows, it will run, but its running under Windows, not DOS.

Stuart


0

Response Number 3
Name: vilo999
Date: August 22, 2004 at 13:47:27 Pacific
Reply:

Thanks, shipping 2 versions of my exe vould be nice. However there definitly is a way how to make it all-in-one.

Of course, creating console mode applications is easy. But regedit really runs in PURE DOS. In fact, all programs run in pure dos. But they all have code at the very beginning of file that checks if the program is running under pure dos. If yes, the code prints message "This program cannot be run in dos mode" and ends. Sure, when regedit is started form windows, its gui-based(because the windows part of the exe loads). But when started from dos(not command line) it is also usable. It will become command-line program. So an usage from PURE dos vould be like this

regedit -d HKEY_LOCAL_MACHINE etc.

I dont remember the commands, because i dont have win 98 installed right now.

If you open a classic win exe in hexeditor, you will see something like

bla bla bla This program cannot be run in dos mode. bla bla

thats the dos-code. However windows 98's regedit.exe doesnt look like this in hexeditor. It looks totally different. It doesnt even have the cant run message.

So my question is: how can i modify the code that runs in pure dos mode? How big can my code for dos be? Thanks


0

Response Number 4
Name: StuartS
Date: August 22, 2004 at 14:04:50 Pacific
Reply:

>> But regedit really runs in PURE DOS. In fact, all programs run in pure dos.<<

I don't know who told you that, but they told you wrong.

"This program cannot be run in dos mode" was only put there in the early days of Windows when there were still a lot of people around familiar with DOS. The fact that you can enter command line parameters is irrelevant.

Modifying any programme to run in an environment different than it was designed for simply by modifying is impossible. There are just to many things that need changing. Even if it were possible, you would need the source code.

Remember, DOS is a 16 bit single user, single taking environment. Windows is a 32 bit multi user, multitasking environment. Windows programmes have to be written to take that into account.


Stuart


0

Response Number 5
Name: vilo999
Date: August 22, 2004 at 14:45:00 Pacific
Reply:

I have found a copy of windows95's regedit.exe. It appears that it is also usable from dos. Ill show why.

Please go to theese addresses. I have placed very descriptionable pictures there. Its because of my english. If youll see the pictures, youll surely know what i mean.

www.goosemaster.szm.sk/normal.jpg

And second:

www.goosemaster.szm.sk/regedit.jpg

Thanks!


0

Related Posts

See More



Response Number 6
Name: vilo999
Date: August 22, 2004 at 14:50:18 Pacific
Reply:

If you are curious on the exe file itself, download from here:

www.goosemasrer.szm.sk/regedit.exe

Give it a try, and run form pure dos using some diskette or something!


0

Response Number 7
Name: vilo999
Date: August 22, 2004 at 16:41:44 Pacific
Reply:

Sorry the address for the exe is

www.goosemaster.szm.sk/regedit.exe


0

Response Number 8
Name: BasicDosHlp
Date: August 23, 2004 at 20:45:59 Pacific
Reply:

A program created for windows cannot be run in dos but a program created for dos can be run in windows
I have created commandline programs in basic that run in windows and Dos
and programed visual basic6 gui programs for windows only
there is an old outdated version of visual basic for dos I havent used it yet
but I am assuming it would do what you ask
http://imaginatica.us.es/~wopr2k/qbdl/index.html#visualbasic
ive been meaning to try it myself let me know how it works

My Page has many quick explainations of basic commands
Feel free to contribute Or enlighten me with code examples that are not on my page
I am particularly interested in learning hardware periph


0

Response Number 9
Name: vilo999
Date: August 24, 2004 at 04:44:41 Pacific
Reply:

Thank you for all your answers. VBDOS create dos-only programs that, yes, work in windows. But thats not what i want to do.

Have some of you looked at the pictures, or have you downloaded the exe? Please, if no, then i understand what you are talking to me. I have also never seen an exe that executes normally in windows and dos too. I came accross that by this way:

I was reading "tips and tricks for windows 98". In one trick there was said: "Do you know that regedit runs also in DOS?"

At the first look, i thinked the SAME as all of you. "What?!? That cant be true!"

But, i could not not-try it. So i have choosed "Restart computer in MS-DOS mode" and launched regedit.exe. Whoala! Runs like a simple command-line parameters based program. Under windows runs like a gui program. (because different parts of exe loads) All i want to do is to tell the compiler(preferably c++) to write the dos portion of exe with MY CODE.

Maybe runs is not a correct word. I want to make a program that *behaves* differently under dos than printing "this program cannot be run in dos mode." I know that now you must think "why are you still asking, even if i said thats not possible!". Sorry, but it is. Download the exe. Run from PURE DOS using some startup diskette. The exe speaks for itself. So the pictures do.


0

Response Number 10
Name: vilo999
Date: August 24, 2004 at 15:31:20 Pacific
Reply:

Yes now i got it. The dos-part of exe is called dos stub. Info on website

http://win32assembly.online.fr/pe-tut1.html

So, dont you please know how can i change the dos stub? You see, "can simply display a string like "This program requires Windows" or it can be a full-blown DOS program depending on the intent of the programmer."

I volud like my program to be compatible with dos! Please somebody dont know the solution?


0

Response Number 11
Name: vilo999
Date: August 25, 2004 at 03:34:24 Pacific
Reply:

For all others: its the /STUB: linker option. Problem solved.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: An exe that runs in dos and widows?

Make an exe with a batch file and.. www.computing.net/answers/programming/make-an-exe-with-a-batch-file-and/17595.html

Code that i can run in background www.computing.net/answers/programming/code-that-i-can-run-in-background/15677.html

dos graphics using visual www.computing.net/answers/programming/dos-graphics-using-visual/7654.html