• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

JNA handling char** java mapping

Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've a C function which takes char** as a argument. C program treats this char** argument as two dimentional array. So this is what it does -

void getStringArray(char** myString){

myString[0] = (char*) malloc (sizeof(char)*20)
strcpy(myString[0], somestring1)
myString[1] = (char*) malloc (sizeof(char)*20)
strcpy(myString[0], somestring2)
myString[2] = (char*) malloc (sizeof(char)*20)
strcpy(myString[0], somestring3)



public void getData(){
PointerByReference pRef = new PointerByReference();

Pointer p = pRef.getValue();
byte buffer[] = p.getByteArray(0,10) //these offsets are indicative, I pass actual value by calculating them in C
sysout(new String(buffer));

byte buffer[] = p.getByteArray(11,20)
sysout(new String(buffer));

buffer[] = p.getByteArray(21,30)
sysout(new String(buffer));

After invoking program I get correct value for first String only other two contain some random values.
am I missing something? or Is there any other way to achieve this?

I don't always make ads but when I do they're tiny
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic