I try to use C++ DLL function in my Delphi application. I’ve the problem in using call back function like that:
Exported functions definitions in C++:
typedef void (__CDECL__* RegisterCallBacksFunction)(AudioChunkCallBackFunction, CaptureEventCallBackFunction, LogMngr*);
Callback definitions:
typedef void (__CDECL__*AudioChunkCallBackFunction)(AudioChunkRef, CStdString& capturePort);
typedef void (__CDECL__*CaptureEventCallBackFunction)(CaptureEventRef, CStdString& capturePort);
AudioChunkRef and CaptureEventRef :
typedef boost::shared_ptr<AudioChunk> AudioChunkRef;
typedef boost::shared_ptr<CaptureEvent> CaptureEventRef;
And AudioChunk and CaptureEvent are C++ class:
class __declspec( dllexport ) AudioChunk // or CaptureEvent (both are similar)
{
public:
//some functions and variables
private:
//some functions and variables
};
C++ library exports:
extern "C"
{
__declspec( dllexport ) void __CDECL__ RegisterCallBacks(AudioChunkCallBackFunction, CaptureEventCallBackFunction, LogMngr*);
}
How can use RegisterCallBacks function in my Delphi app. ?
AFAIK you can not import C++ classes directly to map Delphi classes. That is, even if you get a pointer to a
AudioChunkinstance, you won’t be able to access it directly from Delphi. So use of your callbacks won’t be possible directly.So you’ll have to define by hand a “flat” C interface to be imported in Delphi, which will implement the callback in C++, then expose the interface as C functions, with parameters as C
structinstead of C++ boost classes.