Thanks for the fast answer. :-)

On 30/05/16 11:14, Esteban Lorenzano wrote:
this is not the easiest part of FFI :)

this is the simplest  way:

str := ExternalAddress new. “This will point to NULL”
self callToMyFunction: str.
pharoString := (str pointerAt: 1) readString.

callToMyFunction: str
        self ffiCall: #( void function ( char ** str ) )


now, another way is to declare a value holder:

1) subclass FFIExternalValueHolder.

FFIExternalValueHolder subclass: #StringValueHolder.

2) implement class side method  typeDesc

StringValueHolder class>>typeDesc
        ^ String

3) implement your method replacing char** for your value holder:

callToMyFunction: str
        self ffiCall: #( void function ( StringValueHolder* str ) )

then you call like this:

str := StringValueHolder new.
self callToMyFunction: str.
pharoString := str value readString.

looks like too much steps for just economise the “pointeAt: 1” part, but is 
useful when you have lots of this calls :)
I think I will use the second solution. It is cleaner isn't it?

Julien

Reply via email to