`
chengzhi
  • 浏览: 110245 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

java调用dll之JNative学习笔记

    博客分类:
  • java
阅读更多

 

下载地址:

 

JNative_1.4RC2_src.zip : http://jaist.dl.sourceforge.net/sourceforge/jnative/JNative_1.4RC2_src.zip

 

JNative.jar : http://nchc.dl.sourceforge.net/sourceforge/jnative/JNative.jar

 

如果以上版本不能完成下载,说明版本有可能更新,请从以下地址中下载:

 

Resource URL: http://jnative.sourceforge.net/ 

 

Source Code: http://sourceforge.net/projects/jnative 

 

Detailed Review: http://jnative.free.fr 

 

JavaDOC: http://jnative.free.fr/docs/

 

JNative相对于其它同类开源组件的优点:

 

1.容易使用

 

2.对数据类型的处理做的出色

 

3.支持CallBack

 

下面以一个小Demo来学习一下JNative:

 

1.理解文件用途

 

JNative_1.4RC2_src.zip是JNative源代码的压缩包把它解压后从中找到libJNativeCpp.so和JNativeCpp.dll两个文件.JNativeCpp.dll应用在Windows平台下.把它放在c:\windows\system32目录下.libJNativeCpp.so应用在Linux平台下.放在哪个目录,这个我不知道.

 

把JNative.jar加入到所需的工程中.

 

把要调用的dll文件也放在c:\windows\system32目录下

 

2.测试类

 

package com.xgz.jnative;

 

import org.xvolks.jnative.JNative;

import org.xvolks.jnative.Type;

import org.xvolks.jnative.pointers.memory.MemoryBlockFactory;

 

public class Test {

 

public static void main(String[] args)throws Exception {

   //系统加载dll文件有两种写法1.loadLibrary方法:把dll文件拷贝到c:\windows\system32目录下,引用时只需写dll名字2.load方法:写dll文件的完整路径

   System.loadLibrary("InterfaceFun");//InterfaceFun是dll文件

   //参数说明InterfaceFun dll名,AddZhiYe函数名

   JNative jnative = new JNative("InterfaceFun","AddZhiYe");

   //设置此函数的返回值

   jnative.setRetVal(Type.INT);

   int i=0;

   //赋予参数值

   jnative.setParameter(i++, Type.STRING,"127.0.0.1");

   jnative.setParameter(i++, Type.STRING,"sa");

   jnative.setParameter(i++, Type.STRING,"sa");

   jnative.setParameter(i++, Type.STRING,"程序员");

   jnative.setParameter(i++, Type.INT,"23");

   jnative.setParameter(i++, Type.INT,"23");

   //函数执行

   jnative.invoke();

   //打印函数返回值

   System.out.println(Integer.parseInt(jnative.getRetVal()));

}

 

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics