环境:jdk1.7_02 IDE:netbeans7.1类名:mydll.java
代码:
public class mydll{
public static final String DLL_NAME1 = "ZSComm.DLL";
private static JNative jn;
public static int GSC_GetDLLVersion(String version) throws NativeException, IllegalAccessException{
int ret =0;
try {
jn = new JNative(DLL_NAME1,"GSC_GetDLLVersion");
//设置此函数的返回值
jn.setRetVal(Type.INT);
int i = 0;
jn.setParameter(i++, Type.STRING, ""+version);
jn.invoke();
ret = Integer.parseInt(jn.getRetVal());
System.out.println(jn.getRetVal());
} finally{
if (jn !=null){
jn = null;
}
}
return ret;
} //测试用
public static void main(String[] args){
String v ="";
try {
mydll.GSC_GetDLLVersion(v);
System.out.println("version:"+v);
} catch (NativeException | IllegalAccessException ex) {
Logger.getLogger(Jzscom.class.getName()).log(Level.SEVERE, null, ex.getMessage());
}
}运行:提示
run:
java.lang.NoSuchFieldError: lastError
1 //1表示成功调用DLL
//小弟以下代码为不明,请仁兄指教
at org.xvolks.jnative.JNative.nInvoke(Native Method)
version:
ccx_jni_utils.c.writeLog : can't get a Java Logger instance.
at org.xvolks.jnative.JNative.invoke(JNative.java:807)
at yqcore.zscom.Jzscom.GSC_GetDLLVersion(Jzscom.java:47)
at yqcore.zscom.Jzscom.main(Jzscom.java:357)
Exception in thread "main" 成功生成(总时间:1 秒)
代码:
public class mydll{
public static final String DLL_NAME1 = "ZSComm.DLL";
private static JNative jn;
public static int GSC_GetDLLVersion(String version) throws NativeException, IllegalAccessException{
int ret =0;
try {
jn = new JNative(DLL_NAME1,"GSC_GetDLLVersion");
//设置此函数的返回值
jn.setRetVal(Type.INT);
int i = 0;
jn.setParameter(i++, Type.STRING, ""+version);
jn.invoke();
ret = Integer.parseInt(jn.getRetVal());
System.out.println(jn.getRetVal());
} finally{
if (jn !=null){
jn = null;
}
}
return ret;
} //测试用
public static void main(String[] args){
String v ="";
try {
mydll.GSC_GetDLLVersion(v);
System.out.println("version:"+v);
} catch (NativeException | IllegalAccessException ex) {
Logger.getLogger(Jzscom.class.getName()).log(Level.SEVERE, null, ex.getMessage());
}
}运行:提示
run:
java.lang.NoSuchFieldError: lastError
1 //1表示成功调用DLL
//小弟以下代码为不明,请仁兄指教
at org.xvolks.jnative.JNative.nInvoke(Native Method)
version:
ccx_jni_utils.c.writeLog : can't get a Java Logger instance.
at org.xvolks.jnative.JNative.invoke(JNative.java:807)
at yqcore.zscom.Jzscom.GSC_GetDLLVersion(Jzscom.java:47)
at yqcore.zscom.Jzscom.main(Jzscom.java:357)
Exception in thread "main" 成功生成(总时间:1 秒)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货