BOOL MyFile::ReadAll( ByteBuffer& buffer ) { DWORD dwFileSize = ::GetFileSize(m_handle, NULL); if (0 == dwFileSize) { buffer.Free(); return TRUE; } buffer.Alloc(dwFileSize); LPBYTE lpPos = (LPBYTE) buffer; DWORD dwToRead = dwFileSize; DWORD dwRead = 0; while (::ReadFile(m_handle, lpPos, dwToRead, &dwRead, NULL) && dwRead > 0) { dwToRead -= dwRead; lpPos += dwRead; } if (0 == dwToRead) { return TRUE; } else { buffer.Free(); return FALSE; } }
DWORD MyFile::Read( DWORD dwToRead, ByteBuffer& buffer ) { if (0 == dwToRead) return 0; buffer.Alloc(dwToRead); DWORD dwRead = 0; BOOL bRet = ::ReadFile(m_handle, (LPBYTE)buffer, dwToRead, &dwRead, NULL); if (bRet) { return dwRead; } else { buffer.Free(); return 0; } }