Instant control over file and folder operations in Windows and .NET applications

OnReadFileC event/delegate/callback


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

CallbackFilter     See also    


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


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

[C++ (Lib)]
    typedef void (*CbFltReadFileEventC)(CallbackFilter* Sender, LPWSTR FileName, __int64 *Position, PVOID Buffer, PDWORD BytesToRead, BOOL Cached, PVOID* UserContext, LPBOOL ProcessRequest);

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

[C++ (.NET)]
    public delegate void CbFltReadFileEventC(CallbackFilter^ Sender, String^ FileName, Int64% Position, IntPtr Buffer, Int32% BytesToRead, bool Cached, IntPtr% UserContext, bool% ProcessRequest);

    delegate void CbFltReadFileEventC(CallbackFilter^ Sender, string FileName, ref long Position, IntPtr Buffer, ref Int32 BytesToRead, bool Cached, ref IntPtr UserContext, ref bool ProcessRequest);

    Delegate Sub CbFltReadFileEventC(ByVal Sender As CallbackFilter, ByVal FileName As String, ByRef Position As Long, ByVal Buffer As IntPtr, ByRef BytesToRead As Int32, ByVal Cached As Boolean, ByRef UserContext 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.
  • Cached - specifies if the operation is a cached read (see description)
  • UserContext - the placeholder for the application-defined data
  • ProcessRequest - specifies, whether the request must be passed further to the underlying filters and the file system


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 ECBFltError (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.

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 CallbackFilter.

See also


Back to top