Subject:
Re: [ruby-ffi] 'encoding' type?
From:
Matijs van Zuijlen
Date:
1/8/11 4:15 AM
To:
ruby-ffi@googlegroups.com

Hi Jon,

On 01/07/2011 08:18 AM, dubl wrote:
hello,
i'm trying to attach CFStringCreateWithCString..

below is the reference documentation, which allows you to pass null as
the first argument, a cstring as the second, and an 'encoding' as the
third..

my question is, how do i attach this?  i'm trying
   attach_function :CFStringCreateWithCString,
[:void,:char,:int], :void
..using ':int', its erroring out saying 'invalid parameter type' for
the 0 I pass it...

question is: what symbol do i give it as the third argument, and then
what do i pass it?

You don't give documentation for CFStringEncoding, but if it's an enum, :int should be fine. (You can also tell FFI about the enum, and then use a symbol in the Ruby call).

The first and second argument however don't seem right. Try using :pointer and :string for those, respectively.

I admit I'm new to the concept. this is my first attempt at FFI... i'm
trying to rewrite an old dl/importable version which used the int,
passing it a 0, and it worked fine.

thanks for the opportunity to ask the question.

Jon

----------------
CFStringRef CFStringCreateWithCString (
    CFAllocatorRef alloc,
    const char *cStr,
    CFStringEncoding encoding
);
Parameters
alloc
The allocator to use to allocate memory for the new string. Pass NULL
or kCFAllocatorDefault to use the current default allocator.
cStr
The NULL-terminated C string to be used to create the CFString object.
The string must use an 8-bit encoding.
encoding
The encoding of the characters in the C string. The encoding must
specify an 8-bit encoding.
---------------------

Regards,
-- 
Matijs