[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
Mon Oct 21 07:51:57 CEST 2024
Dennis via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am Mo., 21.
Okt. 2024, 05:09:
>
>
>> 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. 🤷♀️
>
> In C++, I was expected to pass the class instance to the external library.
> So, In Pascal, do I pass the interface variable to the external library?
>
Correct. As I said however: it *might* work, no guarantee.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20241021/6e025a6f/attachment.htm>
More information about the fpc-pascal
mailing list