0

这是我想从 Delphi 调用的 C++ 头文件中的一个函数:

 * @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
);

-- 定义

/** 
 * 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*);
4

2 回答 2

2

大概是这样的:

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

有点朦胧的东西是ABS_OPERATION。因为那是一个IN参数,但它作为指向 的指针传递ABS_OPERATION,我想它是一个struct. 您需要为它声明一个匹配的 Delphi 记录和一个指针类型。也许是这样的:

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

另一个需要注意的参数是pTemplateArray

pTemplateArray 指向模板指针数组的指针。

这是一个指针数组。C 中的数组作为指向第一个元素的指针传递。这就解释了类型,ABS_BIR**指向第一个元素的指针,它本身就是一个指向的指针ABS_BIR

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

您可以像这样调用该函数:

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

我现在看到您已在编辑中添加了结构定义。我将把我编造的结构留在这里,因为您应该能够自己转换这些结构。

于 2012-04-19T21:46:34.987 回答
1

您将不得不检查BSAPI解决的问题。我假设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; 

或者:

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; 
于 2012-04-19T21:38:49.353 回答