Deleting from open file

 

I'd like to delete data from a binary file opened via MQL4's FileOpen. In certain situations a rollback should be done to an earlier state by erasing the end of the file. The data should be removed NOT just overwitten by 0's. Basically a truncate operation is what I need to perform. I tried to put an end-of-file character (0x1A) to the position of the first to-be-deleted data, but I got a 4104 error code. The code looked something like this:

int handle=FileOpen("data.dat",FILE_BIN|FILE_READ|FILE_WRITE);

FileWriteInteger/Double/String operations...;

int offset = <size of the data for deletion>;
FileSeek(handle, offset, SEEK_END);
FileWriteInteger(handle, 0x1A, CHAR_VALUE);

I don't want to rebuild the whole file, because that would take a lot of time. The best would be to just drop the unnecessary data from the end of the file and continue writing into it as if the deleted data would have never been added to it.

Please help.