Код: Выделить всё
typedef void (*example_ptr)(const char*);
void exampleMethod(const char* value)
{
printf("This is the string: %s\n", value);
}
void example_triggerCallback(const example_ptr func, const char* str) {
printf("provided str: %s", str);
func(str);
}
< /code>
Чтобы сделать это, я написал такую обертку JNA в Java < /p>
public class Main {
public interface TestLibrary extends Library {
TestLibrary INSTANCE = (TestLibrary)
Native.loadLibrary("libtest",
TestLibrary.class);
interface ExampleCallback extends Callback {
void invoke(String str);
}
class ExampleCallbackImpl implements ExampleCallback {
public void invoke(String str) {
System.out.println("example: " + str);
}
}
void example_triggerCallback(ExampleCallback callback, String str);
}
public static void main(String[] args) {
TestLibrary testLibrary = TestLibrary.INSTANCE;
final TestLibrary.ExampleCallbackImpl callback = new TestLibrary.ExampleCallbackImpl();
testLibrary.example_triggerCallback(callback, "testiddy test test");
}
}
Подробнее здесь: https://stackoverflow.com/questions/522 ... l-argument