Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Run external app, and return control

This thread is locked; no one can reply to it. rss feed Print
Run external app, and return control
Bruce Fox
Member #7,301
May 2006

Hi Guys,

I am writting a DOS app in C++ using Allegro.
It is a GUI that will be able to run an external app when a key is pressed.

How can I run an external app (testapp.exe) and once I finished with it, have my
main app regain itself as it was before I ran testapp.exe.

The problem I have is when I close the testapp I am left with a blank screen - and not my GUI.

I know how to do this in QBASIC and VB6 - but not C++ :)

I envoke the testapp with: system("testapp.exe")

// Setup
allegro_init();
install_keyboard();
set_color_depth(16);
set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);

// ---------- clipped -----------
while( !key[KEY_ESC]){

if (key[KEY_1]){
if (confArr[16] == "1"){
int sound = play_sample(snd_sample, 128, 0, 1000, 0);
void destroy_sample(SAMPLE *spl);
system("testapp.exe");//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< here
}
}
}

Suggestions?

Cheers,

=========================
Bruce Fox

Kitty Cat
Member #2,815
October 2002
avatar

DOS doesn't share resources very well (read: at all), so if the other app wants to use graphics or something, you have to shut it down, call the app, then restart it.

// Shutdown Allegro
allegro_exit();

system("testapp.exe");

// Re-init Allegro (don't forget error checking)
allegro_init();
install_timer();
set_gfx_mode(...);
install_sound(...);
install_keyboard();
install_mouse();

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Bruce Fox
Member #7,301
May 2006

Ahh, Ok I'll give it a go :)

=========================
Bruce Fox

Tobias Dammers
Member #2,604
August 2002
avatar

Is there a reason why you have to use DOS? If there isn't, or if the reason goes by the name of 'djgpp', then consider using mingw.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

nonnus29
Member #2,606
August 2002
avatar

Quote:

DOS doesn't share resources very well (read: at all), so if the other app wants to use graphics or something, you have to shut it down, call the app, then restart it.

File access is prone to errors as well. The best way to do it under windows is to start a new thread, run the program, and shut down the thread. I found some source code for doing this as it's all winapi calls but I cleverly didn't bookmark it...

Edit; I don't think this is what I found, but it's close and it has some links.

Bruce Fox
Member #7,301
May 2006

Thanks for the replies guys. It MUST be DOS in my case :)
I have implimented Kitty Cats suggestion and that seems robust.
(I am using DJGPPP + Allegro)

Cheers,

=========================
Bruce Fox

Go to: