[Haskell-beginners] Re: ffi woes
Jose A. Ortega Ruiz
jao at gnu.org
Sat Feb 20 04:10:26 EST 2010
Hi Dean,
Dean Herington <heringtonlacey at mindspring.com> writes:
[...]
> Though I'm not an FFI expert, I'll take a stab in case it might help you.
>
> It seems to me that
>
>> s <- (#peek struct wireless_info, essid)
>> peekCString s
>
> would read a pointer from the essid field, which is clearly not what
> you want. I think you'd want to use #ptr. Maybe something like the
> following (untested!):
>
> l <- (#peek struct wireless_config, essid_len) wc
> p <- (#ptr struct wireless_info, essid) wc
> -- wireless_config.essid is a char[MAX_LEN]
> peekCStringLen (p, fromIntegral (l :: CInt))
>
Right, using #ptr works (with the minor modification that it doesn't
return its value inside IO, so one must use let p =..., instead of p <-
...).
Thanks a lot for your help.
Cheers,
jao
More information about the Beginners
mailing list