I want to use JNA to call a function written with C, how do I create a pointer to array of C-style strings, aka char**
?
If I wrote my program in C, char**
would be used like this:
param_names= (char ) malloc( 3000* sizeof( char * ) );
for( i = 0; i < 3000; i++ ) {
param_names[i] = GetName( i );
fprintf( stderr, "%s\n", param_names[i] );
}
if( light( ¶m_names[1],1, &numPoints, &data ) != SUCCESS
Here, light
is a function implemented in C and uses C calling conventions.
How can I write code that allocates these strings and array in Java and calls same light
function implemented in C?
How to allocate C-style strings in Java/JNA?
How to allocate and assign C-style arrays in Java/JNA?
What type should I use to represent pointer to such array, aka char**
in Java/JNA?
when i try to do string[] as argument (in java) i have this error :
Exception in thread "main" java.lang.Error: Invalid memory access
at com.sun.jna.Native.invokeInt(Native Method)
at com.sun.jna.Function.invoke(Function.java:383)
at com.sun.jna.Function.invoke(Function.java:315)
at com.sun.jna.Library$Handler.invoke(Library.java:212)
at $Proxy0.light(Unknown Source)
at ApicallI.getpar.main(getpar.java:429)