java(jna)利用dll关联硬件,String传参出现内存错误
publicclassTestXieKa{/***@paramargs*/publicstaticvoidmain(String[]args){//TODO自动生成方法存...
public class TestXieKa {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
System.out.println(writecardMethods(3,9600,02,10,"00000000"));
}
public interface writecard extends Library{
public boolean writecard(int port,int btl,int qh,int kh,String s);//定义该接口
}
public static boolean writecardMethods(int port,int btl,int qh,int kh,String s){ //在java中定义该方法,传入一参数,返回加密后的密码
writecard write=(writecard)Native.loadLibrary("icpos",writecard.class);//加载该DLL文件,BaseFun代表文件名,Enc代表该函数
boolean b=write.writecard(port, btl, qh, kh, s);
return b;
}
}
提示错误:
Exception in thread "main" java.lang.Error: Invalid memory access
at com.sun.jna.Native.invokeInt(Native Method)
at com.sun.jna.Function.invoke(Function.java:371)
at com.sun.jna.Function.invoke(Function.java:315)
at com.sun.jna.Library$Handler.invoke(Library.java:212)
at $Proxy0.writecard(Unknown Source)
at com.hua.test.TestXieKa.writecardMethods(TestXieKa.java:21)
at com.hua.test.TestXieKa.main(TestXieKa.java:14)
此为厂商提供接口
Function writecard(port:integer;btl:integer;qh:Integer;kh:integer;str:string):boolean; stdcall;External 'icpos.dll' name 'writecard';
参数说明:port:端口
btl:波特率(9600)
qh:扇区
kh:块号
str:块内容(16个字节) 展开
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
System.out.println(writecardMethods(3,9600,02,10,"00000000"));
}
public interface writecard extends Library{
public boolean writecard(int port,int btl,int qh,int kh,String s);//定义该接口
}
public static boolean writecardMethods(int port,int btl,int qh,int kh,String s){ //在java中定义该方法,传入一参数,返回加密后的密码
writecard write=(writecard)Native.loadLibrary("icpos",writecard.class);//加载该DLL文件,BaseFun代表文件名,Enc代表该函数
boolean b=write.writecard(port, btl, qh, kh, s);
return b;
}
}
提示错误:
Exception in thread "main" java.lang.Error: Invalid memory access
at com.sun.jna.Native.invokeInt(Native Method)
at com.sun.jna.Function.invoke(Function.java:371)
at com.sun.jna.Function.invoke(Function.java:315)
at com.sun.jna.Library$Handler.invoke(Library.java:212)
at $Proxy0.writecard(Unknown Source)
at com.hua.test.TestXieKa.writecardMethods(TestXieKa.java:21)
at com.hua.test.TestXieKa.main(TestXieKa.java:14)
此为厂商提供接口
Function writecard(port:integer;btl:integer;qh:Integer;kh:integer;str:string):boolean; stdcall;External 'icpos.dll' name 'writecard';
参数说明:port:端口
btl:波特率(9600)
qh:扇区
kh:块号
str:块内容(16个字节) 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询