jna
  1. jna
  2. JNA-164

jna method call error when the paramters order different

    Details

    • Issuezilla Id:
      164

      Description

      windows xp x86, jdk 1.6.20

      hellojna.h
      extern "C" _declspec(dllexport) int swapvalue(int* a, int* b);
      extern "C" _declspec(dllexport) int rf_select1(unsigned char *_Size);
      extern "C" _declspec(dllexport) int rf_select2(unsigned char *_Size,long
      icdev);
      extern "C" _declspec(dllexport) int rf_select3(long icdev, unsigned char
      *_Size);

      hellojna.cpp
      #include "stdafx.h"
      #include "hellojna.h"

      int rf_select1(unsigned char *_Size) {
      _Size[0] = 'a';
      return 12;
      }

      int rf_select2(unsigned char *_Size, long icdev) {
      _Size[0] = 'a';
      return 12;
      }

      int rf_select3(long icdev, unsigned char *_Size) {
      _Size[0] = 'a';
      return 12;
      }

      HelloJna.java
      public interface HelloJna extends Library {
      HelloJna instance = (HelloJna) Native.loadLibrary("hellojna",
      HelloJna.class);
      int rf_select1(byte[] abd);
      int rf_select2(byte[] abd, long dev);
      int rf_select3(long dev, byte[] abd);
      }

      Test.java
      public class Test {
      /**

      • @param args
        */
        public static void main(String[] args) {
        HelloJna jna = HelloJna.instance;

      byte[] buf = new byte[]

      {'s', 'u', 'p', 'e', 'r', ' ', 'm', 'a', 'n', '\0'}

      ;
      int ret = jna.rf_select1(buf);
      System.out.println("buf=" + new String(buf) + ",ret=" + ret);

      buf[0] = 'I';
      ret = jna.rf_select2(buf, 77);
      System.out.println("77 buf=" + new String(buf) + ",ret=" +
      ret);

      buf[0] = 'E';
      ret = jna.rf_select3(99, buf);
      System.out.println("99 buf=" + new String(buf) + ",ret=" +
      ret);
      }

      }

      console.out:
      buf=auper man , ret=12
      77 buf=auper man ,ret=12
      details looke:
      http://dl.javaeye.com/upload/attachment/308859/6297d5c1-0df9-3299-bf1e-
      066ec1e7f285.png

      why rf_select1 and rf_select2 is right but rf_select3 is error ??
      the differences is just the paramters order??
      because in the rf_select3 the var "_Size" is null so call rf_select3 is error!

      Then 2010-09-15 00:13 add info:
      I found it's work good when HelloJna.java change rf_select3(long dev,
      byte[] abd) to rf_select3(NativeLong dev, byte[] abd)

      HelloJna.java
      public interface HelloJna extends Library {
      HelloJna instance = (HelloJna) Native.loadLibrary("hellojna",
      HelloJna.class);
      int rf_select1(byte[] abd);
      int rf_select2(byte[] abd, long dev);
      int rf_select3(NativeLong dev, byte[] abd);//<----It's work very
      good!
      }

        Activity

        Hide
        skzrorg added a comment -

        please see the detail with url:
        http://skzr-org.javaeye.com/blog/763438

        Show
        skzrorg added a comment - please see the detail with url: http://skzr-org.javaeye.com/blog/763438
        Hide
        skzrorg added a comment -

        Created an attachment (id=90)
        details param value when call rf_select3

        Show
        skzrorg added a comment - Created an attachment (id=90) details param value when call rf_select3

          People

          • Assignee:
            rogerbalakrishnan
            Reporter:
            skzrorg
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: