Advertisement

Multi OS programs

Started by February 23, 2000 12:42 PM
3 comments, last by xstreme2000 24 years, 6 months ago
I believe that it is possible to make a program that would run in different ways depending if you ran it in widows or under DOS. I think this is possible because in the past I have tried to run a Win32 program under DOS and I got a message something like "You can not run a Windows program in MS-DOS". At first I thought nothing of it and that it was an error message from DOS. But on another occasion I got a message something like "This is a Win32 executable". Instantly I thought it was a bit strange to have two error messages for the same problem so I opened the program in a hex editor, sure enough I found the string. So this must be a dos part of the program. At first I thought that maybe it possible to write a duel OS pogram like so: void main() { // dos prog } int APIENTRY WinMain(...) { // windows prog } but no! If you can tell me if this is possible please do. Wouldn''t it be good if when your game was run in DOS you logo appeared and maybe a different game or cheat code or something.
Actually what you''re seeing is the stub file for the executable. The NE and PE executable formats had to run from DOS, but only while windows was also running, so there''s a stub program attached to the beginning that makes sure windows is in operation and if it isn''t dumps you out.

I believe with MSVC 4.0 and Borland 3.0 you could change the stub file to something different, but I don''t know if that functionality is still in the compilers.
Advertisement
We do this at work all the time using #defines that are set through the command line to the compiler. I''ve included an example based on your example. Only one of the main functions will compile, but they will both use the same core function. If changes are made to fn(), then it is done for both OSs at the same time.

Mike Roberts

-----------------------------

#if defined(OS_DOS)

void main()
{
fn();
}

#endif

#if defined(OS_WINDOWS)

int APIENTRY WinMain(...)
{
fn();
}

#endif

//
// This function is common to both OS solutions
//
void fn(void)
{
}
AnonymousPoster: I believe xstreme2000 wants to have the same .exe file run in both DOS and Windows. Your solution will just compile two .exe''s for two different OS''s.

- null_pointer
The obvois thing would be two .exes but that is not what I want.
With Mike Roberts example I have a few questions. If anyone knows about his method could they please follow this up.

1) with this method do you have to compile 2 different .exes, one dos and one windows. because that is the only way I can get it to work. also I have to define OS_DOS/OS_WINDOWS at the start of the program. I would like it to be one .exe which runs under both OS

2) If it is just one .exe do you set the compiler to a dos or windows output(Borland) or what settings in MSVC.

Edited by - xstreme2000 on 2/27/00 8:47:39 AM

This topic is closed to new replies.

Advertisement