2008年4月29日 星期二

如何在Java中call dll

如何在Java中call dll

自城市胡同


我知道的有两种方法,一种是直接用JNI,另一种是则是用Jacob(实质上也用的是JNI)

先讲讲第一种方法

1.编写java程序TestDll,注意,这个类有两个作用,一个是用来做头文件,另外一个作用就是通过它来调用dll
public class TestDll {
 static
 {
 System.loadLibrary("DLLSample");//载入dll
 }
 public native static int DoubleValue(int i);//函数声明
}

2.编译: javac TestDll
3.生成头文件: javah TestDll
生成TestDll.h文件,这里面只对函数DoubleValue作了声明
/\* DO NOT EDIT THIS FILE - it is machine generated \*/
\#include
/* Header for class TestDll */

\#ifndef \_Included_TestDll
\#define \_Included_TestDll
\#ifdef \__cplusplus
extern "C" {
\

沒有留言: