• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1345
  • Last Modified:

Convert Borland C DOS to Windows GUI

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
Idarac
Asked:
Idarac
  • 6
  • 4
1 Solution
 
Kent OlsenData Warehouse Architect / DBACommented:
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
 
Kent OlsenData Warehouse Architect / DBACommented:
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
 
IdaracAuthor Commented:
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
Identify and Prevent Potential Cyber-threats

Become the white hat who helps safeguard our interconnected world. Transform your career future by earning your MS in Cybersecurity. WGU’s MSCSIA degree program was designed in collaboration with national intelligence organizations and IT industry leaders.

 
Kent OlsenData Warehouse Architect / DBACommented:

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
 
IdaracAuthor Commented:
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
 
Kent OlsenData Warehouse Architect / DBACommented:
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
 
IdaracAuthor Commented:
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
 
Kent OlsenData Warehouse Architect / DBACommented:
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
 
IdaracAuthor Commented:
I feel Kent has answered my question.

How do I close out and assign points?
0
 
Kent OlsenData Warehouse Architect / DBACommented:

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

Kent
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now