From: Bob H. <bh...@co...> - 2012-03-19 22:40:50
|
The problem here is that I don't know the Java API, so I don't know how to tell Java what its got. Your C++ function is now returning char**, which is an array of character pointers (with each pointer pointing to the string "ABC", "5CDE", etc.). In other words, charArray() is returning an array of pointers (each to its own char array) instead of just a single array of char's. You need to let Java know that what it is handling is no longer array[char], but is now array[array[char], array[char], array[char]]. You may need to set up a typemap to handle this conversion. Hopefully, I'm not further confusing you. But somebody who knows the SWIG/Java interfaces might do better. I only know Python. On 3/19/2012 3:28 PM, colin gray wrote: > Thanks for the advice Bob, much appreciated. If I change the return type to > a char** then the C function (charArray() returns a SWIGTYPE_p_p_char, but > the char_array_getitem takes in a String to represent the Array parameter. > Any ideas? > > //C Function Wrapper: > > public static SWIGTYPE_p_p_char charArray() { > > long cPtr = TestJNI.charArray(); > > return (cPtr == 0) ? null : new SWIGTYPE_p_p_char(cPtr, false); > > } > > public static char char_array_getitem(String ary, int index) { > > return TestJNI.char_array_getitem(ary, index); > > } > > > On Mon, Mar 19, 2012 at 1:48 PM, Bob Hood <bh...@co... > <mailto:bh...@co...>> wrote: > > On 3/19/2012 2:10 PM, colin gray wrote: >> Hello, >> >> I'm trying to utilize the below C function, charArray in Java using >> SWIG, but it looks like I'm not able to get all of the C Array >> element's data. If I change the C function to use just a single digit >> or letter then its fine. Anyone see any issues with my implementation? >> >> >> inline char *charArray(){ >> static char foo[3]; >> foo[0]='ABC'; >> foo[1]='5CDE'; >> foo[2]='EEE6'; >> return foo; >> } >> > > For one thing, you're stuffing single characters into a character array > (I'm kinda surprised you're not getting compile errors with multiple > characters in single quotes). If you want character /strings/, then > change your C function to something like this: > > inline char** charArray() > { > static char** foo[] = { "ABC", "5CDE", "EEE6", 0 }; > return foo; > } > > Note that your return type is now different that what it was before. > Render me gone, ||| Bob ^(===)^ ---------------------------------oOO--(_)--OOo--------------------------------- I'm not so good with advice...can I interest you in a sarcastic comment? |