c structs and pascal interfaces

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

c structs and pascal interfaces

Andrew Haines
Hi,

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
        );
        .....
};

I'm not very familiar with interfaces but here's what I know. There are
two types com and corba.

I think I need corba so I don't have the ref and unref procedures.

I would translate this to:
{$INTERFACES corba}
ISLPlatItf = interface
   function SetPlayState(state: SLuint32): SLresult; cdecl;
   function GetPlayState(state: PSLuint32): SLresult; cdecl;
   function GetDuration(msec: PSLmillisecond): SLresult; cdecl;
   ......
end;

So now two questions:

Is corba the interface type I need?

Am I wrong to exclude the self parameter from the interface translation?

Thanks,

Andrew Haines


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: c structs and pascal interfaces

Jonas Maebe-2

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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: c structs and pascal interfaces

Andrew Haines
On 01/28/2014 12:26 PM, Jonas Maebe wrote:
>
> 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.

>
> 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.
>

Okay thanks,

Andrew

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal