Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > SWIG Passing Ruby structure arrays into C DLL

Reply
Thread Tools

SWIG Passing Ruby structure arrays into C DLL

 
 
John Reynolds
Guest
Posts: n/a
 
      03-20-2008
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/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Iterate through a list of structure arrays of structure to get outthe field stuie_norris@yahoo.com.au C Programming 2 12-12-2012 09:18 PM
Creating a python c-module: passing double arrays to c functions.segmentation fault. swig kmgrds@gmail.com Python 3 03-31-2008 07:39 PM
Ruby <-SWIG-> C arrays Aureliano Buendia Ruby 3 11-15-2006 02:50 PM
swig & passing array of arrays Albert Vernon Smith Ruby 1 03-05-2006 09:08 PM
msvcrt.dll, msvcirt.dll, msvcrt20.dll and msvcrt40.dll, explanation please! Snoopy NZ Computing 16 08-25-2003 12:34 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57