Need some advices regarding JNI

J

JPractitioner

Hi all!

I already have a .dll file. I want to call a few functions from the
..dll file. I have a pdf documentation that shows me the function specs
of the dll file (i.e. function name, function call, function return,
etc). Apparently those are C/C++ code.

I figured out that this can be done with JNI. However it seems that,
with JNI, I will be creating another .dll

(I refer to this tutorial and done with it:
http://www.iut-info.univ-lille1.fr/docs/tutorial/native1.1/index.html)

So my question is, do i have to create another .dll which will be used
to call the other .dll that need to use?

I wonder if, i can call the dll functions directly from java code. i.e.
after
System.load(theDll.dll);
//call the functions here

If this cannot be done, that means i will have to call the functions
from a c code that will implement java header files right?

Your point of views are very much appreciated.

Thank you.
 
T

Tim Ward

JPractitioner said:
So my question is, do i have to create another .dll which will be used
to call the other .dll that need to use?

Yes. JNI has a particular view of the world, and insists on only making DLL
calls that conform to this view of the world. Unlike when programming in VB,
you can't make a call to an arbitrary DLL function from Java.

If you already have a DLL which has not been written to be called by JNI,
and you don't have the source code to that DLL so can't modify it, then yes,
you have to write your own DLL to sit as a glue layer between the Java code
and the existing DLL.
 
J

JPractitioner

Thanks a lot Tim Ward, for your reply.
Yup, I cant modify the source code of the DLL.
This means i have to learn C. I am so "happy".

Thanks again Tim.
 
J

JPractitioner

Hi Jean-Francois Briere,
The JNative that u suggested really helps.
Thanks a lot! :D
 
J

JPractitioner

Jean Francois, obviously I have one problem using JNative. Do u know
how i can send parameters with byte[] as its data type?
It seems like JNative only support String (Type.String), int
(Type.INT), long (Type.LONG), struct (Type.STRUCT) and void
(Type.VOID).

I am still finding the solutions, and I already asked in JNative news.
Please help me if u know the way before i do.

Many Thanks.
 
J

JPractitioner

I ve got the way already by doing something like this..
byte[] b = new buffer[256];
by using object.setParameter(1, Type.INT,buffer);

However now, i got the following errors..

#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x1000147f, pid=4360,
tid=4468
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode,
sharing)
# Problematic frame:
# C [BridgeMini.dll+0x147f]
#
# An error report file with more information is saved as
hs_err_pid4360.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#

Hmmm.....
hope some one has any idea of what i can learn from this error
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top