This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

How to:using routines of a dll  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a third party dll xyz.dll(without documentation), I can load it by calling:

System.load(dllpath+"\\xyz.dll").

However, how do i come to know wat are the routines that are present in the dll, so that I can use them ?

--thanks in advance
 
Sheriff
Posts: 21548
100
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not how Java works. You can't just call functions in a DLL.

The DLLs you load through System.load and System.loadLibrary are only used for implementation of native methods. So to be able to use the functionality in that DLL file you will need two extra layers: a Java class with native methods, and a JNI bridge between the Java class and the functions in the DLL.
 
author
Posts: 3281
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there and welcome to Javaranch!

What language is the DLL written in? I suspect you're going to have to use JNI to interrogate that native object....
 
subhajit paul
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i have to write the java class with declaration of native methods, i need to know what are the methods present in the dll.

for example, if abc.dll is having a method

void abc1(void)

it can be done by:

public native void abc1();

public Constructor(){System.loadLibrary("abc");}


however, i want to know if i get abc.dll without any documentation, is there a way that can be used to know that there is a method abc1 which takes no arguments and returns nothing?
 
Martijn Verburg
author
Posts: 3281
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know to be honest, you'd be best off using some sort of MS tool to inspect it, anyone?
 
author
Posts: 23811
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

however, i want to know if i get abc.dll without any documentation, is there a way that can be used to know that there is a method abc1 which takes no arguments and returns nothing?



JNI doesn't work like that -- you can't use it to call any DLL. To be quite honest, if you don't know what's in a DLL, is it really a good idea to call it?

In this example "native void abc1()" will execute a call to a function with a name based on both the package and name, and actually pass it parameters (at minimum, the java context). To get the actual C/C++ signature, you have use the javah tool to generate an include file (.h file) from the class file.

And with the include file, you are supposed to write the implementations, and generate a DLL. Now... of course, from the C/C++ code (your implementation), you can call the functions in this other DLL, but again, if you don't know what it does, is it really a good idea to use it?

Henry
[ December 17, 2008: Message edited by: Henry Wong ]
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

JNI doesn't work like that -- you can't use it to call any DLL.

No, but you can use JNI wrappers to do all the legwork for you, so you don't have to write your own JNI DLLs/bridges. For example, JNIWrapper. The resulting program will be faster writing your own bridge, but if speed isn't essential...
 
Rob Spoor
Sheriff
Posts: 21548
100
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Henry Wong:
at minimum, the java context


Actually, at minimum the Java context and either the object (for non-static methods) or class object (for static methods). The rest is the actual method parameters.

But I agree with the general consensus - if you don't know what's in the DLL, don't call it. What if one of the functions deletes your entire hard drive?
 
Shiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!