Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7545527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:57:12+00:00 2026-05-30T08:57:12+00:00

I am working with Ruby-FFI on Ruby 1.8 to wrap a library that uses

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:57:14+00:00Added an answer on May 30, 2026 at 8:57 am

    OK, this is the (inelegant) workaround I have so far. It involves adding a method to FFI::Pointer. It should be safe to call in the context of my library, because all strings are supposed to be UTF-16LE encoded, but otherwise, it may not be good, because it might never encounter a double null and would just carry on reading past the the bounds of the string in memory.

    module FFI
      class Pointer
    
        # Read string until we encounter a double-null terminator
        def read_string_dn
          cont_nullcount = 0
          offset = 0
          # Determine the offset in memory of the expected double-null
          until cont_nullcount == 2
            byte = get_bytes(offset,1)
            cont_nullcount += 1 if byte == "\000"
            cont_nullcount = 0 if byte != "\000"
            offset += 1
          end
          # Return string with calculated length (offset) including terminator
          get_bytes(0,offset+1)
        end
    
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're working on a Ruby on Rails app that needs to take advantage of
I am accessing a C function in Ruby through FFI. The function is called
I'm working with Ruby on Rails 2.3.8 and I've got a collection that is
I'm working on some Ruby code that needs to create primary keys on existing
Has anyone gotten Logstash working with ruby on rails? My client is telling to
From my time working with Ruby On rails, there is a couple different packaged/projects
What is the approach to get SQLite-ruby working in IronRuby?
I'm working with a Ruby project for school, and have sadly not been able
For a project I am working on in ruby I am overriding the method_missing
I came from Java, and now I am working more with Ruby. One language

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.