This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes How do call the function from .dll file in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How do call the function from .dll file in java" Watch "How do call the function from .dll file in java" New topic
Author

How do call the function from .dll file in java

kerthi Joe
Greenhorn

Joined: Dec 29, 2011
Posts: 2
Hi Frnds,

I have added the .dll file which is required for my code in JACOB jar library native path. I dont know in which program the .dll file was written but i know the function name written in them. I have to call that function from java, Could you please help me how to call the function in .dll file from java program.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3575
    
  14

Hi Kerthika, welcome to CodeRanch!

Do a Google search for JNA, or Java Native Access. There should be plenty of tutorials or articles explaining how to set it up and how to call native procedures from dynamic libraries.
kerthi Joe
Greenhorn

Joined: Dec 29, 2011
Posts: 2

Hi stephan,

Thank you for your suggestion. I have used the native library jar in RAD and have given the .dll file path in the native library location in that jar.My program is ,

public class testFromDllFile {

private native int GetIMSData(String A,String B,String C,String D,int x,String E,int y,String F,int z,int a,String G,String H);

public static void main(String[] args) {
int x = new testFromDllFile().GetIMSData("A","B","C","D",0,"E",0,"",0,0,"","F");
System.out.println("x"+x);
}

static {
System.loadLibrary("TRNSACTN");
}
}


But when i run this program am getting "The java class could not be loaded. java.lang.UnsatisfiedLinkError: D:\DLL_file\TRNSACTN.DLL: Can't find dependent libraries" .
Am i missing anything here.?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7503
    
  18

kerthi Joe wrote:But when i run this program am getting "The java class could not be loaded. java.lang.UnsatisfiedLinkError: D:\DLL_file\TRNSACTN.DLL: Can't find dependent libraries" .
Am i missing anything here.?

Well I've never done it myself, but it appears to be telling you that the library contains links to other dependant libraries that it can't find - presumably because you haven't told it where to look for them.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Charles Hargrave
Greenhorn

Joined: Apr 29, 2010
Posts: 11
Winston Gutkowski wrote:
kerthi Joe wrote:But when i run this program am getting "The java class could not be loaded. java.lang.UnsatisfiedLinkError: D:\DLL_file\TRNSACTN.DLL: Can't find dependent libraries" .
Am i missing anything here.?

Well I've never done it myself, but it appears to be telling you that the library contains links to other dependant libraries that it can't find - presumably because you haven't told it where to look for them.

Winston


I agree with Winston.

Your TRNSACTN.DLL file might also need other DLL's too. Looking at the command line and such, it looks like you're on Windows. I'm going to suggest an approach to this. If you already have a Microsoft development tool of some kind on that PC (ex: Microsoft Visual C++), look for the 'depends.exe' program on your PC; it's a dependency walker tool. If you have it, use it to find out what DLL dependencies your program/DLL file has.

I'm going to guess that the original program was made through an IDE of some kind (MS Visual C++, Visual Studio, C#, Intel FORTRAN, etc) and was compiled in a manner where it expected the other redistributable files (DLL's) would already be on whatever PC you wanted to install the program to.

CNH
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37936
    
  22
And welcome to the Ranch [Only 1¾ years on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do call the function from .dll file in java
 
Similar Threads
Callback help in JNI
call activex dll through javascript
Problem in merging PPT files using java
Calling DLL function
Calling VB Dll In JAVA