[fpc-pascal] How do I pass a call back Class and its method to an external library *.so file writting in C++
Sven Barth
pascaldragon at googlemail.com
Fri Oct 4 23:04:47 CEST 2024
Dennis via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am Fr., 4.
Okt. 2024, 08:40:
> Dear All,
>
> I am given an API linux library *.so file written in C++.
> It was expected to be consume by a program written in C++.
> However, I would like to write such a program in Free Pascal.
[snip]
> I am expected to create and pass an instance of such class
> ApiProxyWrapperReply in my calling program
> via a function
> void SPAPI_RegisterApiProxyWrapperReply(ApiProxyWrapperReply*
> apiProxyWrapperReply);
>
> and the external library will then call the various methods of
> ApiProxyWrapperReply as 'call-back' functions when needed.
>
Considering that the class only has abstract virtual methods and the
destructor is non-virtual you *might* be able to do this by declaring a raw
interface ({$Interfaces Corba}) and declaring all the virtual methods in
the same order (very important!) with suitable signatures and calling
convention (for i386 you should pick cppdecl otherwise the system default
should be alright), implementing that interface in some Object Pascal class
and then passing an instance of that interface to the library.
It could still go wrong due to some differences in the ABI, but it might
just as well work. 🤷♀️
> I consulted co-pilot but it failed to teach me how to do so in a Free
> Pascal program calling such an external library.
>
Shows that the current state of "AI" can't help with every obscure topic 😅
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20241004/015d12f4/attachment.htm>
More information about the fpc-pascal
mailing list