Yea, it really pay off to wrap this stuff up. That's what i did and it's one of the file i use the most in my library. The header look like this:
class CFileIO {
public:
CFileIO();
~CFileIO();
private:
HANDLE hFile;
public:
bool IsOpened();
bool OpenForReading(char *fname, bool CanWrite = false);
bool OpenForWriting(char *fname, bool CanRead = false);
bool OpenForAppending(char *fname, bool CanRead = false);
void Close();
UI64 GetSize();
void Flush();
UI64 Tell();
void Seek(UI64 uiDistanceToMove, DWORD dwMoveMethod = FILE_BEGIN);
void Seek(LARGE_INTEGER liDistanceToMove, DWORD dwMoveMethod = FILE_BEGIN);
UINT Read(void *pBuffer, UINT NumBytesToRead);
UINT Write(void *pBuffer, UINT NumBytesToWrite);
};
Just look how easy it is after that to read to a file, for example...
void SomeFunction()
{
BYTE Buffer[1024];
CFileIO f;
if(f.OpenForReading("SomeFile.bin")){
f.Read(&Buffer[0], 1024);
f.Close();
}
}
If you want the code, i don't mind, just tell me. I also have one to handle text file too.