Forums Register Login

java native keyword and dll usage

+Pie Number of slices to send: Send
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

lhorenz
+Pie Number of slices to send: Send
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.

Regards
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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:
Java_a_b_c_MyBridge_myMethod

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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
The moustache of a titan! The ad of a flea:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2293 times.
Similar Threads
native keyword ?
jsp - jar - dll
TrayIcon after explorer crash
protecting .class file from decompilation
Calling a generic DLL
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:27:46.