Created
May 19, 2012 22:40
-
-
Save djberg96/2732650 to your computer and use it in GitHub Desktop.
CharArray vs String in FFI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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