I am working with Ruby-FFI on Ruby 1.8 to wrap a library that uses UTF-16LE strings. The library has a C function that returns such a String.
Whether I wrap the function with
attach_function [:getVersion, [], :pointer]
and call read_string
on the returned pointer, or whether I wrap it with
attach_function [:getVersion, [], :string]
What I get back is only the first character, because the second character is null (\000
) and as a result, FFI stops reading the string there, obviously because it assumes it is dealing with a normal, single-null terminated string.
Is there something I need to do, perhaps in initialization of my Ruby program or FFI or otherwise, to make it know that I expect strings to be UTF-16LE encoded? How else can I get around this?