8.1 The Windows CE File System(文件系统)
1 Creating and Opening Files (创建和打开文件)
HANDLE CreateFile( LPCTSTR lpFileName, DWORD dwDesiredAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes, //NULL
DWORD dwCreationDistribution,
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
dwDesiredAccess--访问权限 GENERIC_WRITE|GENERIC_READ
dwShareMode---其他线程的访问权限 FILE_SHARE_READ|FILE_SHARE_WRITE
返回:INVALID_HANDLE_VALUE 失败
可调用 GetLastError 来确定文件先前是否存在
2 Reading and Writing (读取和写入)
BOOL ReadFile( HANDLE hFile,LPVOID lpBuffer,
DWORD nNumberOfBytesToRead,
LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped); //NULL
WriteFile
3 Moving the File Pointer (移动文件指针)
DWORD SetFilePointer( HANDLE hFile ,LONG lDistanceToMove,
PLONG lpDistanceToMoveHigh,DWORD dwMoveMethod);
dwMoveMethod ---偏移量的基准 FILE_BEGIN ,FILE_CURRENT,FILE_END
查询当前的文件指针位置
nCurrFilePtr=SetFilePointer(hFile,0,0,FILE_CURRENT);
4 Closing a File (关闭文件)
BOOL CloseHandle(HANDLE hObject);
5 Truncating a File (截断文件)
将文件指针移动到想让文件结束的位置,再调用函数
BOOL SetEndOfFile (HANDLE hFile);
6 Getting File Infomation(获取文件信息)
DWORD GetFileAttributes(LPCTSTR lpFileName);
返回:FILE_ATTRIBUTE_COMPRESSED| INROM | DIRECTORY |TEMPORARY
BOOL SetFileAttributes(LPCTSTR lpFileName,DWORD dwFileAttributes);
7 File Times (文件时间)
BOOL GetFileTime (HANDLE hFile,
LPFILETIME lpCreationTime, //创建时间
LPFILETIME lpLastAccessTime, //最近一次访问时间
LPFILETIME lpLastWriteTime); //最近一次写入时间
将GetFileTime函数和其他函数返回的 FILETIME 结构可以转换为可以阅读的信息 SYSTEMTIME 结构:
BOOL FileTimeToSystemTime(const FILETIME *lpFileTime,
LPSYSTEMTIME lpSystemTime);
提供正确的时区
BOOL FileTimeToLocalFileTime ( const FILETIME *lpFileTime,
LPFILETIME lpLocalFileTime);
手工设置
SetFileTime();
8 File Size (文件大小)
DWORD GetFileSize (HANDLE hFile, LPDWORD lpFileSizeHigh);