FFI - struct passed by value

Q&A's, tips, howto's

FFI - struct passed by value

Postby Astrobe » Tue Jan 28, 2014 10:46 pm

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?
Astrobe
 
Posts: 39
Joined: Mon Jan 11, 2010 9:41 pm

Re: FFI - struct passed by value

Postby Lutz » Tue Jan 28, 2014 11:34 pm

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
Lutz
 
Posts: 5276
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Re: FFI - struct passed by value

Postby Astrobe » Wed Jan 29, 2014 11:28 am

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)
Astrobe
 
Posts: 39
Joined: Mon Jan 11, 2010 9:41 pm


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 2 guests