HANDLE CreateFile (LPCTSTR lpFileName, //所要创建的文件名
DWORD dwDesiredAccess, //GENERIC_WRITE允许写,GENERIC_READ读
DWORD dwShareMode, //其他进程对其的权限FILE_SHARE_READ,FILE_SHARE_WRITE
LPSECURITY_ATTRIBUTES lpSecurityAttributes, //安全参数,NULL
DWORD dwCreationDistribution, //打开或者创建文件的方式
DWORD dwFlagsAndAttributes, //文件属性
HANDLE hTemplateFile); //在CE中被忽略,被设置为0.
读和写文件:
1.读函数:
BOOL ReadFile (HANDLE hFile, //打开文件的句柄
LPVOID lpBuffer, //读文件所要接受的数据的缓冲区
DWORD nNumberOfBytesToRead,
LPDWORD lpNumberOfBytesRead,
LPOVERLAPPED lpOverlapped); //CE中不支持overlapped file operations,所以为NULL
2.写函数:
BOOL WriteFile (HANDLE hFile, LPCVOID lpBuffer,
DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten,
LPOVERLAPPED lpOverlapped);
移动文件指针:
//概念未理清
关闭文件:
BOOL CloseHandle (HANDLE hObject ); //关闭成功,返回TRUE,失败,调用GetLastError()返回失败原因
裁减文件:?
//概念未理清
获取文件信息:
DWORD GetFileAttributes (LPCTSTR lpFileName);
当然你也可以:
BOOL SetFileAttributes (LPCTSTR lpFileName, DWORD dwFileAttributes);
文件时间:
标准的Win32 API有3种文件时间:
文件创建时间,文件最后访问时间,文件最后修改时间。
BOOL GetFileTime (HANDLE hFile, LPFILETIME lpCreationTime,
LPFILETIME lpLastAccessTime,
LPFILETIME lpLastWriteTime);
这个函数用来获取文件时间。3个指针是指向要接受时间的FILETIME结构。如果你只对其中部分时间感兴趣,其他时间的指针就设置为NULL。
When the file times are queried for a file in the object store, Windows CE copies the last write time into all FILETIME structures. This goes against Win32 documentation, which states that any unsupported time fields should be set to 0. For the FAT file system used on storage cards, two times are maintained: the file creation time and the last write time. When GetFileTime is called on a file on a storage card, the file creation and last write times are returned and the last access time is set to 0.
BOOL FileTimeToSystemTime (const FILETIME *lpFileTime,
LPSYSTEMTIME lpSystemTime);
将一个FILETIME结构转变为一个SYSTEMTIME结构
Note:SYSTEMTIME结构里已经格式化了时间。
BOOL FileTimeToLocalFileTime (const FILETIME *lpFileTime,
LPFILETIME lpLocalFileTime);
同样,你也可以:
BOOL SetFileTime (HANDLE hFile, const FILETIME *lpCreationTime,
const FILETIME *lpLastAccessTime,
const FILETIME *lpLastWriteTime);
记住:文件时间必须是UTC时间,而不是本地时间。
不过以上仅仅只是在Win32下的,在CE中,修改时间的话,所有的3个时间参数都将被设置。如果有多个时间被设置的话,
那么最后一个设置的时间将设置3个参数;读也是一样的,CE将最后修改的时间放到所有的FILETIME结构中。文件大小和其他信息:
这样获得一个文件的大小:
DWORD GetFileSize (HANDLE hFile, LPDWORD lpFileSizeHigh);
如果你不想文件大小超过4G的话,第2个参数设为NULL。
如果你还想多知道点的话,下面这个函数怎么样?
BOOL GetFileInformationByHandle (HANDLE hFile,
LPBY_HANDLE_FILE_INFORMATION lpFileInformation);
typedef struct _BY_HANDLE_FILE_INFORMATION {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD dwVolumeSerialNumber;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD nNumberOfLinks;
DWORD nFileIndexHigh;
DWORD nFileIndexLow;
DWORD dwOID;
} BY_HANDLE_FILE_INFORMATION;
2004年11月2日21:03:26
本文地址:http://com.8s8s.com/it/it34437.htm