Search code examples
javajava-native-interface

Implement JNI application to use dll methods without implementation


I have the intention of create a Java application to use methods from a dll.

For what I have been reading, in a few words, the process to use JNI consists of: declaring the native methods in Java, generate a .h file, and then code a c or cpp file with the implementation to create a dll.

But my problem is that I have a dll, it is a big library with many methods. I know the interfaces of these methods. But I do not want to implement them. I want to use the dll to avoid using these methods. I understand that using it as a dll may improve performance. But in my case I want to use it just because I want to use the code done by other party.

Am I missing anything? Is it possible to use JNI, or any other Java interface, to use a dll methods, but skipping the coding part?

Thank you very much.


Solution

  • If you don't have a problem to use a lib for that i would recommend to use JNA. It has a more flexible API for dll access. At least i preffered to use it.

    you can find examples here: https://github.com/twall/jna/tree/master/www Therefore you only need to have the dll loaded and some interfaces you just call from java and you get what you need.

    maybe this blog helps you, too: http://jnaexamples.blogspot.de/2012/03/java-native-access-is-easy-way-to.html