Solved

Convert Borland C DOS to Windows GUI

Posted on 2004-04-13
10
1,303 Views
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?
0
Comment
Question by:Idarac
  • 6
  • 4
10 Comments
 
LVL 45

Expert Comment

by:Kdo
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,
Kent
0
 
LVL 45

Expert Comment

by:Kdo
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.


Kent
0
 
LVL 1

Author Comment

by:Idarac
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?
0
 
LVL 45

Expert Comment

by:Kdo
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.


Kent
0
 
LVL 1

Author Comment

by:Idarac
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?

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 45

Expert Comment

by:Kdo
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  */

struct
{
  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)
Ax01B

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:

Axxx0001B

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.



Kent
0
 
LVL 1

Author Comment

by:Idarac
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?
0
 
LVL 45

Expert Comment

by:Kdo
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.


Kent
0
 
LVL 1

Author Comment

by:Idarac
ID: 10863144
I feel Kent has answered my question.

How do I close out and assign points?
0
 
LVL 45

Accepted Solution

by:
Kdo earned 250 total points
ID: 10863196

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

Kent
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now