FFI - struct passed by value

Started by Astrobe, January 28, 2014, 02:46:54 PM

Previous topic - Next topic

Astrobe

I'd like to use this nice little GUI library: http://enchantia.com/software/graphapp/">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/doc/manual/rect.htm">http://enchantia.com/software/graphapp/ ... l/rect.htm">http://enchantia.com/software/graphapp/doc/manual/rect.htm



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

Lutz

#1
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/newlisp_manual.html#struct">http://www.newlisp.org/downloads/newlis ... tml#struct">http://www.newlisp.org/downloads/newlisp_manual.html#struct

Astrobe

#2
Thanks.



(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)