OnReadFileC event/delegate/callback


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

CBFSFilter     See also    


This callback is called when the OS needs to read the data from the open file.


    property OnReadFileC : TCBFSFltReadFileEventC;
    TCBFSFltReadFileEventC = procedure(Sender : TObject; FileName: TCBString; var Position: Int64; var Buffer; var BytesToRead: LongWord; Direction: LongWord; var FileContext: pointer; var HandleContext: pointer; var ProcessRequest: boolean) of object;
    type TCBString = {$ifdef UNICODE}UnicodeString{$else}WideString{$endif};

[C++ (Lib)]
    typedef void (*CBFSFltReadFileEventC)(CBFSFilter* Sender, LPWSTR FileName, __int64 *Position, PVOID Buffer, PDWORD BytesToRead, CBFSFltDataFlow Direction, PVOID* FileContext, PVOID* HandleContext, LPBOOL ProcessRequest);

[C++ (VCL)]
    typedef void __fastcall (__closure *TCBFSFltReadFileEventC)(System::TObject* Sender, TCBString FileName, __int64 &Position, void *Buffer, unsigned long &BytesToRead, unsigned Direction, void* *FileContext, void* *HandleContext, bool &ProcessRequest);

[C++ (.NET)]
    public delegate void CBFSFltReadFileEventC(CBFSFilter^ Sender, String^ FileName, Int64% Position, IntPtr Buffer, Int32% BytesToRead, CBFSFltDataFlow Direction, IntPtr% FileContext, IntPtr% HandleContext, bool% ProcessRequest);

    delegate void CBFSFltReadFileEventC(CBFSFilter^ Sender, string FileName, ref long Position, IntPtr Buffer, ref Int32 BytesToRead, CBFSFltDataFlow Direction, ref IntPtr FileContext, ref IntPtr HandleContext, ref bool ProcessRequest);

    Delegate Sub CBFSFltReadFileEventC(ByVal Sender As CBFSFilter, ByVal FileName As String, ByRef Position As Long, ByVal Buffer As IntPtr, ByRef BytesToRead As Int32, ByVal Direction As CBFSFltDataFlow, ByRef FileContext As IntPtr, ByRef HandleContext as IntPtr, ByRef ProcessRequest As Boolean)


  • Sender - reference to the class that called the delegate/event handler
  • FileName - contains the name of 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.
  • Direction - specifies the direction of the data fllow (see below)
  • FileContext - the placeholder for the application-defined data, common to all concurrent file operations on the file
  • HandleContext - the placeholder for the application-defined data, local to each opened file handle
  • ProcessRequest - specifies, whether the request must be passed further to the underlying filters and the file system

Values of CBFSFltDataFlow


This callback is called when the OS needs to read the data from the open file, before the request is passed to the underlying file system for processing. In the callback handler for this callback you can provide "fake" data to the requestor without passing the request to the underlying file system.

If you need to handle the request without passing it further, write the data (no more than BytesToRead bytes) to the provided Buffer and set ProcessRequest to false.

To report the failure and cancel reading operation you need to throw an instance of ECBFSFilterError (setting ProcessRequest to false won't cancel the operation).

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.

Attention: HandleContext can be empty, if the operation is performed by the cache manager or memory manager. In these situation, the operation is not associated with any particular handle.

Read more about cached and non-cached requests

Error handling

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

See also