The first point I’d like to make is that you’re using a Microsoft Windows API, so you have already lost. You are just not quite aware of how much you have lost.
A quick look around and you say “Ahh… GetFileSize, that’s what I want to do!” Except, of course, you’re wrong. You don’t want to use GetFileSize at all. It has the following signature:
DWORD WINAPI GetFileSize( __in HANDLE hFile, __out_opt LPDWORD lpFileSizeHigh );
Yes, it supports larger than 4GB files! How? A pointer to the high-order doubleword is passed in! So how do you know if this errored? Return -1? WRONG! Because the high word could have been set and your file length could legitimately be 0×1ffffffff. So to find out if you actually had an error, you must call GetLastError! Instead of one call, you now have two.
The Microsoft documentation even acknowledges that this is stupid: “Because …
[Read more]