Re: How do I pass a call back Class and its method to an external library *.so file writting in C++

Sven Barth via fpc-pascal <[email protected]>
Newsgroups gmane.comp.compilers.free-pascal.general
Message-ID <CAFMUeB_=T6tO8BjVBnZWpiyR1LnWTe7WLAo-mvJXEmBKhvnkGw@mail.gmail.com>
Dennis via fpc-pascal <[email protected]> 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

_______________________________________________
fpc-pascal maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.