SWIG Passing Ruby structure arrays into C DLL

Discussion in 'Ruby' started by John Reynolds, Mar 20, 2008.

  1. I have a structure defined in my DLL
    Code:
    typedef struct _ABC{
    int a, b,c;
    }ABC;
    
    And a function

    Code:
    void func(int count, ABC * abc)
    {
    ABC *tempabc = abc;
    for (int i=0; i< count; i++)
    {
    cout << tempabc->a << tempabc->b << tempabc->c << endl;
    tempabc++;
    }
    }
    
    The above is compiled into a DLL, say ABC_DLL that can be used in Ruby
    using the SWIG interface.
    In my ruby script, I create an array of ABC.

    Code:
    arr=Array.new
    temp1 = ABC_DLL::ABC.new
    temp1.a=1111
    temp1.b=1111
    temp1.c=1111
    arr = arr << temp1
    temp2 = ABC_DLL::ABC.new
    temp2.a=2222
    temp2.b=2222
    temp2.c=2222
    arr = arr << temp2
    temp3 = ABC_DLL::ABC.new
    temp3.a=3333
    temp3.b=3333
    temp3.c=3333
    arr = arr << temp3
    
    Question is how do I pass this array (arr) into the DLL function??

    I tried

    ABC_DLL::func(3,arr[0])

    but my func in DLL prints out the following
    1111 1111 1111
    2434 342332 3423442 (some junk numbers)
    2222 2222 2222

    I would have expected something like

    1111 1111 1111
    2222 2222 2222
    3333 3333 3333
    --
    Posted via http://www.ruby-forum.com/.
    John Reynolds, Mar 20, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Pye
    Replies:
    2
    Views:
    295
    Tommy Nordgren
    Mar 15, 2007
  2. Replies:
    3
    Views:
    962
    sturlamolden
    Mar 31, 2008
  3. H. Simpson
    Replies:
    4
    Views:
    235
    H. Simpson
    Aug 3, 2004
  4. Albert Vernon Smith

    swig & passing array of arrays

    Albert Vernon Smith, Mar 5, 2006, in forum: Ruby
    Replies:
    1
    Views:
    108
    rickhg12hs
    Mar 5, 2006
  5. Replies:
    2
    Views:
    249
    Rui Maciel
    Dec 12, 2012
Loading...

Share This Page