I'm attempting to shrink a file in place.
I'm replacing the contents of one file with those of another and when I'm done I want to make sure if the source file is smaller than the dest file, the dest file shrinks correctly.
(Why: because the dest file is a backup and writing to the media is very expensive, so I only write the deltas to the backup)
1.) HANDLE hDest =(HANDLE)_get_osfhandle( fileno(backupFile.GetBufferedHandle()) );
2.) DWORD startingSize = GetFileSize(hDest, NULL);
3.) DWORD dwPtr = SetFilePointer(hDest, newSize, NULL, FILE_BEGIN);
4.) int err = GetLastError();
5.) if (dwPtr != INVALID_SET_FILE_POINTER)
6.) { err = SetEndOfFile(hDest);
7.) if(err == 0)
8.) err = GetLastError();
9.) err = SetFileValidData(hDest, newSize);
10.) }
11.) DWORD endingSize = GetFileSize(hDest, NULL);
I'm getting an error on line 8 that is 1224... I'm wondering if anyone can tell me why, or suggest a better approach.