I am using VB6 and the Win32 API to write data to a file, this functionality is for the export of data, therefore write performance to the disk is the key factor in my considerations. As such I am using the FILE_FLAG_NO_BUFFERING
and FILE_FLAG_WRITE_THROUGH
options when opening the file with a call to CreateFile
.
FILE_FLAG_NO_BUFFERING
requires that I use my own buffer and write data to the file in multiples of the disk's sector size, this is no problem generally, apart from the last part of data, which if it is not an exact multiple of the sector size will include character zero's padding out the file, how do I set the file size once the last block is written to not include these character zero's?
I can use SetEndOfFile
however this requires me to close the file and re-open it without using FILE_FLAG_NO_BUFFERING
. I have seen someone talk about NtSetInformationFile
however I cannot find how to use and declare this in VB6. SetFileInformationByHandle
can do exactly what I want however it is only available in Windows Vista, my application needs to be compatible with previous versions of Windows.