Subject KeyCallback function not passing Callback argument properly


I am trying to create a KeyHolderPlugin using the Delphi API for Firebird.  I am running Firebird version 3.0.3 on for an x64 installation of Windows.  I have been steadily working through the OOAPI documentation, and so far I have learned a great deal about how to interact with Firebird through Delphi.

So far, I have used Delphi to create a DBCrypt plugin as well as a KeyHolder plugin, modelled after the examples provided in the Firebird installation (which are written in C++).  I am able to use my CryptKeyHolder plugin to pass key values to Firebird from an external config file.  I would like to be able to pass the key value from an application instead of from a config file.

My understanding of this process is as follows.  First, we call setDbCryptCallback() from the application, with an argument of a type that implements the ICryptKeyCallback interface.  In my code, this type is called TCryptKey.  Calling setDbCryptCallback() passes the TCryptKey object into the KeyHolder plugin's keyCallback() function.  The actual callback is then be performed from inside keyCallback() by calling TCryptKey.callback().  Please correct me if this understanding is incorrect.

My problem is this: upon calling setDbCryptCallback() with a TCryptKey object, the TCryptKey object's callback() function is not properly called from the keyCallback() function.  (I know this to be the case, because I have debug code that writes to a file when TCryptKey.callback() gets accessed, and it is not showing up.)

Sample code:

{ TCryptKey definition in the application}

TCryptKey = class(ICryptKeyCallbackImpl)


    // ICryptKeyCallback implementation

    function callback(dataLength: Cardinal; data: Pointer; bufferLength: Cardinal; buffer: Pointer): Cardinal; override;


function TCryptKey.callback(dataLength: Cardinal; data: Pointer; bufferLength: Cardinal; buffer: Pointer): Cardinal;


  k : Byte;


  debugLog('TCryptKey.callback: entered'); // this line is not being printed to debug file

  if (bufferLength > 0) and Assigned(buffer) then begin

     k := 13; // I want to pass in a key value of 13 from the application

     CopyMemory(buffer, @k, 1); // DEMO - key is a single byte

     Result := 1;



{ We call setDbCryptCallback with a TCryptKey object somewhere in the application }

FCryptKey := TCryptKey.Create;

prov.setDbCryptCallback(st, FCryptKey); // prov and st are already assigned

{ keyCallback function in the KeyHolder DLL file }

function TMyKeyHolder.keyCallback(status: IStatus; callback: ICryptKeyCallback): Integer;


  debugLog('TMyKeyHolder.keyCallback: entered'); // this line is printed to debug file

  if Assigned(callback) then begin

     Result := callback.callback(0, nil, 1, @FKey); // should be calling FCryptKey.callback()

     debugLog('TMyKeyHolder.keyCallback: result of callback.callback: ' + IntToStr(Result)); // this line is printing a 0 when it should print a 1



Any insight on this matter would be greatly appreciated - I have been trying to figure this out for weeks with no success.

- Nick