欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Jna Using Pointers and Arrays as int*

程序员文章站 2022-03-11 18:30:58
...

Primitive array arguments (including structs) are represented by their corresponding Java types. For example:

// Original C declarations
void fill_buffer(int *buf, int len);
void fill_buffer(int buf[], int len); // same thing with array syntax

// Equivalent JNA mapping
void fill_buffer(int[] buf, int len);

NOTE: if the parameter is to be used by the native function outside thescope of the function call, you must use Memory or anNIO Buffer. The memory provided by a Java primitive array will only be validfor use by the native code for the duration of the function call.

Arrays of C strings (the char* argv[] to the C main,for example), may be represented by String[] in Java code. JNAwill pass an equivalent array with a NULL final element.

转载于:https://www.cnblogs.com/jrvin/archive/2010/09/01/1815325.html