Need some advices regarding JNI

Discussion in 'Java' started by JPractitioner, Jul 24, 2006.

  1. 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.
     
    JPractitioner, Jul 24, 2006
    #1
    1. Advertising

  2. JPractitioner

    Tim Ward Guest

    "JPractitioner" <> wrote in message
    news:...
    >
    > 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
     
    Tim Ward, Jul 24, 2006
    #2
    1. Advertising

  3. 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.

    Tim Ward wrote:
    > 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,..
     
    JPractitioner, Jul 24, 2006
    #3
  4. 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
     
    Jean-Francois Briere, Jul 24, 2006
    #4
  5. JPractitioner, Jul 25, 2006
    #5
  6. 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.

    Jean-Francois Briere wrote:
    > 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, Jul 25, 2006
    #6
  7. 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
     
    JPractitioner, Jul 25, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gildas Garcia

    need advices : intranet archecture design

    Gildas Garcia, Jul 4, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    380
    Gildas Garcia
    Jul 4, 2003
  2. NWx
    Replies:
    1
    Views:
    556
    Saravana [MVP]
    Feb 13, 2004
  3. Joh
    Replies:
    2
    Views:
    328
    Lonnie Princehouse
    Jul 15, 2004
  4. jmfauth
    Replies:
    2
    Views:
    238
    jmfauth
    Nov 23, 2010
  5. NWx
    Replies:
    1
    Views:
    178
    Saravana [MVP]
    Feb 13, 2004
Loading...

Share This Page