Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi: working with Pointer functions

I'm new in delphi, my program developed in delphi working with a dll developed in C++, I need working with pointer functions that throw exceptions of Access Violation address and after many test I don't know how resolve It.

this is defintion of the pointer function in delphi that translate since header c++

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

  type
   TBiMICRSetReadBackFunction =
      function(const nHande:        Integer;
               pMicrCB:             TMICRCallback;
               var pReadBuffSize:    Byte;
               var readCharBuff:     Byte;
               var pStatus:          Byte;
               var pDetail:          Byte
      ): Integer; stdcall;
var
   BiMICRSetReadBackFunction: TBiMICRSetReadBackFunction;

type
   TBiMICRSetReadBackFunction =
      function(const nHande:        Integer;
               pMicrCB:             TMICRCallback;
               var pReadBuffSize:    Byte;
               var readCharBuff:     Byte;
               var pStatus:          Byte;
               var pDetail:          Byte
      ): Integer; stdcall;
var
   BiMICRSetReadBackFunction: TBiMICRSetReadBackFunction;

this is a code that call the pointer functions

type
  function CBMICRRead : Integer; stdcall;
  function CBMICRStatus(dwStatus: LongWord) : Integer;  stdcall;


  Respuesta      : TMICRCallback;
  Estado         : TStatusCallback;

  BiSetStatusBackFunction(m_hApi, Estado);

 BiMICRSetReadBackFunction (m_hApi,
                                    Respuesta,
                                    m_MICRReadBuffSize,
                                    m_MICRReadBuff[0],
                                    m_MICRReadStatus,
                                    m_MICRReadStDetail); 

This is the C++ side of the interface:

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


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

int WINAPI BiMICRSetReadBackFunction(int    nHandle, 
                                     int    (CALLBACK *pMicrCB)(void),
                                     LPBYTE pReadBuffSize,   
                                     LPBYTE readCharBuff,    
                                     LPBYTE pStatus,         
                                     LPBYTE pDetail);        
like image 502
Jericob Avatar asked May 21 '26 13:05

Jericob


1 Answers

You must avoid Object as passing parameters from/to DLL function call result.

TMICRCallback   = function: Integer;  stdcall;
TStatusCallback = function(dwParam: Cardinal): Integer; stdcall;
like image 147
sybond Avatar answered May 23 '26 05:05

sybond



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!