

![]() | 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: |
2 messages in net.java.dev.jna.usersRe: [jna-users] is it OK to use 16bit...| From | Sent On | Attachments |
|---|---|---|
| Avinash Kachhy | Mar 12, 2009 3:08 pm | |
| Daniel Kaufmann | Mar 13, 2009 5: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] is it OK to use 16bit DLL in XP/Vista? | Actions... |
|---|---|---|
| From: | Daniel Kaufmann (dani...@gmail.com) | |
| Date: | Mar 13, 2009 5:09:25 am | |
| List: | net.java.dev.jna.users | |
It looks like you are not mapping it correctly the structure. I think it should be public class SetupPR extends Structure { public byte port[] = new byte[5]; public short baud = 9600; public byte parity = 'N'; public byte data = 8; public byte stop = 1; } and it looks like you should copy "COM1".getBytes() to port byte array and probably make sure that the last byte is 0 . Since 0 is the default value for byte, you won't need to do anything at all for that, just don't assign the result of "COM1".getBytes() because it will have only 5 bytes, make sure you copy the bytes to the array.
It looks like it is possible to call 16 bits library from 32bit code but doesn't seem to be easy. JNA just uses LoadLibrary but to load the dll but it looks that isn't enought, look at the following link: http://support.microsoft.com/kb/123731/en-us, looks like you need to use "Universal Thunk", but I am not sure what actually involves. Regards, Daniel
On Thu, Mar 12, 2009 at 7:09 PM, Avinash Kachhy <akac...@yahoo.com> wrote:
Hello
I have to work with a DLL that controls a financial printer. The DLL was originally written for NT/Win31/Win95. There is a test program and that does not seem to work on Vista too as it shows com port not open error all the time.
When I try to use the functions from the DLL, I get unexpected return codes, e.g. 68 instead of 0.
Is it not possible to use 16 bit DLLs on XP/Vista? If it is possible, is there any thing wrong below?
Thanks in advance. avinash08820 ========================================= import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.NativeLibrary; import com.sun.jna.Platform; import com.sun.jna.win32.*;
public class TestPR2API { public interface PR2Communication extends Library{
PR2Communication pr2comm = (PR2Communication) Native.loadLibrary("wpr50nt", PR2Communication.class);
public byte PRT_CHECKHW (/*void*/); // It checks hardware. public byte PRT_RESET(/*void*/); //WORD WINAPI PRT_RESET (VOID);Performs a physical Reset of the machine. public byte PRT_EJECT(/*void*/); //WORD WINAPI PRT_EJECT (VOID);Eject the paper's front. public byte PRT_CLOSECOM (/*void*/); // Closes the communications port.
/* Functions with arguments */ public byte PRT_OPENCOM(SetupPR spr); public byte PRT_WRITE(String s, byte l); } public static void main(String[] args){
final char comport[] = {'C', 'O', 'M','1'};
SetupPR spr = new SetupPR();
spr.baud = 9600; spr.stop = 1; spr.parity = 'N'; spr.data = 8; //spr.port = comport; spr.port = "COM1"; byte actual = 0; //byte expected = 0;
actual = PR2Communication.pr2comm.PRT_OPENCOM(spr); System.out.println("returned = "+ actual); actual = PR2Communication.pr2comm.PRT_CHECKHW(); System.out.println("returned = "+ actual); actual = PR2Communication.pr2comm.PRT_EJECT(); System.out.println("returned = "+ actual);
actual = PR2Communication.pr2comm.PRT_RESET(); System.out.println("returned = "+ actual); String str = "Hello Hello";byte len = (byte)str.length(); actual = PR2Communication.pr2comm.PRT_WRITE(str,len);
} } ================================================================= import java.lang.String;
import com.sun.jna.Structure; import com.sun.jna.win32.StdCallLibrary;
public class SetupPR extends Structure { //public char port[] = {'C', 'O', 'M','1'}; public String port = "com1"; public short baud = 9600; public byte parity = 'N'; public byte data = 8; public byte stop = 1; } ================================================ The above maps typedef struct (_SETUPPR
CHAR CHAR Port[5]; Port [5]; Puerta (COM1 .. COMx) Puerta (COM1 .. COMx)
USHORT Ushort Baud; Baud; Velocidad (600 .. 9600) Speed (600 .. 9600)
BYTE BYTE Parity; Parity; Paridad (N=no, O=impar, E=par) Parity (N = no, O = odd, E = par)
BYTE BYTE Data; Data; Bits Data (7 ó 8) Data bits (7 or 8)
BYTE BYTE Stop; Stop; Bits Stop (1 ó 2) Stop bits (1 or 2)
} SETUPPR; SETUPPR);







