JNA 如何在从 dll 收到的指针中调用 java 的方法?

JNA how call a method from java in an Pointer received from dll?

我在 dll 中有一个方法,returns 一个指向对象的指针

C代码

basic_hash* getAlgorithmInstance( int algorithm )

对象有以下方法:

void reset ();
void hash (const byte* data, uint64 size, vector_byte& hash).

如何调用这个对象的方法?

我有一个实现returns一个指针

java代码

public interface LIB extends Library {
        LIB INSTANCE = (LIB ) Native.loadLibrary(
                (Platform.isWindows() ? "LIB " : "linuxLIB"), LIB.class);
        Pointer getAlgorithmInstance(int i);
    }

    public static void main(String[] args) {
        try {
            LIB lib = LIB.INSTANCE;
            Pointer pointer = lib.getAlgorithmInstance(0);
            //pointer.reset(); //TODO how call?
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
    }

您需要为每个函数指针声明回调。这是 "reset".

的示例
public class BasicHash extends Structure {
    public interface Reset extends Callback {
        public void invoke();
    }
    public Reset reset;
    public BasicHash() { }
    public BasicHash(Pointer p) { super(p); read(); }
}

BasicHash hash = mylib.getAlgorithmInstance(0);
hash.reset.invoke();