FFI - struct passed by value

Q&A's, tips, howto's
Locked
Astrobe
Posts: 43
Joined: Mon Jan 11, 2010 9:41 pm

FFI - struct passed by value

Post by Astrobe »

I'd like to use this nice little GUI library: http://enchantia.com/software/graphapp/

The widget set is not as full featured as other libraries but it's good enough for simple user interfaces. Plus it fits in a single 700K DLL and is portable.

The problem is that it passes and returns one of its major structures (Rect) as value: http://enchantia.com/software/graphapp/ ... l/rect.htm

Is there, by any chance, some trick to make it work with NewLisp's FFI without writing wrappers?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: FFI - struct passed by value

Post by Lutz »

Yes, it is is possible without writing any wrappers.

See the files newlisp-10.5.x/util/ffitest.c and newlisp-10.5.x/qa-specific-tests/qa-libffi and look for “clock”. There is a “struct clock” defined in ffitest.c. which then is used in qa-libffi.

There are also pointers to structs, an example for those can be found in the manual at:
http://www.newlisp.org/downloads/newlis ... tml#struct

Astrobe
Posts: 43
Joined: Mon Jan 11, 2010 9:41 pm

Re: FFI - struct passed by value

Post by Astrobe »

Thanks.

Code: Select all

(set 'GA "gappw32.dll")
(struct 'Rect "int" "int" "int" "int")
(import GA "app_new_app" "void*" "int" "void*")
(import GA "app_new_window" "void*" "void*" "Rect" "char*" "long")
(import GA "app_main_loop" "void" "void*")
(import GA "app_show_window" "void" "void*")
(import GA "app_new_label" "void*" "void*" "Rect" "char*" "int")
(import GA "app_new_button" "void*" "void*" "Rect" "char*" "void*")

(set 'GH (app_new_app 0 ""))
(set 'W (app_new_window GH (pack Rect 100 100 200 50) "Thanks Lutz" 0x3F0))
(define (sayHi) (println "Hi!"))
(set 'cb (callback 'sayHi "void*" "void*"))
(app_new_button W (pack Rect 5 5 190 40) "It works awsomely" cb)
(app_show_window W)
(app_main_loop GH)

Locked