Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

Need some advices regarding JNI

Thread view: 
JPractitioner - 24 Jul 2006 11:54 GMT
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.
Tim Ward - 24 Jul 2006 12:09 GMT
> 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.

--
Tim Ward
Brett Ward Limited - www.brettward.co.uk
JPractitioner - 24 Jul 2006 12:26 GMT
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.

> 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,..
Jean-Francois Briere - 24 Jul 2006 12:36 GMT
If you don't want to write JNI code there is a way.
You could use a third party tool that does the hard work for you.

Have a look at JNative:
http://sourceforge.net/project/showfiles.php?group_id=156421

This library allows developpers to access native libraries (DLL and
lib.so) from java. You do NOT need to compile a line of C/C++ to use
it.

Regards
JPractitioner - 25 Jul 2006 06:18 GMT
Hi Jean-Francois Briere,
The JNative that u suggested really helps.
Thanks a lot! :D

> Have a look at JNative:
> http://sourceforge.net/project/showfiles.php?group_id=156421
JPractitioner - 25 Jul 2006 08:41 GMT
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.

> If you don't want to write JNI code there is a way.
> You could use a third party tool that does the hard work for you.
[quoted text clipped - 7 lines]
>
> Regards
JPractitioner - 25 Jul 2006 09:23 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.