package com.org.test;
import org.xvolks.jnative.JNative;
import org.xvolks.jnative.exceptions.NativeException;
import org.xvolks.jnative.pointers.Pointer;
import org.xvolks.jnative.pointers.memory.MemoryBlockFactory;
import org.xvolks.jnative.Type;
public class EyPatrol {
/**
* return 转换成功的字节数
*/
static JNative Something = null;
static Pointer pointer;
static int hComDev;
public int getSomething() throws NativeException, IllegalAccessException {
int rev =-1 ;
try {
if (Something == null) {
Something = new JNative("eyPatrol.dll", "connect_hd");
Something.setRetVal(Type.LONG); // 指定返回参数的类型
}
int i = 0;
pointer = new Pointer(MemoryBlockFactory.createMemoryBlock(32));
pointer.setIntAt(0, 32);
Something.setParameter(i++,"123");
Something.setParameter(i++,pointer);
Something.setParameter(i++,115200);
System.out.println("调用的DLL文件名为:" + Something.getDLLName());
System.out.println("调用的方法名为:" + Something.getFunctionName());
System.out.println("*****"+pointer.asLONG());
Something.invoke();// 调用方法
rev = Something.getRetValAsInt();
if(rev!=0)
System.out.println("连接失败");
else
System.out.println("连接成功");
hComDev = Something.getFunctionPointer(); // 供给其他函数调用
System.out.println("---"+Something.getStyle());
System.out.println("---"+Something.getFunctionPointer());
return Integer.parseInt(Something.getRetVal());
}
catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("执行建立连接完毕!");
}
return rev ;
}
public static void main(String[] args) throws NativeException,
IllegalAccessException {
EyPatrol uc = new EyPatrol();
int result = uc.getSomething();
System.err.println("连接端口句柄为:" + result);
if (Something != null)
Something = null;
}
}
Java调用VC的dll
最新推荐文章于 2021-03-14 13:58:01 发布