A customer was copying a file with CopyÂFile, but they wanted the file handles to be opened as FILE_.
We saw some time ago that you can use the progress callback to CopyÂFileÂEx or CopyÂFile2 to flush the output handle. Maybe we can use the progress callback to open the handle as unbuffered?
Nope, that doesn’t work because the progress callback gives you the already-opened handle. You can’t change its buffering flag after the fact.
But that’s okay, because CopyÂFileÂEx and CopyÂFile2 also have a flags parameter, and one of the flags is COPY_, which means that the handle should be opened as FILE_.
BOOL success = CopyFileEx(
sourceFilePath, destinationFilePath,
nullptr, nullptr, nullptr,
COPY_FILE_NO_BUFFERING);
You can do the same with CopyÂFile2, but the flags are in the options structure.
COPYFILE2_EXTENDED_PARAMETERS parameters{};
parameters.dwSize = sizeof(parameters);
parameters.dwCopyFlags = COPY_FILE_NO_BUFFERING;
HRESULT hr = CopyFile2(sourceFilePath, destinationFilePath, ¶meters);
FYI, the article title and first paragraph have a bad HTML encoded character in them.
­