• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling a generic DLL

 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to call a generic dll from JAVA. The dll is provided by thirdparty. I am able to load it using "System.load("dllName.dll");" but i am now confused how can i call the methods. Since it is not made by me using JNI so there is not method with "native" keyword.

Is there any way to use its method?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15354
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't just call any function in a DLL using JNI.

What you can do is write an intermediate DLL yourself. Write a DLL (in C or C++) with functions that you can call from your Java code using JNI, and in your DLL call the functions in the third-party DLL.
 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jesper Young:
You can't just call any function in a DLL using JNI.

What you can do is write an intermediate DLL yourself. Write a DLL (in C or C++) with functions that you can call from your Java code using JNI, and in your DLL call the functions in the third-party DLL.


For JNI, we must have a wrapper DLL as you said and That's what i don't wish to do. Writing the wrapper will take a lot of time. since it is third party dll.

Is there any other api, that can help me to call a dll?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Muhammad Ali Amin:

Is there any other api, that can help me to call a dll?


There are commercial products that do this, I think. It's not something you can just do, out of the box.

JNI questions go in our "Other Java APIs" forum, so I'll move this there.
 
Timothy Wall
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Muhammad Ali Amin:
Hi,

I want to call a generic dll from JAVA. The dll is provided by thirdparty. I am able to load it using "System.load("dllName.dll");" but i am now confused how can i call the methods. Since it is not made by me using JNI so there is not method with "native" keyword.

Is there any way to use its method?


There are a few Java libraries that will let you do this:
JNA (http://jna.dev.java.net)
JNative (http://jnative.sf.net)
NLINK (http://nlink.dev.java.net)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic