WinCE
我们先用第一种的操作:
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)
{
AfxMessageBox(_T(“
return;
}
文件使用完之后就应该及时关闭,以释放对它的资源
BOOL CloseHandle(HANDLE hObject);
比如说上例中
CloseHandle(hFile);
文件的读
BOOL ReadFile(
HANDLE hFile,
LPVOID lpBuffer,
DWORD nNumberOfBytesToRead,
LPDWORD lpNumberOfBytesRead,
NULL);
最后一个参数在WINCE
文件的写
BOOL WriteFile(
HANDLE hFile,
LPCVOID lpBuffer,
DWORD nNumberOfBytesWritten,
NULL);
最后一个参数在WINCE
DWORD SetFilePointer(
HANDLE hFile,
LONG lDistanceToMove,
PLONG lpDistanceToMoveHigh,
DWORD dwMoveMethod);
例如:
SetFilePointer(hFile,0,NULL,FILE_BEGIN);
DWORD GetFileAtrribute(LPSTSTR lpFileName);
参数表示文件名或者目录名
DWORD SetFileAttributes(LPCTSTR lpFileName,DWORD dwFileAttributes);
BOOL GetFileTime(
HANDLE hFile,
LPFILETIME lpCreationTime,
LPFILETIME lpLastAccessTime,
LPFILETIME lpLastWriteTime);
BOOL SetFileTime(
HANDLE hFile,
const FILETIME *lpCreationTime,
const FILETIME *lpLastAccessTime,
const FILETIME *lpLastWriteTime);
DWORD GetFileSize(HANDLE hFile, NULL);
第二种操作:使用MFC
CFile( LPCTSTR lpszFileName, UNIT nOpenFlags);
或者使用CFile::Open
Virtual BOOL Open( LPCTSTR lpszFileName, UINT nOpenFlags, CFileException* pError =NULL);
直接调用Close()
Virtual UNIT Read( void* lpBuf, UNIT nCount);
其中注意nCount
Virtual void Write(const void * lpBuf, UNIT nCount);
Virtual LONG Seek(LONG lOff, UINT nFrom); lOff
Void SeekToBegin();
Void SeekToEnd();