Results 1 to 4 of 4
  1. #1
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default Problem with JNA+DLL

    hello every one. I want to use a DLL in mi project.To reach this aim i had started to use Java Native Access..

    This is a desctiption of one of the most functions in my DLL:

    long TRANS2QUIK_CONNECT (LPCSTR lpcstrConnectionParamsString, long* pnExtendedErrorCode, LPSTR lpstrErrorMessage, DWORD dwErrorMessageSize)

    Where
    lpcstrConnectionParamsString-string
    pnExtendedErrorCode-pointer on a variable LONG
    lpstrErrorMessage-pointer on a string
    dwErrorMessageSize-long..

    I tried to use this code for connect , but it isdo not work:
    Java Code:
     public interface TransToQuik  extends Library{
    
       public long TRANS2QUIK_CONNECT (String lpcstrConnectionParamsString, long pnExtendedErrorCode, String lpstrErrorMessage, long dwErrorMessageSize);
    
    
    }
    
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        String Error;
        long len;
        long FunctionResult=0;
        long pnExtendedErrorCode=0;
        String lpstrErrorMessage="";
        long dwErrorMessageSize=0;
        TransToQuik lib = (TransToQuik) Native.loadLibrary ("D:\\java project\\Robot\\TRANS2QUIK.dll",TransToQuik.class);
        FunctionResult=lib.TRANS2QUIK_CONNECT("D:\\QUIK5.15\\info.exe",pnExtendedErrorCode,lpstrErrorMessage,dwErrorMessageSize);
    
        }
    And this error occured
    Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Error looking up function 'TRANS2QUIK_CONNECT': Не найдена указанная процедура.

    at com.sun.jna.Function.<init>(Function.java:179)
    at com.sun.jna.NativeLibrary.getFunction(NativeLibrar y.java:345)
    at com.sun.jna.NativeLibrary.getFunction(NativeLibrar y.java:325)
    at com.sun.jna.Library$Handler.invoke(Library.java:20 3)
    at $Proxy0.TRANS2QUIK_CONNECT(Unknown Source)
    at robot.Robot.jButton1ActionPerformed(Robot.java:106 )
    at robot.Robot.access$000(Robot.java:8)
    at robot.Robot$1.actionPerformed(Robot.java:32)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2015)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2338)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:253)
    at java.awt.Component.processMouseEvent(Component.jav a:6279)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3311)
    at java.awt.Component.processEvent(Component.java:604 4)
    at java.awt.Container.processEvent(Container.java:208 4)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4639)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2142)
    at java.awt.Component.dispatchEvent(Component.java:44 65)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4664)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4327)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4257)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2128)
    at java.awt.Window.dispatchEventImpl(Window.java:2612 )
    at java.awt.Component.dispatchEvent(Component.java:44 65)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 618)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:286)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:191)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:186)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:178)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:139)
    Thank to all for help!
    From Russia with Love! ;)

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,352
    Blog Entries
    7
    Rep Power
    20

    Default

    crossposted.

    kind regards,

    Jos

  3. #3
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default

    Firts problem that the instruction for this DLL was created for C ++ or C SHARP. And those languages use different name of function... The real name of function is _TRANS2QUIK_CONNECT@16...

    And ishould to write this
    Java Code:
     public int _TRANS2QUIK_CONNECT@16(String lpcstrConnectionParamsString, int pnExtendedErrorCode, String lpstrErrorMessage, int dwErrorMessageSize);
    
    }
    
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        String Error;
        int len;
        int FunctionResult=0;
        int pnExtendedErrorCode=0;
        String lpstrErrorMessage="";
        int dwErrorMessageSize=0;
        TransToQuik lib = (TransToQuik) Native.loadLibrary ("D:\\java project\\Robot\\TRANS2QUIK.dll",TransToQuik.class);
       // FunctionResult=lib._TRANS2QUIK_CONNECT@16("D:\\QUIK5.15\\",pnExtendedErrorCode,lpstrErrorMessage,dwErrorMessageSize);
    
       // jTextArea1.setText(long(FunctionResult));
    
        }
    But another problem appear :
    run:
    Exception in thread "AWT-EventQueue-0" java.lang.ClassFormatError: Duplicate field name&signature in class file robot/Robot$TransToQuik
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :764)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:144)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:382)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:75)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 294)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 288)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:287)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 99)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:334)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 32)
    at robot.Robot.jButton1ActionPerformed(Robot.java:100 )
    at robot.Robot.access$000(Robot.java:8)
    at robot.Robot$1.actionPerformed(Robot.java:36)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2015)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2338)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:253)
    at java.awt.Component.processMouseEvent(Component.jav a:6279)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3311)
    at java.awt.Component.processEvent(Component.java:604 4)
    at java.awt.Container.processEvent(Container.java:208 4)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4639)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2142)
    at java.awt.Component.dispatchEvent(Component.java:44 65)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4664)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4327)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4257)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2128)
    at java.awt.Window.dispatchEventImpl(Window.java:2612 )
    at java.awt.Component.dispatchEvent(Component.java:44 65)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 618)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:286)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:191)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:186)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:178)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:139)
    BUILD SUCCESSFUL (total time: 5 seconds)

  4. #4
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

Similar Threads

  1. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 06:12 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
  •