[fpc-pascal] how to use procedure of object in C
Michael Schnell
mschnell at lumino.de
Tue Mar 10 09:59:42 CET 2015
On 03/09/2015 04:20 PM, Xiangrong Fang wrote:
>
> can I implement SetHandler in a library written in C, then call h in C?
>
For inter-language calls you obviously need to to define the calling
style on both sites. e.g. "STDCALL" or "PASCAL", to make both use
compatible calling conventions.
I don't know if/how such keywords exist for "procedure of object" style
of functions (and hence for the types of the variables pointers to them
are stored in).
If not you should use a "flat" calling scheme: on both sites use
standard (non-object) functions with e.g. "STDCALL" (adding/extracting
the Self pointer explicitly on the way, if appropriate). Regarding
variables for holding (pointers to) such functions they need to be a
record of a (flat) function pointer plus a Self pointer.
This said, you can't (easily) pass objects to a C library, anyway, as
the memory management is not synchronized by default. Like with Pascal
Strings, a e.g. Free will lead into chaos.
-Michael
More information about the fpc-pascal
mailing list