OnReadFile event/delegate/callback

Filter:

Pascal    C++ (Lib)    C++ (VCL)    C++ (.NET)    C#    VB.NET    Java 

CBFSConnect     See also    

Overview

This event is fired when the OS needs to read the data from the open file or volume.

Declaration

[Pascal]
    property OnReadFile : TCBReadFileEvent;
    TCBReadFileEvent = procedure( Sender : TObject; FileInfo: TCBFileInfo; Position: Int64; var Buffer; BytesToRead: LongWord; var BytesRead: LongWord ) of object;

[C++ (Lib)]
    void (__stdcall *CBReadFileEvent)(void* Sender, CBFileInfo* FileInfo, __int64 Position, void * Buffer, unsigned long BytesToRead, unsigned long & BytesRead );

[C++ (VCL)]
    typedef void (__closure *TCBReadFileEvent)( System::TObject* Sender, TCBFileInfo* FileInfo, __int64 Position, void * Buffer, unsigned long BytesToRead, unsigned long & BytesRead );

[C++ (.NET)]
    public __delegate void CBReadFileEvent( CBFSConnect^ Sender, CBFileInfo^ FileInfo, Int64 Position, CbFsManagedBuffer Buffer, Int32 BytesToRead, Int32% BytesRead );
    typedef array<unsigned char>^ CbFsManagedBuffer;

    public __delegate void CBReadFileNativeEvent( CBFSConnect^ Sender, CBFileInfo^ FileInfo, Int64 Position, IntPtr Buffer, Int32 BytesToRead, Int32% BytesRead );

[C#]
    public void CBReadFileEvent( CBFSConnect Sender, CBFileInfo FileInfo, Int64 Position, byte[] Buffer, Int32 BytesToRead, ref Int32 BytesRead );

    public void CBReadFileNativeEvent( CBFSConnect Sender, CBFileInfo FileInfo, Int64 Position, IntPtr Buffer, Int32 BytesToRead, ref Int32 BytesRead );

[VB.NET]
    Sub CBReadFileEvent( ByVal Sender As CBFSConnect, ByVal FileInfo As CBFileInfo, ByVal Position As Int64, ByVal Buffer As Byte(), ByVal BytesToRead As Int32, ByRef BytesRead As Int32 )

    Sub CBReadFileNativeEvent( ByVal Sender As CBFSConnect, ByVal FileInfo As CBFileInfo, ByVal Position As Int64, ByVal Buffer As IntPtr, ByVal BytesToRead As Int32, ByRef BytesRead As Int32 )

[Java]
    void ICbFsFileEvents.onReadFile( CBFSConnect sender, CBFileInfo fileInfo, long position, byteArrayRef buffer, int bytesToRead, intRef bytesRead );

Parameters

  • Sender - reference to the class that called the delegate/event handler
  • FileInfo - contains the information about the file
  • Position - the starting position to read the file data from
  • Buffer - the buffer to put the read data
  • BytesToRead - the number of bytes to read from the file. The Buffer contains not more space, than this value.
  • BytesRead - the event handler must set the parameter to the number of bytes actually read from the file.

Description

This event is fired when the OS needs to read the data from the open file or volume. Write the data (no more than BytesToRead bytes) to the povided Buffer. Put the actual number of read bytes to BytesRead. Note, that unless you create the virtual disk for some specific application, your callback handler should be able to provide exactly BytesToRead bytes of data. Reading less data than expected is an unexpected situation for many applications, and they will fail if you provide less bytes than requested.
In .NET you should not try to replace the Buffer. Instead you need to copy the data to the provided buffer. You can use Array.Copy method for this.

Read more about contexts.

Error handling

See Error handling topic for detailed information about how to report errors, which occur in the event handlers, back to CBFS Connect.

See also

MaxReadBlockSize property     GetHandleInfo method     OnCreateFile event     OnOpenFile event     OnWriteFile event