Results 1 to 7 of 7
  1. #1
    santhosh_el is offline Member
    Join Date
    Feb 2009
    Posts
    50
    Rep Power
    0

    Default how to call dll file in java program

    dear sir,

    i having a gui which has a dll file .i need to use various functions in that dll .first i need know call dll in my java program.

    thanks
    santhosh

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    You need to write a JNI (Java Native Interface) wrapper for your dll, with methods in Java declared as native.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    This is not a question that can be answered in one or two statements followed by a couple of lines of code. No to solve this, you're going to have to do some hard work and studying. I recommend that you Google the Java JNI library and it's various tutorials. Then start reading. See you back in a few weeks. Good luck.

  4. #4
    santhosh_el is offline Member
    Join Date
    Feb 2009
    Posts
    50
    Rep Power
    0

    Default how to call dll in java program

    dear sir,

    this my code to dll in my java program.

    public class NewClass {
    @NativeImport(library="C:/jinvoke/testdll/Debug/testdll.dll",
    convention=CallingConvention.THISCALL)

    public static native int fntestdll();

    public static void main(String[] args) {
    // JInvoke.initialize();
    try
    {
    System.out.println("testing");
    int i=fntestdll();
    System.out.println("i" + ":" +i);
    }catch(Exception e)
    {
    System.out.println(e);
    }
    // System.out.println("The C code return " + i);
    }


    }

    the code has compiled sucessfully ,but when run the code ,its get error message

    run:
    testing
    Exception in thread "main" java.lang.UnsatisfiedLinkError: NewClass.fntestdll()I
    at NewClass.fntestdll(Native Method)
    at NewClass.main(NewClass.java:28)
    Java Result: 1

    any body can give solution here.

    thanks
    santhosh

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    santhosh, you must be much more intelligent than I am, for it took me weeks to a few months to grok JNI even partially.

    So, have you Googled for JNI links and tutorials? You understand of course that you're not going to be able to link a dll by simply referring to it in your java program that you have to create a C/C++ wrapper program first that encapsulates the code from the dll.

    I feel you are looking for quick answers where they don't exist. Again, my recommendation is to go do some serious studying.

  6. #6
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Unless that dll has been compiled against a JNI header, it won't have the required interface to be called from java, hence a link error.

    I may be incorrect, but I'm pretty sure that's the case here.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm guessing that the dll he's trying to link is the one mentioned about in the first post here, that he has yet to create a JNI header file or a C/C++ bridging program that uses the JNI header.

Similar Threads

  1. Program To Call Random Methods
    By nyamtoko in forum Advanced Java
    Replies: 5
    Last Post: 12-01-2008, 11:49 AM
  2. To open an image file such as Jpeg file using JAva Program
    By itmani2020 in forum Advanced Java
    Replies: 10
    Last Post: 07-11-2008, 09:57 AM
  3. Is it possible to make a Phone call program using java?
    By fireball2008 in forum New To Java
    Replies: 2
    Last Post: 05-08-2008, 06:20 PM
  4. How to call C/C++ Program from Java
    By sanjeevtarar in forum Advanced Java
    Replies: 1
    Last Post: 04-17-2008, 08:55 AM
  5. I need to call and run another program
    By coco in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 05:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •