Java中使用JNI调用DLL
1 编写范例文档
/**
* @Package:
* @Title: TestNative.java
* @Author: zhangzuoqiang
* @Time: 5:08:48 PM Sep 17, 2011
* @Version:
*/
/**
* @Description:
* @Author: zhangzuoqiang
* @Date: Sep 17, 2011
*/
public class TestNative {
private native int add(int x, int y);
public static void main(String[] args) {
TestNative hh = new TestNative();
int r = hh.add(30, 20);
System.out.println("result = " + r);
}
static {
System.loadLibrary("NativeDemo");
}
}
#include "TestNative.h"
#include <jni.h>
JNIEXPORT jint JNICALL Java_TestNative_add
(JNIEnv *ev, jobject obj, jint x, jint y)
{
return x+y;
}
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class TestNative */
#ifndef _Included_TestNative
#define _Included_TestNative
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: TestNative
* Method: add
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_TestNative_add
(JNIEnv *, jobject, jint, jint);
#ifdef __cplusplus
}
#endif
#endif