0

This is one function in the C++ header file I want to call from Delphi:

 * @param hConnection Handle to the connection to FM.
 * @param pOperation See description of ABS_OPERATION.
 * @param dwTemplateCount Count of templates in the pTemplateArray.
 * @param pTemplateArray Pointer to the array of pointers to templates.
 * @param pResult Pointer to memory location, where result of the comparing 
 */
ABS_STATUS BSAPI ABSVerify(
    IN ABS_CONNECTION hConnection,
    IN ABS_OPERATION* pOperation,
    IN ABS_DWORD dwTemplateCount,
    IN ABS_BIR** pTemplateArray,
    OUT ABS_LONG* pResult,
    IN ABS_DWORD dwFlags
);

-- Def

/** 
 * The header of the BIR. This type is equivalent to BioAPI's structure 
 * BioAPI_BIR_HEADER. 
 */
typedef struct abs_bir_header {
  ABS_DWORD Length;     ///< Length of Header + Opaque Data
  ABS_BYTE HeaderVersion;   ///< HeaderVersion = 1
  ABS_BYTE Type;    ///< Type = 4 (BioAPI_BIR_DATA_TYPE_PROCESSED)
  ABS_WORD FormatOwner;     ///< FormatOwner = 0x12 (STMicroelectronics)
  ABS_WORD FormatID;    ///< FormatID = 0
  ABS_CHAR Quality;     ///< Quality = -2 (BioAPI_QUALITY is not supported)
  ABS_BYTE Purpose;     ///< Purpose (BioAPI_PURPOSE_xxxx, ABS_PURPOSE_xxxx).
  ABS_DWORD FactorsMask;    ///< FactorsMask = 0x08 (BioAPI_FACTOR_FINGERPRINT)
} ABS_BIR_HEADER;

/** 
 * A container for biometric data. 
 */
typedef struct abs_bir {
  ABS_BIR_HEADER Header;    ///< BIR header
  ABS_BYTE Data[ABS_VARLEN];    ///< The data composing the fingerprint template.
} ABS_BIR;

  struct abs_operation;
typedef struct abs_operation ABS_OPERATION;  /* forward declaration */

/** 
 * A type of the callback function that an application can supply to 
 * the BSAPI to enable itself to display GUI state information to user. 
 * 
 * @param pOperation Pointer to ABS_OPERATION structure used when calling the interactive operation.
 * @param dwMsgID ID of message. See description of ABS_MSG_xxxx constants.
 * @param pMsgData Pointer to data with additional information related with 
 * the message. 
 */
typedef void (BSAPI  *ABS_CALLBACK) ( const ABS_OPERATION*, ABS_DWORD, void*);
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Ezi
  • 2,212
  • 8
  • 33
  • 60
  • You need to show the definition of `ABS_OPERATION` and `ABS_BIR` – David Heffernan Apr 19 '12 at 21:34
  • 1
    What is your question? Make sure it's of general interest. [Stack Overflow is not a code-translation service.](http://meta.stackexchange.com/a/129362/33732) – Rob Kennedy Apr 19 '12 at 21:47
  • I have a lot to convert, I didn't post it here to have someone convert it for me. (although I would love if someone would want to do it for me :)) this code is just one sample that shows pointers, that I had trouble with. – Ezi Apr 20 '12 at 02:40

2 Answers2

2

It's probably something like this:

function ABSVerify(
    hConnection: Integer;
    Operation: PABS_OPERATION;
    dwTemplateCount: DWORD;
    pTemplateArray: PPABS_BIR;
    var pResult: Integer;
    dwFlags: DWORD
): Integer; stdcall; external 'bsapi.dll';

The things that are a little hazy are ABS_OPERATION. Because that is an IN parameter and yet it is passed as a pointer to ABS_OPERATION, I imagine it is a struct. You will need to declare a matching Delphi record and a pointer type for it. Maybe like this:

type
  ABS_OPERATION = record
    field1: Integer;
    field2: Integer;
    //etc.
  end;
  PABS_OPERATION = ^ABS_OPERATION;

The other parameter that requires care is pTemplateArray:

pTemplateArray Pointer to the array of pointers to templates.

This is an array of pointers. Arrays in C are passed as pointers to the first element. So that explains the type, ABS_BIR**, pointer to first element, which is itself a pointer to an ABS_BIR.

type
  ABS_BIR = ... //whatever it is
  PABS_BIR = ^ABS_BIR;
  PPABS_BIR = ^PABS_BIR;

You might call the function something like this:

var
  TemplateArray: array of PABS_BIR;
...
  SetLength(TemplateArray, dwTemplateCount);
  // populate TemplateArray
  returnval := ABSVerify(..., dwTemplateCount, @TemplateArray[0], ...);

I see now that you have added the struct definitions in an edit. I'll leave my made up structs here because you ought to be able to convert these structs yourself.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
1

You will have to check what BSAPI resolves to. I am assuming stdcall:

type
  PABS_OPERATION = ^ABS_OPERATION;
  PABS_BIR = ^ABS_BIR;
  PPABS_BIR = ^PABS_BIR;
  PABS_LONG = ^ABS_LONG;

function ABSVerify( 
    hConnection: ABS_CONNECTION;
    pOperation: PABS_OPERATION;
    dwTemplateCount: ABS_DWORD;
    pTemplateArray: PPABS_BIR;
    pResult: PABS_LONG;
    dwFlags: ABS_DWORD
): ABS_STATUS; stdcall; 

Alternatively:

type
  PABS_BIR = ^ABS_BIR;

function ABSVerify( 
    hConnection: ABS_CONNECTION;
    var pOperation: ABS_OPERATION;
    dwTemplateCount: ABS_DWORD;
    var pTemplateArray: PABS_BIR;
    out pResult: ABS_LONG;
    dwFlags: ABS_DWORD
): ABS_STATUS; stdcall; 
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770