Create file
HANDLE hFile = ::CreateFile(lpcszFileName, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
Create file with specified size
return (BOOL)::GetLastError();
}
::CloseHandle(hFileMap);
::CloseHandle(hFile);
WriteFile is more efficient than fwrite, because fwrite calls down to WriteFile internally
return 0;
}
Do not call FlushFileBuffers explicitly, data in system cache will be flushed to disk when needed.
Get a buffer for WriteFile, just as fwrite does, because API call cost more time than simply memcpy, call WriteFile when buffer is filled up.
For windows, fwrite() will write the data to a buffer until that buffer fills, which will cause it to send the data in the buffer to WriteFile() call. When you call fflush() all that happens is that the data currently in the buffer is passed to a call to WriteFile() – fflush() doesn't call FlushFileBuffer().
Rename a file
)) == 0)
{
cout<<::GetLastError()<<endl;
}