Control registry operations in Windows and .NET applications

OnPreCreateKey event/delegate/callback


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

CallbackRegistry     See also    


This callback is called before key creation request is processed by the system code which deals with the registry.


    property OnPreCreateKey : TCbRegPreCreateKeyEvent;
    TCbRegPreCreateKeyEvent = procedure( Sender : TObject; FullName : TCBString; DesiredAccess: ACCESS_MASK; var KeyHandle: THandle; var KeyHandleContext: pointer; var GrantedAccess: ACCESS_MASK; var UserContext: pointer; var StopFiltering : boolean ) of object;
    type TCBString = {$ifdef UNICODE}UnicodeString{$else}WideString{$endif};

[C++ (Lib)]
    typedef void (*CbRegPreCreateKeyEvent)( CallbackRegistry* Sender, LPCWSTR FullName, DWORD DesiredAccess, HANDLE *KeyHandle, LPVOID *KeyHandleContext, DWORD *GrantedAccess, LPVOID *UserContext, BOOL * StopFiltering );

[C++ (VCL)]
    typedef void __fastcall (__closure *TCbRegPreCreateKeyEvent)( System::TObject* Sender, TCBString FullName, unsigned DesiredAccess, unsigned &KeyHandle, void* &KeyHandleContext, unsigned &GrantedAccess, void * &UserContext, bool &StopFiltering );
    #ifdef UNICODE
    typedef UnicodeString TCBString;
    typedef WideString TCBString;

[C++ (.NET)]
    public delegate void CbRegPreCreateKeyEvent( CallbackRegistry^ Sender, String^ FullName, UInt32 DesiredAccess, SafeHandle^ %KeyHandle, Object^ %KeyHandleContext, UInt32 %GrantedAccess, Object^ UserContext, bool %StopFiltering );

    delegate void CbRegPreCreateKeyEvent( CallbackRegistry Sender, string FullName, UInt32 DesiredAccess, ref SafeHandle KeyHandle, ref Object KeyHandleContext, ref UInt32 GrantedAccess, ref Object UserContext, ref bool StopFiltering );

    Delegate Sub CbRegPreCreateKeyEvent( ByVal Sender As CallbackRegistry, ByVal FullName As String, ByVal DesiredAccess As UInt32, ByRef KeyHandle As SafeHandle, ByRef KeyHandleContext As Object, ByRef GrantedAccess As UInt32, ByRef UserContext As Object, ByRef StopFiltering As Boolean )


  • Sender - reference to the class that called the delegate/event handler
  • FullName - The "full" name of the key to be created in system format (for example for "HKEY_LOCAL_MACHINE\System" key the name will be "\Registry\Machine\System").
  • DesiredAccess - The access mask that was specified by the thread that is attempting to create the registry key.
  • KeyHandle - handle of the key which the application may open instead of the system-opened key (see Description for details)
  • KeyHandleContext - the placeholder for the application-defined data which will be passed to OnCloseHandle event
  • GrantedAccess - if the KeyHandle parameter is used the granted access rights must be set here
  • UserContext - the placeholder for the application-defined data
  • StopFiltering - If StopFiltering is set to true, no other callbacks for the created key handle will be called


This callback/event handler is called before a key is created. You can pass the name of the key to other callbacks/event handlers by storing FullName in the UserContext object that you create.
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 CallbackRegistry.

See also

OnCloseKeyHandle     OnPostCreateKey     OnPreCloseKey     OnPreOpenKey    

Back to top