Convert C Header to delphi

int  WINAPI  BiMICRSetReadBackFunction(
    int  nHandle,
    int  (CALLBACK  *pMicrCB)(void),
    LPBYTE  pReadBuffSize,
    LPBYTE  readCharBuff,
    LPBYTE  pStatus,
    LPBYTE  pDetail);

    typedef int (CALLBACK* MICRCallback)(void);
    typedef int (CALLBACK* StatusCallback)(DWORD);

    int WINAPI BiSetInkStatusBackFunction(int nHandle,
        int (CALLBACK *pStatusCB)(DWORD dwStatus)
);

I need to convert this function to Delphi.

I tried to use headconv4.2 but the resulting static unit is not completed, and errors occur when compiling.

Thanks in advance for your kind help :D

Upvotes: 4

Views: 951

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 598309

A literal translation would be:

type
  MICRCallback = function: Integer; stdcall; 
  StatusCallback = function(dwStatus: DWORD): Integer; stdcall; 

function BiMICRSetReadBackFunction( 
  nHandle: Integer; 
  pMicrCB: MICRCallback; 
  pReadBuffSize: PByte; 
  readCharBuff: PByte; 
  pStatus: PByte; 
  pDetail: PByte
): Integer; stdcall; 

function BiSetInkStatusBackFunction(
  nHandle: Integer;
  pStatusCB: StatusCallback
): Integer; stdcall; 

If you are importing functions from a DLL, then you need to add the DLL filename to the function declarations:

function BiMICRSetReadBackFunction( 
  nHandle: Integer; 
  pMicrCB: MICRCallback; 
  pReadBuffSize: PByte; 
  readCharBuff: PByte; 
  pStatus: PByte; 
  pDetail: PByte
): Integer; stdcall; external 'filename.dll';

function BiSetInkStatusBackFunction(
  nHandle: Integer;
  pStatusCB: StatusCallback
): Integer; stdcall; external 'filename.dll';

Upvotes: 3

Toribio
Toribio

Reputation: 4078

Supposing WINAPI and CALLBACK always being __stdcall, DWORD being unsigned int and LPBYTE as unsigned char *, you could try this dirty conversion I made:

unit UHeader;

interface

// Data types

type
  PByte = ^Byte;
  PPByte = ^PByte;

// Prototypes

type
  TMICRCallback = function: Integer; stdcall;
  TStatusCallback = function(dwParam: Cardinal): Integer; stdcall;

// Functions

type
  TBiMICRSetReadBackFunction =
    function(nHande: Integer;
             pMicrCB: TMICRCallback;
             pReadBuffSize: PByte;
             readCharBuff: PByte;
             pStatus: PByte;
             pDetail: PByte
    ): Integer; stdcall;

var
  BiMICRSetReadBackFunction: TBiMICRSetReadBackFunction;

type
  TBiSetInkStatusBackFunction =
    function(nHandle: Integer;
             pStatusCB: TStatusCallback
    ): Integer; stdcall;

var
  BiSetInkStatusBackFunction: TBiSetInkStatusBackFunction;

implementation

end.

I'm not entirely sure, though, if this is correct... but this could be a path for you to try to convert it yourself.

Upvotes: 3

Related Questions