Win32檔案操作

2021-08-29 20:14:04 字數 921 閱讀 8770

①開啟檔案的示例**:

handle hsrcfile = createfile(text("main.cpp"), generic_read, file_share_read, null, open_existing, file_attribute_normal, null);

if (hsrcfile==invalid_handle_value)

//以寫方式開啟檔案,寫的時候檔案不能共享。若檔案不存在則建立

handle hdestfile = createfile(text("main.cpp.bak"), generic_write, 0, null, create_always, file_attribute_normal, null);

if (hdestfile == invalid_handle_value)

②對於普通檔案(非串列埠或其他裝置),readfile同步讀時會立即返回,並不會等待直到讀取指定數量的位元組數才返回,因此可以迴圈讀大檔案,通過判斷實際讀取的位元組數來判斷檔案是否被讀完。

③windows記事本的ansi格式是可變字符集,對於ascii碼採用1個位元組存放,對於中文字元採用兩個位元組存放,沒有bom頭。對於windows的unicode編碼,採用的是小端位元組序,每個字元用兩個位元組存放,有bom頭,bom頭佔兩個位元組,這兩個位元組構成的16位數為0xfeff。正常utf-8編碼的二進位制是沒有bom標識的,而windows上的utf-8編碼的檔案有utf-8 bom標識(ef bb bf)。

④lstrlen,lstrcpy,lstrcat, wsprintf 等是windows的字串處理函式。

⑤intel處理器是小端儲存的。如0x1234這樣乙個16位的數,在記憶體中存放的順序是:

(位址低端)0x34,0x12(位址高階)

即小端儲存方式為:記憶體低位址存放資料的低位。

Win32 檔案的讀寫操作

檔案的寫操作 writefile 函式的宣告如下 bool writefile handle hfile,lpcvoid lpbuffer,dword nnumberofbytestowrite,lpdword lpnumberofbyteswritten,函式詳情見 實戰 寫入數字 寫入英文本母 ...

Win32 檔案操作的幾個API

1.建立檔案 handle createfile lpctstr lpname,dword dwaccess,dword dwsharemode,lpsecurity attributes lpsecurityattributes,dword dwcreate,dword dwarttrandfla...

win32 檔案系統

檔案系統是指作業系統用於管理磁碟上檔案的方法和資料結構 換句話說就是在磁碟上如何組織檔案的方法。getlogicaldrives 沒有引數,返回值就是當前作業系統有幾個卷 getlogicaldrivestrings getdrivetype根據返回值去判斷什麼型別,可查詢msdn文件來看返回值對應...