Convert Borland C DOS to Windows GUI

Posted on 2004-04-13
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?
Question by:Idarac
  • 6
  • 4
LVL 45

Expert Comment

ID: 10813524
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,
LVL 45

Expert Comment

ID: 10814155
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.


Author Comment

ID: 10814405
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?
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

LVL 45

Expert Comment

ID: 10814550

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.


Author Comment

ID: 10816116
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?

LVL 45

Expert Comment

ID: 10816373
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.


Author Comment

ID: 10832927
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?
LVL 45

Expert Comment

ID: 10833086
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.


Author Comment

ID: 10863144
I feel Kent has answered my question.

How do I close out and assign points?
LVL 45

Accepted Solution

Kdo earned 250 total points
ID: 10863196

Click the "Accept" button to the right of the comment that you want to accept.


Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to setup iphone app subscription service 3 134
memory mapped I/O query 6 147
smtp c source code 7 67
Test the speeds on my PC Drives 12 43
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

805 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question