Skip to content

Instantly share code, notes, and snippets.

@djberg96
Created May 19, 2012 22:40
Show Gist options
  • Save djberg96/2732650 to your computer and use it in GitHub Desktop.
Save djberg96/2732650 to your computer and use it in GitHub Desktop.
CharArray vs String in FFI
require 'ffi'
class MyStruct < FFI::Struct
layout(:path, [:char, 2]) # wchar
end
s = "hello".encode("UTF-16LE")
m = MyStruct.new
m[:path].to_ptr.put_bytes(0, s, s.bytesize)
p m[:path].to_s # => "" (empty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment