[racket] FFI question again - how to get a string back from C

From: keydana at gmx.de (keydana at gmx.de)
Date: Sat Jun 11 02:54:32 EDT 2011

Hi again,

sorry for again asking such a basic FFI question, but I have a problem getting an output string from the C side...

E.g. in one case, in my first attempt 

(def-ocilib datetotext OCI_DateToText : (date_ptr : _pointer) (fmt : _string) (size : _int) (strval : (_ptr o _string)) -> (result : _bool) -> (values strval result))

I simply tried using (strval : (_ptr o _string)) for the return string (the argument size indicates the desired size for the output string).

After the experience with the null-terminated strings from my recent post, I also tried an input-output-arg, passing a null-terminated string in to C:

(def-ocilib datetotext OCI_DateToText : (date_ptr : _pointer) (fmt : _string) (size : _int) (strval : (_ptr io _string) = (gen-output-string 100))-> (result : _bool) -> (values strval result))

where gen-output-string pads an empty string to a specified length.

But in both cases, I get the same error:

ptr-ref: expects type <cpointer> as 1st argument, given: #<bad-value>; other arguments were: #<ctype>

Honestly, I have no idea what the problem might be (or how to debug/investigate it), and would very much appreciate any hints...  :-)

Many thanks!


Posted on the users mailing list.