简体   繁体   中英

Call a function written in JNI from java without loading a DLL

I have a code written in C with JNI that loads a java class with CallStaticVoidMethod.
I want the java class to be able to call a specific function from the C code.
I've seen examples over the web, but all of them were loading a DLL that has nothing to do with the java class (using System.loadLibrary).
Is it possible that the java class will call a function from the original C code that loaded it?

Yes you can, see https://stackoverflow.com/a/21734539/192373 . The key is RegisterNatives() JNI function.

If you don't want to do native methods you could also pass function pointers to Java and use JNA to call the function.

(I'm using this to call functions in COM object vtables on Windows, because I didn't want to write a wrapper DLL for every object. The difference is that I don't pass the function pointers in but compute them from the object address.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM