

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
7 messages in net.java.dev.jna.usersRe: [jna-users] Can I use By-referenc...| From | Sent On | Attachments |
|---|---|---|
| Albert Kurucz | Jun 22, 2009 7:07 am | |
| Timothy Wall | Jun 22, 2009 7:18 am | |
| Albert Kurucz | Jun 22, 2009 7:45 am | |
| Timothy Wall | Jun 22, 2009 8:16 am | |
| Albert Kurucz | Jun 22, 2009 9:27 am | |
| Timothy Wall | Jun 22, 2009 9:42 am | |
| Albert Kurucz | Jun 22, 2009 10:09 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] Can I use By-reference argument with the experimental direct calling convention? | Actions... |
|---|---|---|
| From: | Albert Kurucz (albe...@gmail.com) | |
| Date: | Jun 22, 2009 7:45:29 am | |
| List: | net.java.dev.jna.users | |
Timothy,
Here is the original (non-direct) mapping code, which works OK:
package com.jtstand.jna; /** * * @author albert_kurucz */ import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.Platform; import com.sun.jna.ptr.IntByReference;
/** Simple example of JNA interface mapping and usage. */ public class HelloVisa {
// This is the standard, stable way of mapping, which supports extensive // customization and mapping of Java to native types. public interface NiVisaLibrary extends Library {
NiVisaLibrary INSTANCE = (NiVisaLibrary) Native.loadLibrary((Platform.isWindows() ? "visa32" : "????"), NiVisaLibrary.class);
//void printf(String format, Object... args); int viOpenDefaultRM(IntByReference sesn);
int viOpen(int sesn, String rsrcName, int accessMode, int openTimeout, IntByReference vi); }
public static void main(String[] args) { int status; System.out.println("viOpenDefaultRM..."); IntByReference sesn = new IntByReference(); status = NiVisaLibrary.INSTANCE.viOpenDefaultRM(sesn); System.out.println("Status:" + status);
System.out.println("viOpen..."); IntByReference vi = new IntByReference(); status = NiVisaLibrary.INSTANCE.viOpen(sesn.getValue(), "COM1", 0, 0, vi); System.out.println("Status:" + status);
} }
and here the modified code, trying to make use the direct mapping:
package com.jtstand.jna;
import com.sun.jna.*;
/** Simple example of JNA direct mapping. * Fewer automatic type conversions are supported with this method */ public class HelloDirectVisa {
static { Native.register(Platform.isWindows() ? "visa32" : "????"); }
public static native int viOpenDefaultRM(int[] sesn);
public static native int viOpen(int sesn, String rsrcName, int accessMode, int openTimeout, int[] vi);
public static void main(String[] args) { int status; System.out.println("viOpenDefaultRM..."); int[] sesn = new int[1]; status = viOpenDefaultRM(sesn); System.out.println("Status:" + status);
System.out.println("viOpen..."); int[] vi = new int[1]; status = viOpen(sesn[0], "COM1", 0, 0, vi); System.out.println("Status:" + status); } }
..using your recommended "primitive array of length one".
What am I doing wrong, because I am getting and Exception:
java.lang.ExceptionInInitializerError Caused by: java.lang.NullPointerException at java.lang.reflect.Array.getLength(Native Method) at com.sun.jna.Structure$FFIType.<init>(Structure.java:1432) at com.sun.jna.Structure$FFIType.get(Structure.java:1483) at com.sun.jna.Structure$FFIType.get(Structure.java:1450) at com.sun.jna.Structure$FFIType.getSignature(Structure.java:1492) at com.sun.jna.Native.register(Native.java:940) at com.sun.jna.Native.register(Native.java:888) at com.jtstand.jna.HelloDirectVisa.<clinit>(HelloDirectVisa.java:11)
On Mon, Jun 22, 2009 at 9:19 AM, Timothy Wall <twal...@dev.java.net>wrote:
On Jun 22, 2009, at 10:08 AM, Albert Kurucz wrote:
Can I use By-reference argument with the experimental direct calling
convention? If this is possible, examples please.
Complete documentation of mappings for both the direct and the conventional methods would be very useful. If there are differences, mapping types would really look nice in a table.
You can use a primitive array of length one, which has the same result.
Type mappings for interface and direct mapping are the same; direct mapping does not yet implement NativeMapped or TypeMapper conversions.
You'll get runtime errors if you attempt to use an unsupported argument type.







