Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes java native keyword and dll usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java native keyword and dll usage" Watch "java native keyword and dll usage" New topic

java native keyword and dll usage

Lorenz Baylon
Ranch Hand

Joined: Jan 04, 2006
Posts: 99
Hi there!
I am using a dll(written in C or C++, im not so sure) for my application, I need to use the dll's methods from my Java program. I've learned that a way (or maybe the only way.. any comments?) to do this is to use java's 'native' keyword. My problem is on how to get the dll's method names and how exactly should i deal with them. Is there some workaround in java to do such task of knowing a dll's method names? Or maybe i should ask for some pointers first regarding the usage of 'native'?

Thank you in advance


I just cant look, its killing me.
Jean-Francois Briere
Ranch Hand

Joined: Mar 03, 2004
Posts: 101
You need to create a java native wrapper DLL that will serve as the bridge between the java application and the C/C++ DLL.
The java methods tagged as "native" will call the JNI wrapper DLL functions,
which in turn will call the C/C++ DLL functions.

Lorenz Baylon
Ranch Hand

Joined: Jan 04, 2006
Posts: 99
Thanks for the response, do my java methods need to be named exactly the same as the C/C++ DLL functions?

Is there a way that I know the C/C++ DLL function names?

Again, many thanks
Jean-Francois Briere
Ranch Hand

Joined: Mar 03, 2004
Posts: 101
You should read a JNI Tutorial first to get acquainted with the beast :-)

To answer your questions, the JNI functions must follow a specific naming convention related to the java part, NOT the third party C/C++ DLL part.
For instance, suppose you have a java class with one native method:
package a.b.c;
class MyBridge
native void myMethod();
Then the JNI function name MUST be:

If you don't have any documentation on your third party C/C++ DLL, it will be hard to know how to use it.
Knowing the exported function names of the DLL will not help much.
There are many tools out there to read all the exported symbols of a DLL.
But you might find one in the C/C++ build tools you are currently using.

Hope this help.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Note that you can avoid having to use the big long Java-mandated function names, if you explicitly connect your C functions to the Java methods, via the JNI function RegisterNatives(). However, it is unlikely that this will allow you to call the existing C functions directly from Java. You'll probably still need "bridge"/"trampoline" methods, to adjust the argument types etc.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Lorenz Baylon
Ranch Hand

Joined: Jan 04, 2006
Posts: 99
hi thanks for the responses, i guess now i have some hints in getting along with 'the beast' (haha i like that)...

those responses really help
subject: java native keyword and dll usage
Similar Threads
Calling a generic DLL
TrayIcon after explorer crash
jsp - jar - dll
protecting .class file from decompilation
native keyword ?