A customer was copying a file with CopyFile­, but they wanted the file handles to be opened as FILE_.
We saw some time ago that you can use the progress callback to CopyFileEx or CopyFile2 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 CopyFileEx and CopyFile2 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 CopyFile2, 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);
CopyFile­?
Probably copy&paste error – ­ is soft hypen, but the semicolon got dropped.