• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to:using routines of a dll

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23951
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

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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • 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:
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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic