Download EaseFilter Monitor, Control and Encryption Filter Driver SDK Setup File Download EaseFilter Monitor, Control and Encryption Filter Driver SDK Zip File
Sets the physical file size for the specified file to the current position of the file pointer.
The physical file size is also referred to as the end of the file. The SetEndOfFile function can be used to truncate or extend a file. To set the logical end of a file, use the SetFileValidData function.
BOOL SetEndOfFile( HANDLE hFile );
hFile
A handle to the file to be extended or truncated.
The file handle must be created with the GENERIC_WRITE access right. For more information, see File Security and Access Rights.
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero (0). To get extended error information, call GetLastError.
The SetEndOfFile function can be used to truncate or extend a file. If the file is extended, the contents of the file between the old end of the file and the new end of the file are not defined.
Each file stream has the following:
If
CreateFileMapping is called to create a file mapping object for hFile, UnmapViewOfFile must be called first to unmap all views and call CloseHandle to close the file mapping object before you can call SetEndOfFile.
Example
LPCTSTR lpfname = TEXT("C:\\test.tmp"); LONG lsize = 10000000; // ~10MB DWORD dwErr; HANDLE file = CreateFile(lpfname, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_NEW|OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); dwErr = GetLastError(); if (dwErr > 0) { cout << "Error Code: " << dwErr << endl; } SetFilePointer(file, lsize, 0, FILE_BEGIN); SetEndOfFile(file); CloseHandle(file);