• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Calling .dll files methods in Java Code

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check Java SE Desktop Accessibilityibility
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Let's go to the waterfront with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic