Reputation: 335
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.
Upvotes: 0
Views: 150
Reputation: 36630
You can
use the JNA approach. The advantage of JNA is that no native code is necessary - the methods from the DLL you want to wrap are dynamically invoked.
implement a wrapper DLL which implements the JNI methods and then calls the real methods from your DLL. This would be the right approach if you can, for any reason, not use the JNA library (e.g. due to licensing restrictions)
Upvotes: 1
Reputation: 510
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
Upvotes: 2