Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use DLL in java code

 
Rishi Tyagi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/
 
Rishi Tyagi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks James,
Will try in this way. Lets hope if it helps us.
Regs,
Rishi Tyagi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic