怎麼清空一個用CreateFile打開的文件呢,文件是GENERIC_READ|GENERIC_WRITE的,
用FlushFileBuffers嗎?怎麼無法清空呢?
謝謝!
http://community.csdn.net/Expert/topic/3965/3965695.xml?temp=.7716333
用FlushFileBuffers嗎?怎麼無法清空呢?
謝謝!
http://community.csdn.net/Expert/topic/3965/3965695.xml?temp=.7716333
我转换一下把
问题是:
怎么清空一个用CreateFile打开的文件呢,文件是GENERIC_READ|GENERIC_WRITE的,
用FlushFileBuffers吗?怎么无法清空呢?
谢谢!
http://community.csdn.net/Expert/topic/3965/3965695.xml?temp=.7716333
具體怎麼做呢?假設hFile是CreateFile的return,
好像沒有SetLength Function!!
void CFile::SetLength(DWORD dwNewLen)
{
ASSERT_VALID(this);
ASSERT(m_hFile != (UINT)hFileNull); Seek((LONG)dwNewLen, (UINT)begin); if (!::SetEndOfFile((HANDLE)m_hFile))
CFileException::ThrowOsError((LONG)::GetLastError());
}CFile::SetLength 又调用了 CFile::Seek LONG CFile::Seek(LONG lOff, UINT nFrom)
{
ASSERT_VALID(this);
ASSERT(m_hFile != (UINT)hFileNull);
ASSERT(nFrom == begin || nFrom == end || nFrom == current);
ASSERT(begin == FILE_BEGIN && end == FILE_END && current == FILE_CURRENT); DWORD dwNew = ::SetFilePointer((HANDLE)m_hFile, lOff, NULL, (DWORD)nFrom);
if (dwNew == (DWORD)-1)
CFileException::ThrowOsError((LONG)::GetLastError()); return dwNew;
}
SetEndOfFilehaha
thank you!