Win32下Foxbase+資料庫瀏覽程式的編寫 (轉)
一、目的
: (Cyrix 200MHz ), 16M,4G
要求:在98的中滑鼠雙擊任何一個Foxbase+圖示(每個檔案資料記錄在一萬條以下),開啟資料庫檔案並顯示資料庫內容。
二、步驟
Foxbase+資料庫檔案格式(參照Mark Sadler的檔案格式說明和相應C語言源程式檔案)
中發生的問題:
以下是Mark Sadler的F.H檔案部分內容:
typedef unsigned char UCHAR;
struct FIELD_RECORD /* This structure is filled in memory */
{ /* with a fread. do not 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 be 32 bits */
#endif
UCHAR len; /* length of field */
UCHAR dec; /* decimals in field */
UCHAR reserved_bytes[14]; /* reserved by se */
};
struct DBF
{
char filename[MA]; /* dfilename */
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, do 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);
以上資料中提供的都提供了源程式,雖然大部分都是使用ANSI C,但卻是針對DOS方式下的。如日期:
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;
這顯然在下無法編譯透過。但在DOS下完全可以編譯透過,並準確地讀出各條記錄資訊。
修改以上各函式,使之符合WIN32特點,編譯透過。
執行程式,發現無法正確顯示資料庫內容。
由於函式實現部分已經全部修改為Win32可以接受的形式,沒什麼問題,只有檢查DBF.H。
DOS的int與char一樣為8bit, 而WIN32中,int 為32bit,Smallint 為8bit。
修改DBF.h檔案,將struct中所有的int 改為Smallint,long int 改為int。
編譯透過,程式能正常執行。
三、總結
在WIN32沿用DOS方式下的C程式時,要特別注意不同平臺下的區別。
以上程式還可適當加強,如:讀入各項資料時應新建一執行緒,並增加一進度條顯示資料庫檔案讀入情況,再編寫一些函式(如Find、Delete等),增加一些功能,使程式更加完美。
本文是幾年前所作,希望對初學者有所幫助。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10794571/viewspace-974729/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- LotusDomino編寫Web瀏覽器多資料庫檢索程式Web瀏覽器資料庫
- 使用瀏覽器命令列編寫JavaScript程式碼瀏覽器命令列JavaScript
- 瀏覽器資料庫 IndexedDB(一) 概述瀏覽器資料庫Index
- 微軟效仿Firefox 建立IE瀏覽器BUG資料庫(轉)微軟Firefox瀏覽器資料庫
- Win32彙編教程二 Win32彙編程式的結構和語法 (轉)Win32
- 利用 Powershell 編寫簡單的瀏覽器指令碼瀏覽器指令碼
- Win32彙編教程四 編寫一個簡單的視窗 (轉)Win32
- 瀏覽器資料庫 IndexedDB 入門教程瀏覽器資料庫Index
- 在瀏覽器上儲存資料(轉)瀏覽器
- 編寫資料庫設計文件資料庫
- ASP.Net寫的瀏覽器間諜 (轉)ASP.NET瀏覽器
- 一張圖瀏覽資料庫各種型別資料庫型別
- 利用Win32的網路函式建立一個網路瀏覽器 (轉)Win32函式瀏覽器
- Billy Belceb 病毒編寫教程for Win32 ----Win32優化Win32優化
- Billy Belceb 病毒編寫教程for Win32 ----Win32多型Win32多型
- isql指令碼編寫建立資料庫SQL指令碼資料庫
- Laravel 自增瀏覽數實現(資料庫 + Redis)Laravel資料庫Redis
- Linux 下使用 IE瀏覽器(轉)Linux瀏覽器
- unix下編寫socket程式的一般步驟(轉)
- 用匯編編寫DOS下的記憶體駐留程式(5) (轉)記憶體
- 用匯編編寫DOS下的記憶體駐留程式(3) (轉)記憶體
- 用匯編編寫DOS下的記憶體駐留程式(4) (轉)記憶體
- Billy Belceb 病毒編寫教程for Win32 ----Win32 反除錯Win32除錯
- C#下資料庫程式設計(二) (轉)C#資料庫程式設計
- 瀏覽資料夾中的圖片(用VB實現) (轉)
- Win32環境下動態連結庫(DLL)程式設計原理 (轉)Win32程式設計
- ChiselStore:Rust編寫的Raft分散式SQLite資料庫RustRaft分散式SQLite資料庫
- 如何編寫同時用於 Node 和瀏覽器的 JavaScript 包瀏覽器JavaScript
- 編寫易讀的程式碼 (轉)
- Billy Belceb 病毒編寫教程for Win32 ----高階Win32技術Win32
- VC在windows下編寫用於序列通訊的程式 (轉)Windows
- [翻譯]Billy Belceb 病毒編寫教程for Win32 ----病毒編寫中的有用的東西Win32
- 資料庫課程作業筆記 - 編寫資料填充資料庫筆記
- Linux伺服器部署Web版VSCode,在window下使用瀏覽器在linux環境下編寫程式碼Linux伺服器WebVSCode瀏覽器
- 用Rust編寫的資料庫GreptimeDB現開源Rust資料庫
- 貓學Grails之完善編寫的第一個程式和資料庫設定AI資料庫
- Billy Belceb 病毒編寫教程for Win32 ----附錄Win32
- (轉載)編寫高效的jQuery程式碼jQuery