Compilation of foxbase+ database browsing program under WIN32

Source: Internet
Author: User
Tags date format fread functions win32
Program | data | Database


One, Purpose


Hardware: CPU (Cyrix 200MHz), memory 16M, HDD 4G


requirements: In WINDOWS98 Explorer, double-click any foxbase+ database file icon (each file data is recorded below 10,000), the program opens the database file and displays the database contents.





Second, step


foxbase+ Database file format (refer to mark Sadler file format description and corresponding C language source program file)

Problems in
programming:


This is part of Mark Sadler's DBF.H file:


typedef unsigned char uchar;





struct Field_record/* This structure are filled in memory/*


{/* with a fread. Don't change. */


Char name[11]; /* Name of field in Asciz */


Char Typ; /* Type of field...char,numeric etc. */


Char *field_data_address; /* Offset of field in record */


#if defined (__tiny__) | | Defined (__small__) | | Defined (__medium__)


int space_holder; /* field_data_address must to bits * *


#endif


Uchar Len; /* Length of field */


Uchar Dec; /* Decimals in field */


Uchar reserved_bytes[14]; /* Reserved by dbase * *


};





struct DBF


{


Char Filename[maxpath]; /* DOS filename */


FILE *file_ptr; /* C file pointer * *


unsigned long int current_record;/* current record in memory */


Enum/* Status of File */


  {


not_open=0,


not_updated,


Updated


} status;


Uchar Num_fields; /* Number of fields * *





/* The following 7 variables are filled with a fread, does not change order or size * *


Uchar Dbf_version; /* Version character * *


Uchar Update_yr; /* Date of last Update-year (-1900) */


Uchar Update_mo; /* Date of last Update-month * *


Uchar Update_day; /* Date of last Update-day * *


unsigned long int records; /* Number of records in DBF */


unsigned int header_length; /* Length of header structure */


unsigned int record_length; /* Length of a record */


  /*                */


struct Field_record *fields_ptr; /* Pointer to field array */


Char *record_ptr; /* Pointer to current record struct * *


};





int D_addrec (struct DBF *d);


int D_blank (struct DBF *d);


int d_close (struct DBF *d);


int d_cpystr (struct dbf *s,struct dbf *d);


Char d_getfld (struct DBF *d,int f,char *buff);


int D_getrec (struct DBF *d,unsigned long int R);


int D_open (struct DBF *d);


int d_putfld (struct DBF *d,int f,char *buff);


int D_putrec (struct DBF *d,unsigned long int R);





the functions provided in the above data provide the source program, although most of them are using ANSI C, but it is for DOS mode. Update Date:


inregs.h.ah=0x2a;


Intdos (&inregs,&outregs);


d->update_day=outregs.h.dl;


d->update_mo=outregs.h.dh;


d->update_yr=outregs.x.cx-1900;


This obviously cannot be compiled under Win32. But in DOS can be compiled through, and accurately read the records of information.


Modify the above functions so that they conform to WIN32 features and compile through.


runs the program and finds that the contents of the database cannot be displayed correctly.


Since the function implementation part has been completely modified to Win32 acceptable form, there is no problem, only check DBF.H.


dos int is the same as Char 8bit, and in WIN32, int is 32bit,smallint 8bit.


modifies the DBF.h file to change all int in struct to smallint,long int instead of int.


compile and pass, the program can run normally.


Three, summary


in WIN32 following the DOS mode of C program, pay special attention to the difference between different platforms.


above procedures can also be appropriately strengthened, such as: Read the data should be a new thread, and add a progress bar to display the database file read, and then write some functions (such as find, delete, etc.), add some features, make the program more perfect.


This article was made a few years ago, hoping to help beginners.








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.