Solved

Porting from Turbo C to Visual C++

Posted on 2001-07-22
17
629 Views
Last Modified: 2013-12-14
I'm quite new to VC++ programming and I have this task of porting a DOS C application to Visual C++ 32 bit.

1) However, there is this UNION REGS that is used in Turbo C (dos.h) and no longer supported in Visual C++. Is there an equivalent structure or workaround for this problem?

2) The obsolete 'far' keyword used in Turbo C is also no longer supported. What is the equivalent keyword used in Visual C++ or can I just omit it?


Thank you.
0
Comment
Question by:yjt
17 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 150 total points
ID: 6306939
>> 1) However, there is this UNION REGS that is used in Turbo C
>> (dos.h) and no longer supported in Visual
>> C++. Is there an equivalent structure or workaround for this problem?
that union/structure is used in specifying values to be lopaded into CPU registers for passing to DOS sevices (DOS OS functions) and for retreiving the values returned by the services in the CPU registers.

Sp you could achieve the same thing by using the VC inline asembly features.  These allow you to load registers with values and retreive the values from registers.  However, that is likely to be ov no value for you, since the popint was to lload registers in order to perform some sort of DOS service function and you cannot perform that DOS function in win32.

So you need to look into alternatives to the DOS functions you are calling.  There are about a 100 of these functions and they perform a tremendous range of functions, like opening disk files, getting user input, or allocaitng memory.   Windows provides about 3,000 functions for these and other actiivities.  Basically all of the features of the DOS functions are duplicated and MANY more in the windows API.  

But without knowing what DOS services you are calling, I can't tell you wnat windows API funcitons you need to look into using.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6306943
>> 2) The obsolete 'far' keyword used in Turbo C is also no
>> longer supported. What is the equivalent keyword
>> used in Visual C++ or can I just omit it?
In win32 you have a full 32bit address space (4 gig of memory) so there is no need to worry about segments anymore.  There is no near or far attribute to pointers since all pointes point into the same 4 gig segment.

so you can drop near and far and any associated feature like that.  (far memory functions for example).
0
 
LVL 1

Author Comment

by:yjt
ID: 6307171
hello.

The sample of functions that uses the dos.h file:

UNION REGS regs;

/* Initialise COM port */

regs.h.ah = 2;     /* clear always rx buffer */
regs.x.dx = com_port;
int86(0X14, &regs, &regs);

baudrate = str_encode(5);
.
.
.

inportb(base_addr+3);          /* set DLAB = 0 */
temp_byte = temp_byte & 0X7F;
outportb(base_addr,temp_byte);

it is used to communicate with the modem via the com port...therefore i think the regs is an obsolete declaration, followed by the int86 function, inportb and outportb.

How can I change the equivalent commands to VC++ using API?

I also notice the
struct ffblk ffblk declaration used in the dir.h that is also obsolete in VC++. Any ideas on the equivalent structure for this?


thank you very much.





0
 
LVL 22

Expert Comment

by:nietod
ID: 6307918
>>  is used to communicate with the modem via the com port.
Windows provides functions for dealign with serial ports.   There is LOTS of information about this.stuff in the VC help.  the best way to get there is to look up one of the communication functions, like SetCommState().  Thn go to the bottom of the page and go to the link "Communications overview"    This takes you to a very short introduction about communications.  but then you want to read forward from there and you will find many many pages of information.  To go forward you actually need to use the down arrow in the tool bar, not the right arrow.   or use the table of contents window to help you navigate around in this section of the help.

Workign with serial communications with windows is going to be very different.  The code is probably going to have to change in design a good bit.  However, you should be able to do things much more easily in windows than in DOS.


>> struct ffblk ffblk declaration used in the dir.h that is also obsolete in VC++.
What is it used for?
0
 
LVL 1

Author Comment

by:yjt
ID: 6309026
well, the ffblk structure is to be used for the dos files function example:

struct ffblk ffblk;
done = findfirst("*.CFG",&ffblk,0);

anyhow, i'm going to study more on how to use VC to communicate with the modem first...thanx for the guidance...

0
 
LVL 22

Expert Comment

by:nietod
ID: 6309063
Then look into FindFirstFile() or FindFirstFileEx()  From a previous question.

***********************

You can use the windows API functions FindFirstFile() and FindNextFile().

FindFirstFile() will find the first file in a directory that matches the search string (if there is one) and will fill in a WIN32_FIND_DATA structure with information about the file found.  It will also return a handle to information that windows needs to record so that it can find additional files.   You can then call FindNextFile() to find then next file that matches the search string.  You pass the handle returned from FindFirstFile() to FindNextFile() so it knows what to look for and it will fill in another  WIN32_FIND_DATA structure for the file found.  You then continue calling FindNextFile() until no more files are found.  You can then close the find handle using FindClose().

An example might be

   BOOL  Done;                     // Done searching for files?
   HANDLE  FndHnd = NULL;   // Handle to find data.
   WIN32_FIND_DATA FindDat;  // Info on file found.

   FndHnd = FindFirstFile("C:\\*.txt", &FindDat);
   Done = (FndHnd == INVALID_HANDLE_VALUE);       // Indicate we are done if nothing was found.

   while (!Done)
   {
      cout <<  FindDat.cFileName << endl; // Print name of file found.
      Done = !FindNextFile(FndHnd, &FindDat);
   }
   if (FndHnd != INVALID_HANDLE_VALUE)            // If there was anything found, then
      FindClose(FndHnd); // Close the find handle
0
 
LVL 1

Author Comment

by:yjt
ID: 6332645
i think this is directly supported under Visual C++:

#include <stdio.h>

FILE *stream;
char msg[200];

stream = fopen("cust.dat","rb");
fgets(msg, 200, stream);

but when i run the fopen command, VC prompts up a window asking the file source location, "Please enter the path for FOPEN.C?"

why is this so? thanx.
0
 
LVL 1

Author Comment

by:yjt
ID: 6332648
i think this is directly supported under Visual C++:

#include <stdio.h>

FILE *stream;
char msg[200];

stream = fopen("cust.dat","rb");
fgets(msg, 200, stream);

but when i run the fopen command, VC prompts up a window asking the file source location, "Please enter the path for FOPEN.C?"

why is this so? thanx.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 22

Expert Comment

by:nietod
ID: 6332687
This has nothing to do with the fopen() function.  That function absolutely never prompts for a file name.  

I think what is happening is that you created a Vc project that uses a source code file called fopen.c.  but that file got moved or deleted so when VC tries to _compiler_  not _run_ the program it asks you where the file is located.

Did you try to compile the program?  Do you get the same message?

If so, tell VC whenere the source code file (fopen.c) is located.
0
 
LVL 1

Author Comment

by:yjt
ID: 6332774
That's strange. I do not have a source file named fopen.c.

This is exactly how I get the error message. I create a new project and add in a new header file which contain the simple codes as follow:

#include <stdio.h>

int FilOpen(void);

int FilOpen(void)
{
     FILE *stream;
     char msg[200];

     stream = fopen("customer.dat","rb");
     fgets(msg,200,stream);
     
     return 0;
}

Then at the View.cpp file, I add in the reference to this file, #include <myheader.h> and call the function at the view contructor procedure. When I put a breakpoint at the fopen function, and step into the codes, i will get the prompt asking for the location of fopen.c? when i clicked on cancel, it will go into the assembler codes? is this normal when you trace into it? But when I run the program, it does not prompt me anything.


0
 
LVL 1

Author Comment

by:yjt
ID: 6332775
That's strange. I do not have a source file named fopen.c.

This is exactly how I get the error message. I create a new project and add in a new header file which contain the simple codes as follow:

#include <stdio.h>

int FilOpen(void);

int FilOpen(void)
{
     FILE *stream;
     char msg[200];

     stream = fopen("customer.dat","rb");
     fgets(msg,200,stream);
     
     return 0;
}

Then at the View.cpp file, I add in the reference to this file, #include <myheader.h> and call the function at the view contructor procedure. When I put a breakpoint at the fopen function, and step into the codes, i will get the prompt asking for the location of fopen.c? when i clicked on cancel, it will go into the assembler codes? is this normal when you trace into it? But when I run the program, it does not prompt me anything.


0
 
LVL 1

Author Comment

by:yjt
ID: 6332776
That's strange. I do not have a source file named fopen.c.

This is exactly how I get the error message. I create a new project and add in a new header file which contain the simple codes as follow:

#include <stdio.h>

int FilOpen(void);

int FilOpen(void)
{
     FILE *stream;
     char msg[200];

     stream = fopen("customer.dat","rb");
     fgets(msg,200,stream);
     
     return 0;
}

Then at the View.cpp file, I add in the reference to this file, #include <myheader.h> and call the function at the view contructor procedure. When I put a breakpoint at the fopen function, and step into the codes, i will get the prompt asking for the location of fopen.c? when i clicked on cancel, it will go into the assembler codes? is this normal when you trace into it? But when I run the program, it does not prompt me anything.


0
 
LVL 22

Expert Comment

by:nietod
ID: 6333755
>>  I create a new project and add in a new header file which
>> contain the simple codes as follow:
That would be extremely unusial code to place in a header file.   you nave a main() in there.  Procedures are sometimes declared in a header file.  They are almost never definined in one.    This is especially true of main().

>> Then at the View.cpp file,
What is in this file?  

Did id you write that file?   That sounds like an MFC file?   Your code is NOT MFC code.

What type of project did you create?   It must be a win32 console application.   Not an MFC application.
0
 
LVL 1

Author Comment

by:yjt
ID: 6336513
i have created an MFC AppWizard (EXE)project since i wanted to have forms and windows controls.

so the appview.cpp is actually the cpp file generated by the wizard. so i've actually called this header file which contains C codes from the appview contructor procedure.

does MFC actually supports the fopen operation?

if it doesn't, and i want to convert the C codes to have windows interface, i still have no choice but to start an MFC AppWizard or there is still another way?
0
 
LVL 22

Expert Comment

by:nietod
ID: 6339985
>> i have created an MFC AppWizard (EXE)project since i wanted
>> to have forms and windows controls.
Fine, but then you have to write an MFC program.   That is very different than a standard C/C++ program.  You don't have a main().  the entry point to the program will be somewhere inside the MFC code.   MFc will determient he basic behavior of your program.  its going to pop-up a dialog askign for a document to work on, or try to create a new document etc etc etc.    This is all part of MFC.

>> does MFC actually supports the fopen operation?
fopen() is part of C and C++.  An MFC application is a C++ application.  so yes it is supported.   But MFC does the bulf of the applciation design for you.   You just fillin custom code in places.  Most of what you are "looking at" is MFC's work, not your custom code.   I don't where you are even trying to call fopen(), but your code needs to be placed intot he MFC  design at the right poiints.

>> C codes to have windows interfac
If you are converting from a non-windows design to a windows design its goignt o be a HUIGE change.  You can't jsut take your non-windows code and compile it as part of an MFC application.   That doesn't work.   A windows program has a very different design.  you code needs to be completely rewritten for that design.

what Do you know about MFC?   haveyou read any books on it?  You can't expect to use it without learning about it first.
0
 
LVL 11

Expert Comment

by:griessh
ID: 6833114
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "nietod" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6853104
Per recommendation comment force/accepted by

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

746 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

9 Experts available now in Live!

Get 1:1 Help Now