[fpc-pascal] c structs and pascal interfaces

Jonas Maebe jonas.maebe at elis.ugent.be
Tue Jan 28 18:26:44 CET 2014


On 28 Jan 2014, at 18:13, Andrew Haines wrote:

> I want to use c "interfaces" exposed as structs in fpc as interfaces. In particular I'm converting the OpenSLES header file to fpc.
> 
> Here's an example of an exported struct:
> struct SLPlayItf_ {
> 	SLresult (*SetPlayState) (
> 		SLPlayItf self,
> 		SLuint32 state
> 	);
> 	SLresult (*GetPlayState) (
> 		SLPlayItf self,
> 		SLuint32 *pState
> 	);
> 	SLresult (*GetDuration) (
> 		SLPlayItf self,
> 		SLmillisecond *pMsec
> 	);
> 	.....
> };

If they are exposed as structs, you should translate them into records in FPC (with {$packrecords c}. The "member functions" are fields that are procedure variables, and you have to explicitly include the "self" parameters.

Corba (or other) interfaces are something different and you cannot use them to import arbitrary C structs, regardless of whether they contain function pointers.


Jonas


More information about the fpc-pascal mailing list