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
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to