Subject:
Re: [ruby-ffi] Re: Using Windows Unicode functions
From:
Wayne Meissner
Date:
1/28/10 7:57 PM
To:
ruby-ffi@googlegroups.com

On 29 January 2010 05:58, Jon <jon.forums@gmail.com> wrote:
>
> A new type binary blob type similar to :buffer_in but skips over the null-byte checking and encodes to UTF-16LE behind the scenes?  Something like :unicode_string or :win_wide_string?  Could the new type also be made applicable to both Windows UTF-16 and *nix UTF-8/locale environments?

If anyone wants to experiment with this, I strongly encourage them to
spin up a new ffi-related gem, along the lines of NiceFFI and play
with the win32/unicode stuff there.  This way it will work on both
CRuby and JRuby, and you won't be waiting months for it to be merged
in to the various FFI implementations.

FFI's attach_function is all ruby code, its just setting up and wiring
together primitives provided by the C ext or JRuby code.  You can
replace it with your own version that when it detects say a :wstring
parameter/return type, wraps the function call in a small ruby stub
that does the conversion to/from native code.

you could use it like something like this:

module Foo
  extend Win32FFI::Library

  @encoding = "UTF-16LE"
  attach_function :BarW, [ :wstring, :int ], :wstring
end

Foo.BarW "Test", 2

APIs you'll want to learn about are
http://ffi.github.com/api/FFI/Function.html
http://ffi.github.com/api/FFI/DynamicLibrary.html and possibly
http://ffi.github.com/api/FFI/Type.html