日期:2014-05-20  浏览次数:20758 次

java调用dll 堆栈溢出
我在做一个RFID读卡器,在调用其中的初始化函数的时候 总归是爆出堆栈溢出的错误。
请问如何解决? 用到了 JNA的技术 dll文件问 rfid.dll
java代码如下:

public class EcardReaderImpl {
 /**
  * 连接读写器
  * @param port
  * @return
  * @throws NativeException
  * @throws IllegalAccessException
  */
 public String ConnectionReader(int port) throws NativeException, IllegalAccessException{
  JNative n = null;
  try{ 
   //1.创建JNative对象

   n = new JNative("rfid.dll","RFID_Startup");//初始化
   //2.设置函数返回值类型
   n.setRetVal(Type.INT);
   //3.设置参数类型
   int i=0;
   n.setParameter(i++, port);
   //4.执行函数
   n.invoke();
   //5.获取函数返回值
  
   return n.getRetVal();
  }finally{
   if(n!=null){
    n.dispose();
   }
  }
 }


 /**
  * 关闭读卡器
  * @return
  * @throws NativeException
  * @throws IllegalAccessException
  */
 public String CloseReader() throws NativeException, IllegalAccessException{
  JNative n = null;
  try{ 
   //1.创建JNative对象
   n = new JNative("rfid.dll","RFID_Shutdown");
   //设置函数返回值类型
   n.setRetVal(Type.INT);
   //设置参数类型
   
   //执行函数
   n.invoke();
   //获取函数返回值
   return n.getRetVal();
  }finally{
   if(n!=null){
    n.dispose();
   }
  }
 }
 
 public static void main(String[] args)throws NativeException, IllegalAccessException {
  EcardReaderImpl impl = new EcardReaderImpl();

  System.out.println("连接读卡器=="+impl.ConnectionReader(1));

 System.out.println("关闭读写器=="+impl.CloseReader());
 }
}

#
# An unexpected error has been detected by Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x100101b4, pid=11152, tid=8808
#
# Java VM: Java HotSpot(TM) Client VM (11.0-b15 mixed mode, sharing windows-x86)
# Problematic frame:
# C  [rfid.dll+0x101b4]
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  T H R E A D  ---------------

Current thread (0x02579800):  JavaThread "main" [_thread_in_native, id=8808, stack(0x002c0000,0x00310000)]

siginfo: ExceptionCode=0xc0000005, writing address 0x00000001

Registers:
EAX=0x00000007, EBX=0x00000000, ECX=0x00000000, EDX=0x04c60178
ESP=0x002ff9f4, EBP=0x002ffa44, ESI=0x00000001, EDI=0x04c62e90
EIP=0x100101b4, EFLAGS=0x00010202

Top of Stack: (sp=0x002ff9f4)
0x002ff9f4:   fb456bfa 00000000 00000000 00000000
0x002ffa04:   6da7a2e0 ffffff00 00000001 002ffa30
0x002ffa14:   7651de45 765b0630 0257e3c0 04c62de8
0x002ffa24:   00000000 00000000 00000000 002ffa48
0x002ffa34:   002ff9f4 0030fd9c 1001bbb1 00000002
0x002ffa44:   0030fbd8 66c44773 00000001 0257e3c0
0x002ffa54:   6d9813ae 02579800 00000006 00000004
0x002ffa64:   00000000 00000020 66c4452e 02579914 

Instructions: (pc=0x100101b4)
0x100101a4:   01 c6 45 fc 02 33 db eb 03 8b 75 08 3b f3 74 1b
0x100101b4:   c7 06 02 00 00 00 c7 46 04 04 00 00 00 c7 46 08 


Stack: [0x002c0000,0x00310000],  sp=0x002ff9f4,  free space=254k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [rfid.dll+0x101b4]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.xvolks.jnative.JNative.nInvoke(I)V+0
j  org.xvolks.jnative.JNative.invoke()V+55
j  ecard.sys.javadll.EcardReaderImpl.ConnectionReader(I)Ljava/lang/String;+33
j  ecard.sys.javadll.EcardReaderImpl.main([Ljava/lang/String;)V+22