Java调用VC的dll

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;
        }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值