Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Creation and memory mapping existing DBF files as alternative of data serialization during work with modified CListCtrl classes in virtual mode on dialogs of MDI application

, 22 Jul 2009
The demonstration of reading, writing and creation of standard DBF files with random access in memory instead of serialization of typical MFC application for descendants of CListCtrl classes in Virtual Mode.
ModifiedListCtrl04.zip
ModifiedListCtrl04
Bin
Main.exe
Dbf
First.dbf
Second.dbf
Third.dbf
ListCtrlEx
Main.aps
Main.clw
Main.dsp
Main.dsw
Main.ncb
Main.opt
Main.plg
res
Main.ico
MainDoc.ico
Toolbar.bmp
Toolbar2.bmp
Toolbar2_.bmp
/////////////////////////////////////////////////////////////////////////////
// DBF.h : interface of the CDBF class
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_DBF_H__EMERY_EMERALD__INCLUDED_)
	#define AFX_DBF_H__EMERY_EMERALD__INCLUDED_

	#if _MSC_VER > 1000
		#pragma once
	#endif // _MSC_VER > 1000

	//*** Visual FoxPro dbf type
	#define VFPTYPE							48  // = 0x30 ("0")
	//*** Base year
 	#define BASEYEAR					2000  // For Visual FoxPro dbf type
	//*** Header record terminator
	#define HEADEREND						13  // = 0x0D
	//*** File record terminator
	#define DBFEND							26  // = 0x1A

	//*** Code page marks
 	#define CP1250						0xC8  // Eastern European Windows
 	#define CP1251						0xC9  // Russian Windows
 	#define CP1252						0x03  // Windows ANSI
 	#define CP1253						0xCB  // Greek Windows
 	#define CP1254						0xCA  // Turkish Windows

	//*** The types of dbf fields
	#define TYPE_C						0x43  // Character
	#define TYPE_N						0x4E  // Numeric 
	#define TYPE_F						0x46  // Float 
	#define TYPE_D						0x44  // Date 
	#define TYPE_L						0x4C  // Logical 
	#define TYPE_M						0x4D  // Memo 
	#define TYPE_G						0x47  // General 
	#define TYPE_B						0x42  // Double 
	#define TYPE_I						0x49  // Integer 
	#define TYPE_Y						0x59  // Currency 
	#define TYPE_T						0x54  // DateTime 
	#define TYPE_P						0x50  // Picture

	//*** Turns off alignment of data at all
	#pragma pack(1)

	//*** The dbf header structure
	typedef struct {
		/*00-00*/ BYTE cType;  // File type
		// 0x02 FoxBASE
		// 0x03 FoxBASE+/dBASE III PLUS, no memo
		// 0x30 Visual FoxPro
		// 0x31 Visual FoxPro, autoincrement enabled
		// 0x43 dBASE IV SQL table files, no memo
		// 0x63 dBASE IV SQL system files, no memo
		// 0x83 FoxBASE+/dBASE III PLUS, with memo
		// 0x8B dBASE IV with memo
		// 0xCB dBASE IV SQL table files, with memo
		// 0xF5 FoxPro 2.x (or earler) with memo
		// 0xFB FoxBASE
		/*01-01*/ BYTE cYear;  // Year of last update
		/*02-02*/ BYTE cMonth;  // Month of last update
		/*03-03*/ BYTE cDay;  // Day of last update
		//* Fox: Curent century + YY
		//* dBase: 1900 + YY
		//* SIx: 0x700(1792) + YY
		/*04-07*/ ULONG nRecCount;		// Number of records in file
		/*08-09*/ WORD wFirstRec;	// Position of first data record
		/*10-11*/ WORD wRecSize;  // Length of one data record, including delete flag
		/*12-27*/ BYTE cReserv1227[16];	// Reserved, contains 0x00
		/*28-28*/ BYTE cFlag;	// Table Flags (Only Visual Foxpro)
		// 0x01 file has structural .cdx or .mdx
		// 0x02 file has a Memo field
		// 0x04 file is a database .dbc
		// This byte can contain the sum of any of the above values
		/*29-29*/ BYTE cCodePage;	// Code page mark
		// 0x01 437    U.S. MS-DOS
		// 0x69	620    Mazovia (Polish) MS-DOS
		// 0x6A 737    Greek MS-DOS (437G)
		// 0x02 850    International MS-DOS
		// 0x64 852    Eastern European MS-DOS
 		// 0x67 861    Icelandic MS-DOS
 		// 0x66 865    Nordic MS-DOS
 		// 0x65 866    Russian MS-DOS
 		// 0x68 895    Kamenicky (Czech) MS-DOS
 		// 0x6B 857    Turkish MS-DOS
 		// 0xC8 1250   Eastern European Windows
 		// 0xC9 1251   Russian Windows
 		// 0x03 1252   Windows ANSI
 		// 0xCB 1253   Greek Windows
 		// 0xCA 1254   Turkish Windows
		/*30-31*/ WORD wReserv3031;  // Reserved, contains 0x00
	} DBF_HEADER;

	//*** The dbf field structure
	typedef struct {
		/*00-10*/ BYTE acName[11];  // Field name
		// Field name with a maximum of 10 characters. If less than 10, it 
		// is padded with null characters (0x00)
		/*11-11*/ BYTE cType;	// Field type
		// C � Character 
		// N � Numeric 
		// F � Float 
		// D � Date 
		// L � Logical 
		// M � Memo 
		// G � General 
		// B � Double 
		// I � Integer 
		// Y � Currency 
		// T � DateTime 
		// P � Picture
		/*12-15*/ ULONG nOffset;  // Displacement of field in record
		/*16-16*/ BYTE cLen;	// Length of field (in bytes)
		/*17-17*/ BYTE cDec;	// Number of decimal places
		/*18-18*/ BYTE cFlag;	// Field flag
		// 0x01 System Column (not visible to user)
		// 0x02 Column can store null values
		// 0x04 Binary column (for CHAR and MEMO only)
		// 0x06 (0x02+0x04) When a field is NULL and binary (Integer, Currency, and 
		// Character/Memo fields) 
		// 0x0C Column is autoincrementing
		/*19-22*/ LONG nNext;  // Value of auto increment Next value 
		/*23-23*/ BYTE cStep;  // Value of auto increment Step value 
		/*24-31*/ BYTE cReserv2431[8];	// Reserved, contains 0x00
	} DBF_FIELD;
	/*
	//*** The real dbf record structure
	typedef struct {
		BYTE cDelete;
		BYTE acData1[FLDLEN1];
		BYTE acData2[FLDLEN2],
		. . .
		BYTE acDataN[FLDLENN];
	} DBF_RECORD;
	*/
	/*
	//*** The dbf record structure
	typedef struct {
		BYTE cDelete;  // Delete flag
		BYTE acRecData[1];  // Really DbfHdr.wRecSize = FLDLEN1+FLDLEN2+...+FLDLENN bytes are
	} DBF_RECORD;
	*/
	//*** The dbf file structure (Part No. 1)
	typedef struct {
		DBF_HEADER DbfHdr;  // Dbf header structure
		DBF_FIELD aDbfField[1];  // Really FLDCOUNT = (DbfHdr.wFirstRec-296)/32 fields are
		//BYTE cHdrEnd;  // Header record terminator = 0x0D (13)
		//BYTE acDbcFile[263];    // A data range for associated *.dbc file, else 
		// contains 0x00. It is for Visual FoxPro only (when DbfHdr.cType = VFPTYPE)
		//DBF_RECORD aDbfRec[1];  // Really DbfHdr.nRecCount records are
		//BYTE cFileEnd;  // File record terminator = 0x1A (26)
	} DBF_FILE1;

	//*** The dbf file structure (Part No. 2)
	typedef struct {
		//DBF_HEADER DbfHdr;  // Dbf header structure
		//DBF_FIELD aDbfField[1];  // Really FLDCOUNT = (DbfHdr.wFirstRec-296)/32 fields are
		BYTE cHdrEnd;  // Header record terminator = 0x0D (13)
		BYTE acDbcFile[263];    // A data range for associated *.dbc file, else 
		// contains 0x00. It is for Visual FoxPro only (when DbfHdr.cType = VFPTYPE)
		BYTE aDbfRec[1];  // Really DbfHdr.wRecSize * DbfHdr.nRecCount records are
		//BYTE cFileEnd;  // File record terminator = 0x1A (26)
	} DBF_FILE2;
	/*
	//*** The dbf-file data table structure
	typedef struct {
		BYTE *pcFldName;  // Field name
		BYTE cFldType;  // Field type
		BYTE cFldLen;  // Field lenght (in bytes)
		BYTE cDecLen;  // Number of decimal places (in bytes)
	} DATA_HEADER;
	*/
	//*** Turns on alignment by default
	#pragma pack()
	//{{AFX_INSERT_LOCATION}}
	// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DBF_H__EMERY_EMERALD__INCLUDED_)

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Emery Emerald
Software Developer
Ukraine Ukraine
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 22 Jul 2009
Article Copyright 2009 by Emery Emerald
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid