| Author |
Calling .dll files methods in Java Code
|
shikhar sinha
Greenhorn
Joined: Aug 26, 2006
Posts: 1
|
|
Hi , I have a 3rd Party dll file containing Encryption methods. I need to call those methods in my java code. According to JNI , i have to compile the Java Code into a .h file and then include and call its methods in a C++ code. then compile this code into a dll. Since the dll which i have cannot be modified , so compilation into a dll is not possible. Can you please suggest me a way to overcome this problem ?
|
Cheers,<br /> <br />Shikhar Sinha<br /> <br />$$ Lyf is short. Live every moment of it $$
|
 |
Mohd Fuzail
Ranch Hand
Joined: Feb 20, 2002
Posts: 107
|
|
|
Check Java SE Desktop Accessibilityibility
|
Being defeated is often a temporary condition. Giving up is what makes it permanent.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
According to JNI , i have to compile the Java Code into a .h file and then include and call its methods in a C++ code. then compile this code into a dll. Since the dll which i have cannot be modified , so compilation into a dll is not possible.
Basically, you have to create a wrapper layer. Create a Java class with native methods that you want. Convert that to a .h include file. Create a C/C++ file that implements that include file, but that implementation merely routes the calls to the actually library. And then convert your new C/C++ code to a DLL. You also need to change the Java side to load the DLLs. The DLL that you are creating is not the original DLL that can't be modified. It's a brand new DLL with code that calls the original DLL. Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
Originally posted by Henry Wong: You also need to change the Java side to load the DLLs.
I think it is best that the Java code is only responsible for loading the JNI wrapper DLL (the new DLL you will create). It should not be directly responsible for loading the DLL containing the real cryptography implementation. To load the wrapper DLL, you use the Java System.loadLibrary() call. You could use System.load() to load the cryptography DLL, but I suggest not. When the wrapper DLL loads, it should then load the cryptography DLL. This can be done either explicitly (via LoadLibrary() on Windows, for example) or implicitly, via the dependencies built into the wrapper DLL.
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
This doesn't seem relevant at all. What was the idea?
|
 |
jiju ka
Ranch Hand
Joined: Oct 12, 2004
Posts: 302
|
|
I don't see the issue here. I am not familiar with dll. Can't you run a dll from command prompt or dos? If so can't you use Runtime.getRuntime().exec(command:String) method
|
 |
Andrew Monkhouse
author and jackaroo
Marshal Commander
Joined: Mar 28, 2003
Posts: 10826
|
|
Originally posted by jiju ka: Can't you run a dll from command prompt or dos?
No, DLL files are not directly executable. Hopefully the purists will forgive this bad analogy, but you could think of a the functions in a DLL as being similar to a method in a Java class. They can be very useful, but only when called by something that is executable. So, just as you cannot call System.out.println() from the command line, you cannot call a function within a DLL from the command line. Regards, Andrew
|
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
|
 |
 |
|
|
subject: Calling .dll files methods in Java Code
|
|
|