[plt-scheme] ffi type _bool does only return #t
Hi,
I'm currently working on the bindings of a dll using ffi. The library uses a
lot of boolean procedures. I now found that the type _bool converts
everything into #t when I call a function, thus making it useless. I read
the documentation, where it is said _bool converts every #f into 0 _int and
other values into 1, but shouldn't that apply also to the other way round?
Here is a very simple example:
The dll exports the following procedure
bool YesNo(int n)
{
if(n == 0) return false;
return true;
}
On the scheme side the code is:
(require (lib "foreign.ss" "mzlib"))
(unsafe!)
(define dll (ffi-lib "Test"))
(define yesno (get-ffi-obj "YesNo" dde-client-dll (_fun _int -> _bool)))
(yesno 0)
(yesno 12)
The result is:
Welcome to DrScheme, version 350.4-svn7jul2006.
Language: Pretty Big (includes MrEd and Advanced Student) custom.
#t
#t
>
If I substitute _bool with _byte in the get-ffi-obj call I get:
Welcome to DrScheme, version 350.4-svn7jul2006.
Language: Pretty Big (includes MrEd and Advanced Student) custom.
0
1
>
This shows the values are transferred right via ffi, but the type conversion
goes wrong.
Do I miss anything? Is there a simple way to get the following behavior:
(yesno 0)
> #f
(yesno 12)
> #t
Any help and comments appreciated.
Robert
_________________________________________
Robert Matovinovic
2 Fenella Drive, Monavale
Harare
Zimbabwe
Tel: +263 (0)4 339 879
Cell: +263 (0)91 43 66 47
email: robert.matovinovic at web.de