WinCE檔案基本操作

2021-04-01 22:59:23 字數 2765 閱讀 4178

wince

下對檔案的基本操作

wince

對檔案操作有兩種方式:一種是用

wince

自帶的api

函式,另一種方法是用

mfc類庫種的

cfile

類。我們先用第一種的操作:

1.檔案的開啟

handle createfile(

lpctstr lpfilename,

dword dwdesireaccess,

dword dwsharemode,

lpsecurity_attributes lpsecurityattributes,

dword dwcreationdispostion,

dword dwflagsandattributes,

handle htemplatefile);

以上引數比較多,這個在

evc下有幫助,可以查到。可以舉個例子:

handle hfile;

hfile = createfile(_t(「//my documents//myfile.txt」),

generic_read,

file_share_read,

null,

open_existing,

file_attribute_normal,

null);

if(hfile == invalid_handle_value)

2.檔案的關閉

檔案使用完之後就應該及時關閉,以釋放對它的資源

bool closehandle(handle hobject);

比如說上例中

closehandle(hfile);

3.檔案的讀寫

檔案的讀

bool readfile(

handle hfile,

lpvoid lpbuffer,

dword nnumberofbytestoread,

lpdword lpnumberofbytesread,

null);

最後乙個引數在

wince

下是不支援的,所以一般用

null.

檔案的寫

bool writefile(

handle hfile,

lpcvoid lpbuffer,

dword nnumberofbyteswritten,

null);

最後乙個引數在

wince

下是不支援的,所以一般用

null.

4.檔案指標的移動

dword setfilepointer(

handle hfile,

long ldistancetomove,

plong lpdistancetomovehigh,

dword dwmovemethod);

例如:setfilepointer(hfile,0,null,file_begin);

5.獲取和設定檔案資訊

dword getfileatrribute(lpststr lpfilename);

引數表示檔名或者目錄名

dword setfileattributes(lpctstr lpfilename,dword dwfileattributes);

6.獲取和設定檔案時間

bool getfiletime(

handle hfile,

lpfiletime lpcreationtime,

lpfiletime lplastaccesstime,

lpfiletime lplastwritetime);

bool setfiletime(

handle hfile,

const filetime *lpcreationtime,

const filetime *lplastaccesstime,

const filetime *lplastwritetime);

7.獲取檔案大小

dword getfilesize(handle hfile, null);

第二種操作:使用

mfc庫

1.檔案的開啟

cfile( lpctstr lpszfilename,unit nopenflags);

或者使用

cfile::open

函式virtual bool open( lpctstr lpszfilename, uint nopenflags, cfileexception* perror =null);

2.檔案的關閉

直接呼叫

close()

方法就可以了,比如說

file.close();

3.檔案的讀寫

virtual unit read( void* lpbuf, unit ncount);

其中注意

ncount

是從檔案中讀取的最大的資料量,返回的是實際的讀取的資料量,可能小於

ncount

的值。virtual void write(const void * lpbuf, unit ncount);

4.檔案指標的移動

virtual long seek(long loff, uint nfrom); loff

表示偏移量,

nfrom

表示計算方式。

void seektobegin();

void seektoend();

WinCE檔案基本操作

wince 下對檔案的基本操作 wince 對檔案操作有兩種方式 一種是用wince 自帶的api 函式,另一種方法是用mfc 類庫種的cfile 類。我們先用第一種的操作 1 檔案的開啟 handle createfile lpctstr lpfilename,dword dwdesireacce...

WinCE 檔案操作總結

用的三種方法,歸納如下 方法一 使用mfc的cfile類 開啟用open,關閉用close 檔案指標移動用seek,讀檔案用read 寫檔案用write,獲取檔案屬性可以使用getfilestatus方法,這個可以檢視msdn,下面給幾行簡單 cfile file bool isopenok fil...

Wince下檔案操作API

序言 wince中的檔案操作使用傳統的基於控制代碼的方法 檔案通過返回控制代碼的函式開啟 讀取和寫入函式被傳遞控制代碼以便指出要操作的函式 資料在檔案中讀取和寫入的偏移量由系統維護的檔案指標來指出 最後當讀取和寫入完成時,應用程式通過關閉檔案控制代碼來表示操作的結束。正文1.1 建立和開啟檔案 ha...