Java调用DLL
来源:互联网 发布:dat文件导入数据库 编辑:程序博客网 时间:2024/05/18 13:28
java调用dll的方法实例:
1、使用JNI调用:参考
http://wenku.baidu.com/view/927abf92f242336c1fb95e31.html
http://blog.csdn.net/whustyle/article/details/49123933
直接在java中输出类的配置:http://www.oschina.net/question/1402563_133543?fromerr=f7RcQNZn
2、使用JNA调用
例如:
需要导入jna.jar包
(1)接口类:
package com.lp.jna;
import com.sun.jna.Library;
import com.sun.jna.Native;
public interface JnaDllInterFace extends Library{
//void
//加载Dll
//JnaDllInterFace dllInterFace = (JnaDllInterFace)
//Native.loadLibrary((Platform.isWindows() ? "UnZipTool.dll" : "c"), JnaDllInterFace.class);
JnaDllInterFace instanceDll = (JnaDllInterFace)Native.loadLibrary("UnZipTool.dll",JnaDllInterFace.class);
//声明Dll中的函数,如果Dll中有个printf的函数,在此声明一个同名的
//且参数类型一致的方法,java与c的类型映射见第三节
public void getExportPatch(String strSourceZipPath, String strDestZipPath, String strNewDestZipPath);
}
(2)测试
package com.lp.test;
import com.lp.jna.JnaDllInterFace;
import com.sun.jna.Library;
public class TestDLL {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//fun("G:\\zipCeshi1\\Config.zip","G:\\zipCeshi2\\Config.zip","G:\\zipCeshi3");
//方法一:Jna调用DLL
/**
* jna测试
* 1、添加jna的jar包
* 2、添加接口extends Library
* 3、调用方法
*/
JnaDllInterFace.instanceDll.getExportPatch("G:\\zipCeshi1\\Config.zip", "G:\\zipCeshi2\\Config.zip","G:\\zipCeshi3");
System.out.println("hello world");
}
}
3、使用JNative调用
导入JNative.jar包
(1)接口文件
import org.xvolks.jnative.exceptions.NativeException;
public interface DllUtilTools {
void ImplementDll(String strSourcePath,String strDestPath,String strSavePath) throws NativeException, IllegalAccessException;
}
import org.xvolks.jnative.JNative;
import org.xvolks.jnative.Type;
import org.xvolks.jnative.exceptions.NativeException;
public class DllUtilToolsImpl implements DllUtilTools{
static JNative myjnative = null;
public void ImplementDll(String strSourcePath,String strDestPath,String strSavePath) throws NativeException,IllegalAccessException {
try {
if (myjnative == null) {
myjnative = new JNative("UnZipTool.dll", "getExportPatch");
myjnative.setRetVal(Type.INT);
}
//传入参数
//myjnative.setParameter(0,"F:\\ziptest\\ceshi1\\aaa\\aaa.zip
");
//myjnative.setParameter(1, "F:\\ziptest\\ceshi2\\v\\bbb.zip
");
//myjnative.setParameter(2, "F:\\ziptest\\ceshi3");
myjnative.setParameter(0, strSourcePath);
myjnative.setParameter(1, strDestPath);
myjnative.setParameter(2, strSavePath);
myjnative.invoke();
myjnative.getRetVal();
System.out.println(myjnative.getRetVal());
//return myjnative.getRetValAsInt();
} finally {
if (myjnative != null) {
myjnative.dispose();
}
}
}
}
impl.ImplementDll("F:\\ziptest\\ceshi1\\aaa\\aaa.zip
", "F:\\ziptest\\ceshi2\\v\\bbb.zip
", "F:\\ziptest\\ceshi3");
System.out.println("hello world!");
- java调用dll
- JAVA调用DLL(1)
- JAVA调用DLL
- java调用.dll程序
- JAVA调用DLL(转载),
- java调用.dll程序
- JAVA 调用Dll
- java调用.dll文件
- Java调用DLL方法
- java调用dll
- java调用dll
- JAVA调用DLL
- java调用dll
- java 调用dll JNI
- java调用dll
- java调用Dll
- Java调用.dll文件
- java调用dll例子
- 实时 Java 社区论坛:Sym
- 线性结构栈----动态实现
- on my zsh 安装
- Hello Gradle
- 防抖算法小结
- Java调用DLL
- hive建外表时默认分隔符错误导致行数增加和数据错误
- 梯度下降法
- [HDU 1874] 畅通工程续 spfa 写法
- 快速打开Android虚拟机的方法
- leetcode---Power of Four
- memset calloc malloc
- JQ一些常用的方法
- PageRank算法在spark上的简单实现