Mar 202018
 
File C2QB.ZIP from The Programmer’s Corner in
Category BASIC Language
Access Quickbasic routines ÿfrom C.
File Name File Size Zip Size Zip Type
C2QB.TXT 5879 2444 deflated
TPCREAD.ME 199 165 deflated
TPCREAD.ME.HTML 294 221 deflated

Download File C2QB.ZIP Here

Contents of the C2QB.TXT file


/***************************************************************************
* This example program should give you some help if you are trying to call
* routines written for QuickBasic from C. In the process of converting
* many of our QB stuff to C, we found that we didn't want to "give up" the
* nice QB libraries we had.
*
* The problem is, the QB4 manual has some GROSS errors in it concerning
* calling QB stuff from C. The example on page 310 (passing strings from
* C to QB) is wrong. It should read:
*
* char cstr [] = "ABC";
* struct dodo {
* int sd_len; /* THESE ARE REVERSED IN MANUAL! */
* char near *sd_addr; /* MUST DEFINE AS NEAR! */
* } near str_des; /* best to define as near */
*
* (Page 307 clearly shows that the 2 byte length comes FIRST and the 2
* byte address comes second - ever wonder if MS tests their examples?
* Obviously they didn't in this case!)
*
*
* Rather than going through all the ins-n-outs of why, (because frankly,
* I'm not sure in some cases) I thought I'd simply provide a copy of a
* program we wrote to call a routine written for QB. Note that the routine
* is an Assembler routine WRITTEN FOR QB (i.e. it isn't written in QB).
* This really doesn't make any difference, but it just lets you know that
* if you have a bunch of commercial QB libraries, you should be able to use
* them with C.
*
* The routine we are calling is called CRC. It's purpose is to calculate
* a CRC on a record. (Thanks to Tom Hanlin and Wayne Hammerly of Hammerly
* computers for providing this great routine for QB programmers!) In
* QB you would call it as:
*
* CALL CRC(STRING$,HICRC%,LOCRC%)
*
* The string is what you pass to the subroutine, and the HICRC and LOCRC are
* integers returned to you. We basically want to do the same thing from C.
* The calling sequence in C is:
*
* crc(&str_des,&hicrc,&locrc);
*
* Note that you have to set the C program up to handle all this as shown in
* the program.
*
* By the way, this program was compiled under large model and worked fine.
* The only thing we wanted to do later was pass a string which had been
* malloc'ed. This meant that it was no longer a NEAR string and could not
* possibly be NEAR (i.e. defined within the function itself.) We had to
* actually modify the assembler source to get this working since near stuff
* passes only a two byte address (which is what QB routines expect.) So,
* make SURE you define everything you are going to passing to QB routines
* as NEAR or use medium or small model (where everything is near by default.)
*
* I am sorry that I could NOT include the CRC.OBJ module with this file.
* I didn't because I didn't write it and it belongs to Tom Hanlin and Wayne
* Hammerly. But, chances are, if you're reading this you are aware of the
* ADVBAS series for QB. You can simply use the CRC module found in that
* library. If you don't have ADVBAS (library for QB) I suggest you download
* it from CompuServe or any of the thousands of BBS's which have it. By
* the way, PROBAS (the commercial version of ADVBAS) also has CRC in it.
* (Actually, I used CRC2 from PROBAS which is faster because it does a
* table lookup for CRC. CRC2 called from my C program is lightning fast!)
*
* By the way, I've only been coding in C for about 8 days now so if you see
* any gross inefficiency or my explanation isn't correct "to the letter"
* please forgive me. But, I'm sure there are a lot of QB/C programmers out
* there who will find this information useful regardless of any small
* inaccuracies there may be in the explanation.
*
* Jim Kloss
* Nochange Software - Home of "XChange" Unattended File Transfer
* 540 Silver Pine Trail
* Roswell, GA 30076-3323
* (404)587-3815 voice
* (404)641-8270 data
****************************************************************************/

#include
#include

/***************************************************************************
* The format for the routine is CRC2(STRING$,HICRC%,LOCRC%) where we pass
* it the STRING$ and it returns the HICRC% and LOCRC%. Note that we must
* define the routine as 'fortran' (or 'pascal') to tell C that the
* parameters are put onto the stack in the exact opposite order that it
* normally puts them on. (No, there is not a 'basic' that I know of...)
* The following statement is required to tell C about the QB function. It
* is a prototype really and defines the kinds of variables you will be
* sending and receiving.
****************************************************************************/
extern void fortran crc2(struct dodo near *,int near *, int near *);

/***************************************************************************
* Everything must be declared NEAR which basic is going to work with since
* it must work in the default data segment.
****************************************************************************/
struct dodo {
unsigned int sd_len;
unsigned char near *sd_addr;
} near str_des;

/***************************************************************************
* Main Program.
****************************************************************************/
void main()
{

char temp[200];
unsigned hicrc,locrc;

strcpy(temp,"This is a test."); /* results should be 236 and 29 as hi/lo */

str_des.sd_addr = temp;
str_des.sd_len = strlen(temp);

hicrc=locrc=0;

printf("%u is the hicrc and %u is the locrc before call on %s\n",hicrc,locrc,temp);
crc(&str_des,&hicrc,&locrc);
printf("%u is the hicrc and %u is the locrc after call on %s\n",hicrc,locrc,temp);
printf("If everything worked right, the results should be 236 and 29!");
}



 March 20, 2018  Add comments

Leave a Reply