2 messages in net.java.dev.jna.usersRe: Re:
FromSent OnAttachments
Timothy WallFeb 26, 2008 5:45 am 
Timothy WallFeb 27, 2008 3:56 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: Re:Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Feb 27, 2008 3:56:27 am
List:net.java.dev.jna.users

The java code is not much help without the reference C definitions.

My guess is that you're using Java long in place of native long, which is incorrect. Native long on windows is always Java "int", or NativeLong (32 bits). Java long is 64 bits.

You should also use Native.toString() to convert your byte arrays to String, since that method pays attention to NUL terminators while new String(byte[]) does not.

On Feb 27, 2008, at 12:18 AM, Ruslan Kenzhebekov wrote:

Thanks for your answer. I did it ,but I can't understand anything. My Dll file described like this: public interface TradeDll extends StdCallLibrary {

public static class Instrument extends Structure { public static class ByValue extends Instrument implements Structure.ByValue { } public long id; public byte[] marketName =new byte[15];; public byte[] sectorName=new byte[15]; public byte[] groupName=new byte[15]; public byte[] shortName=new byte[15]; public byte[] name=new byte[100]; public byte status; public byte sesNum; public double open; public double ask; public double bid; public double last; public long lastVolume; public double average; public double max; public double min; public long volume; public long volTotal; public long orderCnt; public long dealCnt; public long ustKurs; public double kaseKurs; public long curId; public byte[] nin=new byte[15]; public byte isCupon; public long nominal; public byte method; public byte[] base=new byte[250]; public double cuponTax; public long cuponCnt; public long pastPayDate; public long nextPayDate; public long xDate; public double accInt; public double startKurs; public double koeff; public long days; public long closeDate; public long openDate; public long lot; public double korrCnt; public double korrPrc; } long getInstrumentCount(); Instrument.ByValue getInstrumentByNum(long n);

In my programm I have written like this:

import com.sun.jna.*; import arm.Trade.TradeDll; import com.sun.jna.*; import com.sun.jna.ptr.*; import com.sun.jna.Pointer.*; import java.lang.reflect.Field;

public class LocalTime { public static void main (String [] args) {

TradeDll lib=(TradeDll)Native.loadLibrary("c:/trade", TradeDll.class);

try { long n=lib.getInstrumentCount(); System.out.println(n); for (long i=0;i<1; i++) {

TradeDll.Instrument result=lib.getInstrumentByNum(i); Structure s=result; Field f; System.out.println(s.toString()); String s1=new String(result.marketName); String s2=new String(result.sectorName); String s3=new String(result.groupName); String s4=new String(result.shortName); String s5=new String(result.name); String s6=new String(result.nin); System.out.println(result.id+" "+s1+" "+s2+" "+s3+" "+s4+" "+s5+" "+s6); } } catch(Exception e) { System.out.print("Exception: "+e.toString()); } } }

After running my program the result is: init: deps-jar: compile-single: run-single: 677 TradeDll$Instrument$ByValue(allocated@0x3f24e0 (632 bytes)) { byte id[4]@0=[B@758fc9 byte marketName[15]@4=[B@32fb4f byte sectorName[15]@13=[B@1113708 byte groupName[15]@22=[B@133f1d7 byte shortName[15]@31=[B@14a9972 byte name[100]@40=[B@a01335 byte status@a4=1 byte sesNum@a5=0 double open@a8=0.0 double ask@b0=0.0 double bid@b8=0.0 double last@c0=0.0 Pointer lastVolume@c8=null double average@d0=0.0 double max@d8=0.0 double min@e0=0.0 Pointer volume@e8=null Pointer volTotal@ec=null Pointer orderCnt@f0=null Pointer dealCnt@f4=null double ustKurs@f8=-558.65283203125 double kaseKurs@100=3.66088800274E-313 Pointer curId@108=native@0x43315a4b byte nin[15]@10c=[B@bf32c byte isCupon@11b=0 Pointer nominal@11c=null byte method@120=0 byte base[250]@121=[B@89fbe3 double cuponTax@220=4.9E-324 Pointer cuponCnt@228=null Pointer pastPayDate@22c=null Pointer nextPayDate@230=null Pointer xDate@234=null double accInt@238=0.0 double startKurs@240=0.0 double koeff@248=0.0 long days@250=6442454047 Pointer closeDate@258=null Pointer openDate@25c=native@0x3ff00000 Pointer lot@260=null double korrCnt@268=1.0E-323 double korrPrc@270=0.0 } memory dump [20ab0000] [45717569] [74696573] [00000000] [0000004c] [69737469] [6e670000] [00000000] [00004c69] [7374696e] [67204100] [00000000] [004b4b47] [42200000] [00000000] [00000000] [cff0eef1] [f2fbe520] [e0eaf6e8] [e820c0ce] [2022cae0] [e7eaeeec] [ece5f0f6] [e1e0edea] [22000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [0100f477] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [397581c0] [06848940] [11000000] [4b5a3143] [30303430] [30303136] [00000000] [01000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [01000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [00000000] [1f0c0080] [01000000] [00000000] [0000f03f] [00000000] [0000f03f] [02000000] [00000000] [00000000] [00000000] [B@758fc9 Equities

as I said I can't get values from Long and double type variable . I think you can help me to solve this problem :-); Thank