Luc
Luc

Reputation: 31

passing a int** to a C routine using JNA

I'm having in my java program a int[][] that stores some data I want to compute (alter) in a C routine. But I can't figure out how to pass the "pointer to pointer to int" to the C code which declares a f(int sz, int** structure). Any idea?

Thanks, Luc.d

Upvotes: 1

Views: 1851

Answers (2)

Abhijith
Abhijith

Reputation: 2632

Since this is question is tagged JNA, Similar Example in JNA docs

// Original C declaration
void allocate_buffer(char **bufp, int* lenp);

// Equivalent JNA mapping
 void allocate_buffer(PointerByReference bufp, IntByReference lenp);

// Usage
PointerByReference pref = new PointerByReference();
IntByReference iref = new IntByReference();
lib.allocate_buffer(pref, iref);
Pointer p = pref.getValue();
byte[] buffer = p.getByteArray(0, iref.getValue());

Isn't this what you are looking for ? you use PointerByReference when there is a Pointer to a Pointer.

Upvotes: 2

Constantinius
Constantinius

Reputation: 35049

I think this example might come in handy :)

Upvotes: 1

Related Questions