aspose file tools*
The moose likes Java in General and the fly likes how to use DLL in java code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to use DLL in java code" Watch "how to use DLL in java code" New topic
Author

how to use DLL in java code

Rishi Tyagi
Ranch Hand

Joined: Feb 14, 2002
Posts: 100
Dear All,

I am working on a project which needs to use an dll api originaly written to be used with visual basic or other microsoft platform languages like VC++ etc.

Is there any way to use a dll api in java , I heard that using JNI we can do this, but could not get the proper information to use JNI for invoking objects and their methods into java application which are embedded inside dll api.

Is there anybody who has ever done this before and can share his experience with me here.


Regs,
Rishi Tyagi
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
JNI is the trick. Make a special DLL that is JNI callable and a Java class with just the methods that call straight through to the DLL. The DLL can call other C/C++ or whatever programs as needed.

Did you start here to learn JNI? http://java.sun.com/docs/books/tutorial/native1.1/


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Rishi Tyagi
Ranch Hand

Joined: Feb 14, 2002
Posts: 100
Thanks James,

But as you mentioned that we need to make dll JNI compatible, what we need to do for that?

Actually the api i want to use is a third party api and i dont have source of it and hence it is next to impossible to make any change in that dll.
Is there any way so that we can invoke dll without touching it.

Regs,
Rishi
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You'll have to put your own custom DLL in front:

Java -> JNI -> Custom DLL -> standard DLL call -> 3rd Party DLL

We've done this for a couple desktop products.
Rishi Tyagi
Ranch Hand

Joined: Feb 14, 2002
Posts: 100
Thanks James,
Will try in this way. Lets hope if it helps us.
Regs,
Rishi Tyagi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use DLL in java code