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 180297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:33:40+00:00 2026-05-11T14:33:40+00:00

I’m having some beginner problems setting an FFI struct in Ruby. What I want

  • 0

I’m having some beginner problems setting an FFI struct in Ruby. What I want to do is pass a pointer to a C string by setting a string property in an FFI::Struct object:

class SpSessionConfig < FFI::Struct   layout :api_version,          :int,            :cache_location,       :string,            :settings_location,    :string,            :application_key,      :pointer,            :application_key_size, :int,            :user_agent,           :string,            :sp_session_callbacks, :pointer,            :user_data,            :pointer    end end   sessionConf = SpotifyLibrary::SpSessionConfig.new()  puts sessionConf # => '#<SpotifyLibrary::SpSessionConfig:0x9acc00c>'  sessionConf[:api_version] = 1 puts 'Api Version: #{sessionConf[:api_version]}'  myTempDir = 'tmp' sessionConf[:cache_location] = myTempDir # !Error! 

But when I run the code I get this error:

jukebox.rb:44:in `[]=': Cannot set :string fields (ArgumentError) from jukebox.rb:44:in `<main>' 

So I don’t really know where to go from here.

Also, if you know of any good documtation or tutorials on this subject please leave a response! So far I have found the wiki documentation on Project Kenai very useful but the more the merrier!

Thanks!

I have tried to declare the string data members as [:char, 5] but that gives another error:

jukebox.rb:44:in `put': put not supported for FFI::StructLayoutBuilder::ArrayField_Signed8_3 (ArgumentError)     from jukebox.rb:44:in `[]='     from jukebox.rb:44:in `<main> 

There is a good suggestion to try out the memory pointer type and I will try that after work today.

  • 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. 2026-05-11T14:33:41+00:00Added an answer on May 11, 2026 at 2:33 pm

    FFI automatically rejects setting strings. Try changing it from :string to :char_array, as mentioned on this page:

    :char_array – used ONLY in a struct layout where struct has a C-style string (char []) as a member

    If that doesn’t work, you’re going to have to use a :pointer and convert it back into a string. It’s not well documented, but MemoryPointer has a bunch of available functions, such as write_string, that should help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 99k
  • Answers 99k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I've not encountered anything particularly lint-like for CF, but there… May 11, 2026 at 7:48 pm
  • Editorial Team
    Editorial Team added an answer I subclassed the DataObject class and used DoDragDrop to allow… May 11, 2026 at 7:48 pm
  • Editorial Team
    Editorial Team added an answer My colleague ended up using a combination of Axis2 /… May 11, 2026 at 7:48 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.