OnCreateFile event/delegate/callback
Filter:
Pascal C++ (Lib) C++ (VCL) C++ (.NET) C# VB.NETOverview
This event is fired when the OS handles file or directory creation event.
Declaration
[Pascal]
property OnCreateFile : TCbFsCreateFileEvent;
TCbFsCreateFileEvent = procedure(
Sender : TObject;
FileName: WideString;
DesiredAccess: LongWord;
FileAttributes: LongWord;
ShareMode: LongWord;
var FileHandleContext: Pointer
) of object;
[C++ (Lib)]
void (__stdcall *CbFsCreateFileEvent)(void* Sender,
wchar_t* FileName,
unsigned long DesiredAccess,
unsigned long FileAttributes,
unsigned long ShareMode,
void ** FileHandleContext
);
[C++ (VCL)]
typedef void (__closure *TCbFsCreateFileEvent)(
System::TObject* Sender,
WideSrting FileName,
unsigned long DesiredAccess,
unsigned long FileAttributes,
unsigned long ShareMode,
void ** FileHandleContext
);
[C++ (.NET)]
public __delegate void CbFsCreateFileEvent(
CallbackFileSystem^ Sender,
String^ FileName,
UInt32 DesiredAccess,
UInt32 FileAttributes,
UInt32 ShareMode,
IntPtr% FileHandleContext
);
[C#]
public void CbFsCreateFileEvent(
CallbackFileSystem^ Sender,
string FileName,
UInt32 DesiredAccess,
UInt32 FileAttributes,
UInt32 ShareMode,
ref IntPtr FileHandleContext
);
[VB.NET]
Sub CbFsCreateFileEvent(
ByVal Sender As CallbackFileSystem,
ByVal FileName As String,
ByVal DesiredAccess As UInt32,
ByVal FileAttributes As UInt32,
ByVal ShareMode As UInt32,
ByRef FileHandleContext As IntPtr
)
Parameters
- Sender - reference to the class that called the delegate/event handler
- FileName - the name of the file to create
- DesiredAccess - desired mode of access to the created file
- FileAttributes - the attributes to be set for the newly created file
- ShareMode -
- FileHandleContext - the placeholder for the application-defined data
Description
This event is fired when the OS wants to create a file or directory with given name and attributes. The directories are created with this call.
To check, what should be created (file or directory), check FileAttributes as follows (C++ / C# notation):
Directory = FileAttributes & FILE_ATTRIBUTE_DIRECTORY == FILE_ATTRIBUTE_DIRECTORY;
If the file name contains semicolon (":"), this means that the request is made to create a named stream in a file. The part before the semicolon is the name of the file itself and the name after the semicolon is the name of the named stream. If you don't want to deal with named streams, don't implement the handler for OnEnumerateNamedStreams event. In this case CBFS API will tell the OS that the named streams are not supported by the file system.
DesiredAccess, ShareMode and Attributes are passed as they were specified in the call to CreateFile() Windows API function.
The application can use FileHandleContext to store the reference to some information, identifying the file or directory (such as file/directory handle or database record ID or reference to the stream class etc).
The value, set in the event handler, is later passed to all operations, related to this file, together with file/directory name and attributes.
Read more about contexts.
Security checks
Your code is responsible for checking access rights of the process, which accesses the file system object. See Security checks topic for detailed information about how to check security.
Error handling
See Error handling topic for detailed information about how to report errors, which occur in the event handlers, back to Callback File System.
