Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem running C++ program in DOS

Status
Not open for further replies.

vallabhc

Programmer
Apr 24, 2006
2
US
Hello everyone,
I am trying to run a C++ program by booting into DOS Mode. I am using Borland Turbo C++ v3. I have to run this program in DOS itself because of its application.

Program has some basic graphic display stuff (color circle with gray background). When I open the tc.exe, then open the .cpp file and run the program, its working fine. The code is such that when I press a key on keyboard, it should halt/end the program and as usual go back to editor window. Here is the problem. When I press a key to end the program, the program stops but screen is turning blank (black) with a cursor blinking on it. Cursor is moving with the arrow presses on the keyboard. I am sure that the screen is going back to the turbo c++ editor where I ran the program initially. I am sure because, I tried to press ENTER key like around five times and restarted the computer. When I opened the code, I found those five blank lines in the code because of the ENTER presses. I guess I am opening and closing graphics correctly. These are the lines that I am using to open graphics mode.

int gdriver = DETECT, gmode;
initgraph (&gdriver, &gmode, "c:\\tc\\bin\\bgi");


To close the graphics I am using this line.

closegraph();
restorecrtmode();

I tried a small program which just opens graphics and closes graphics and halts the program on the press of a key (used getch()). Even for that, the screen is turning blank after halting the program.

Have no idea. Please share your views on this.
Hope I will find a solution soon.
Your help is highly appreciated.
Thanks,
Vallabh C
 
It's been centuries since I compiled anything in DOS, but I wonder if you need to save the contents of the video buffer when you start your program, do your stuff, then restore the video buffer when you exit your program?
 
Thanks for yor reply. By the way, as I said, my application requires the C++ program to be run in DOS. I have never done this earlier either. Basically we are trying to display some graphic patterns on a touch screen placed in a pigeon cage. The pecks of the pigeon are read and its feeder (electric device controlled through printer port of CPU) is activated conditionally (my boss studies psychology of pegion). The problem is I am not able to run the C++ program in Windows on a touch screen. If I do so, as soon as the bird pecks the graphics screen (which looks like a DOS screen with color disks), the graphics screen is jumping back to Windows desktop. This should not happen. On usual CRT monitor, this is not happening. I appreciate if you can give any suggestion to avoid this.

Also, as far as I know, when we initiate graphics using initgraph(), the current graphics/video settings will be stored in buffer and when we close the graphics, they will be automatically restored. But this is not happening in my case. I couldn't find out why?

Any suggestions will be appreciated?
Thanks,
Vallabh C
 
May be you see black letters on black background?
Try textattr() after returning from graphic mode.
 
Try reversing the order of the closegraph and restorecrtmode function calls. closegraph() shuts down the graphics subsystem, of which restorecrtmode is a part of. I'm thinking that when you shut it down , you're also losing the video buffer that was saved on the switch to graphics mode.

The simplest solution is the best!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top