-1

I get an I/O Error 1784 due to blockwrite in the following code which overwrites 3 times a file.

I presume I/O Error 1784 means ERROR_INVALID_USER_BUFFER.

I don't know why. The error appears sometimes, not at each run...

Could you help me ?

   procedure overwrite_files_3_times(iPath : string); 
    var
      numwritten : integer;
      iFileSize, iPosition : int64;
      InFile : File of byte;
      ipBufBlock : pTBUFFER;
      k : integer;

    begin
      if not FileExists(iPath) then
        exit;   


      FileMode := fmOpenRead or fmOpenWrite or fmShareDenyNone;      

      AssignFile(InFile, iPath);
      Reset(InFile);


      iFileSize := getfilesize2(iPath);  // retrieve the filesize
      iPosition := 0;



          // 3 overwrites
          for k:= 0 to 3-1 do
            begin
              Seek(InFile, 0);
              iPosition := 0;
              ///////////////////
              // on écrit
              while iPosition + sizeOf(TBuffer) < iFileSize do
                begin
                  BlockWrite(InFile,ipBufBlock^,sizeOf(TBuffer),numwritten);               
                  iPosition := iPosition + sizeOf(TBuffer);                                
                end;

              // the end
              if iPosition <= iFileSize -1 then
                begin
                 BlockWrite(InFile,ipBufBlock^,iFileSize-iPosition,numwritten);    //-->> generate I/O Error 1784       
                end;                                                                      
            end;


      ////////////////
      CloseFile(InFile);
end;
Taz
  • 3,718
  • 2
  • 37
  • 59
user382591
  • 1,320
  • 5
  • 19
  • 39

2 Answers2

3

Assuming pTBUFFER is a pointer to TBUFFER, where is ipBufBlock initialized? If it isn't, ipBufBlock may point to anything - even memory that cannot be read and thus not be written to the file.

Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
1

Someone else had a similair error, so this might apply to your case too:

WriteFile returning error 1784

-- Arjan

Community
  • 1
  • 1
Arjan de Haan
  • 29
  • 1
  • 4