-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;
4

2 回答 2

3

假设 pTBUFFER 是指向 TBUFFER 的指针,那么 ipBufBlock 在哪里初始化?如果不是,ipBufBlock 可能指向任何东西——甚至是无法读取因此无法写入文件的内存。

于 2012-07-02T06:32:29.613 回答
1

其他人有类似的错误,所以这也可能适用于您的情况:

WriteFile 返回错误 1784

——阿让

于 2012-07-02T06:58:20.140 回答