• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling .dll files methods in Java Code  RSS feed

 
shikhar sinha
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Mohd Fuzail
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check Java SE Desktop Accessibilityibility
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mohd Fuzail:
Check Java SE Desktop Accessibility


This doesn't seem relevant at all. What was the idea?
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12156
256
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!