3

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);        
3
  • 4
    Only use regular functions as callbacks (not "of Object") (search for "implicit self parameter", e.g. stackoverflow.com/questions/7706637/…). Commented Oct 9, 2012 at 0:50
  • It would help if you showed the matching portions of your C++ interface Commented Oct 9, 2012 at 7:25
  • 1
    Here is the official documentation about the implicit parameter of a class method. Commented Oct 9, 2012 at 16:30

1 Answer 1

4

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

TMICRCallback   = function: Integer;  stdcall;
TStatusCallback = function(dwParam: Cardinal): Integer; stdcall;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.