We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Convert Borland C DOS to Windows GUI

Idarac asked
Medium Priority
Last Modified: 2007-12-19
I have to convert a DOS based Borland C program to Windows GUI application. I have completed conversions in other languages but never C. I know from experience the conversion process is never seamless.

Here is what I need

What would I use as programming environment? I would like to do minimal code changes.

What are the code nuances to watch for?
Code changes to be expected.
1. Printing.
2. File I/O
3. Data entry

How do you go from a DOS based program to event driven app?

What to watch for in the conversion of printing routines?
Watch Question

Kent OlsenData Warehouse / Database Architect

Hi Idarac,

You've actually got quite a bit of work ahead of you.  Some of the Borland extensions that worked on the DOS compilers have been obsoleted -- some changed, and others dropped completely.

My suggestion is to get a copy of Borland's C++ Builder, about $70.00 for a single-user developer version.  This won't guarantee that any non-ANSI extensions will work, but more will work with a Borland compiler than any other.

To convert to a GUI app, you should also consider converting to C++.  Your core application can remain in C, but using the C++ calls for the Windows interface will modernize your code.  C++ Builder is also LOTS easier than coding all of the interfaces in C, or even C++.  (The builder does 90% or more of the interface for you.)

Good Luck,
Kent OlsenData Warehouse / Database Architect

Hi Idarac,

Guess I didn't answer all of your questions, huh?

Printing will be different.  In C++ you can actually read/print a file very easily.

All of your file I/O that uses the streaming functions (FILE macro, fgets(), fprintf(), etc) will continue to work just fine.

Data entry will be different.  Much different.  The good thing is that you have almost unlimited flexibility in controlling the input.  I'll be glad to answer any specific questions here.



How do I convert to C++.  What type of process shoudl I follow?

Will I have to change the coding for any data entry text boxes? And there are Browse windows which will have to be converted. I suppose I will have to put buttons on for example (Save,Close etc.)

The dataset I was sent has files with extensions .dta, .kx and .xx. And there is supposed to be a data packing and reindexing routine.
Have you ever encountered this?
Kent OlsenData Warehouse / Database Architect


All of the functions that you've created for accessing the data (reading, writing, packing, indexing, etc) should work with little or no changes.  The biggest potential problem in converting this from 16-bit DOS to 32-bit Windows is that objects within your 'struct' definitions may now be a different size.  if so, you'll have to use 'short' instead of int to define 16-bit values.  Either that or convert the data structures as you convert the application.

You say "data entry text boxes".  You must have "home grown" APIs to do this.  With C++ Windows/GUI, most of it "just happens".

Dialog boxes are a snap.  Here's an example of an open dialog box that browses txt, rtf, and doc files.

  TOpenDialog *OpenDialog = new TOpenDialog (this);
  OpenDialog->Filter =
    "Text Files (*.txt)|*.txt|"
    "RTF files (*.rtf)|*.rtf|"
    "DOC files (*.doc)|*.doc|"
    "documents (*.txt, *.rtf, *.doc)|*.txt;*.rtf;*.doc|"
    "All Files (*.*)|*.*";
  if (OpenDialog->Execute ())
    FileName = OpenDialog->FileName;
  delete OpenDialog;

As far as converting from C to C++, I'd convert only the human interface (Keyboard input/GUI) and keep the application in C.  At least for now.



I am coming from relative novice view point even though I worked with C programming before I have never converted an app to a Windows GUI. This is not my orignal project

When you say convert to C++ How do you do that? Is there a conversion utility out there?

I have never seen a case where a C program has a packing and reidexing routine. If that is the case do you have any idea what format the data may be?

The browse I was talking about is a  browse where you view a series of data not a browse of files directories. Similar to a list box.

When you say Data entry will be different and you have almost unlimited flexibility in controlling the input. What do you mean? When the user has to enter a numeric or date value what do we have to change in the code to mveo it from DOS to Windows?

Kent OlsenData Warehouse / Database Architect

Hi Idarac,

Regarding a conversion utility -- I'm not aware of one.

As far as packing and reindexing, the "nuts and bolts" of C work just fine in C++, though there are places where you must be careful.

  int IntVariable = 12;  /*  works fine in all flavors of C and its successors  */

  char ChVar1;
  int  IntVar;
  char ChVar2;
} MyStruct_t;

In the structure above, you've got three pitfalls.  C/C++ will normally align the data so that the structure begins on a word boundary.  However, there may be "hidden" bytes between chVar1 and IntVar, and there may also be hidden bytes between IntVar and chVar2.  This is because memory is so cheap on modern systems that most compilers will try and align the data on word boundaries for quickest access.  Also, IntVar is probably 2 bytes on your 16-bit DOS system, but 4-bytes on your 32-bit Windows system.

You probably don't care how long the integer is, but data alignment means that you have to take this into account.  If you try and read this structure directly from your data file, what happens?  Well, it depends on the size of each field and how data is aligned.  If you read into this structure from your data file you may very well be doing something like this:

MyStruct_t MyStruct;

  fread (&MyStruct, sizeof (MyStruct), 1, InputFile);

On your 16-bit system, your data probably looks like one of the following:

A01B    (or)

The 'x' represents a padding character that you don't see.  If you try and read it into your 32-bit system, you'll get junk because the 32-bit system is probably expecting the data for this stucture to look like:


You will have to convert the data.

Browsing the data is MUCH easier than it is in C.  Assume that your GUI has an edit box.  (An edit box is an object on a form/window that looks and acts just like the parts of Notepad, Wordpad, Word, and WordPerfect where you enter and edit text.  You typed your last response in an edit box, probably in Internet Explorer.)  You can load an entire file into the text lines of the box with one line.

  MyEditBox->LoadFromFile ("FileName.txt");

Every object in the C++ library that allows input from the screen can control what is input.  Most of these objects have an OnKeyPress method that is automatically called when a keypress occurs.

  if (Key < '0' || Key > '0')
    return 0;
Putting those two lines in the OnKeyPress method would cause the object to ignore all non-numeric input.  You have almost unlimited flexibility in defining what is valid input for every field on your GUI.



I just have 2 questions left.

1. So if I get C++ Builder can I just bring the Borland C source into it. Or does it have to be massaged some how first?

2. When I work with dBase files I can use DBU to actually look at the data in the data files. Is there some type of data utility out there I can use to look at the data?
Kent OlsenData Warehouse / Database Architect

Hi Idarac,

1.  The C++ Builder will compile all of the ANSI C code as well as the BORLAND extensions.  I know of only one small inconsistency in structure/union definitions that isn't portable, but is easily fixable.  The one place that won't convert easily is the console/terminal I/O that uses the definitions in conio.h.  These are DOS specific I/O routines, some of which are available via other API.  Most of the conio.h defined routines are not part of C++.  ncurses (ncurses.h) may be an easy way to convert without building a full Windows GUI application.

2.  dBase files.  This is the first that I've picked up on this.  There should be any number of utilities available to allow you DBU kinds of access to your data.  DBU might work.



I feel Kent has answered my question.

How do I close out and assign points?
Data Warehouse / Database Architect
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.