求大侠帮忙!!!jnative组件怎么样用java调用dll文件里的方法!!
1个回答
展开全部
public class TestHello {
public native void displayHelloWorld();
public native int sum(int a, int b);
static {
System.loadLibrary("testhello"); //装载dll文件
}
public static void main(String[] args) {
TestHello th = new TestHello();
int y = new TestHello().sum(2, 4);
System.out.println("y=" + y);
th.displayHelloWorld();
}
}
//下面是DLL文件的源码
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class TestHello */
#ifndef _Included_TestHello
#define _Included_TestHello
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: TestHello
* Method: displayHelloWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_TestHello_displayHelloWorld
(JNIEnv *, jobject);
/*
* Class: TestHello
* Method: sum
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_TestHello_sum
(JNIEnv *, jobject, jint, jint);
#ifdef __cplusplus
}
#endif
#endif
public native void displayHelloWorld();
public native int sum(int a, int b);
static {
System.loadLibrary("testhello"); //装载dll文件
}
public static void main(String[] args) {
TestHello th = new TestHello();
int y = new TestHello().sum(2, 4);
System.out.println("y=" + y);
th.displayHelloWorld();
}
}
//下面是DLL文件的源码
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class TestHello */
#ifndef _Included_TestHello
#define _Included_TestHello
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: TestHello
* Method: displayHelloWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_TestHello_displayHelloWorld
(JNIEnv *, jobject);
/*
* Class: TestHello
* Method: sum
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_TestHello_sum
(JNIEnv *, jobject, jint, jint);
#ifdef __cplusplus
}
#endif
#endif
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询