JNI调用(Java Native Interface)
来源:互联网 发布:电脑没网络wifi没网络 编辑:程序博客网 时间:2024/06/05 10:16
<1>用 “javah cn.itcast.TestNative”命令生成Java class文件中native方法对应的.h头文件。我生成的是:cn_itcast_TestNative.h
<2>生成动态链接库.dll文件。
需要另外另个jni.h和jni_md.h头文件,网上下载即可。
创建的工程是Win32 Dynamic-Link Library。编写一下源文件,把JNIEXPORT void JNICALL Java_cn_itcast_TestNative_sayHello (JNIEnv *env, jobject obj)
即Java调用的C函数实现一下,可见要实现的函数名字不是sayHello,有所修改。
同时将cn_itcast_TestNative.h中#include <jni.h>修改为#include "jni.h"
<3>在Debug目录下,将动态链接库头文件加入到path环境变量下.我的是我的dll所在的路径是:E:\VC6练习\TestNative3\Debug
这样,每次更新动态链接库,就不用管那么多了。
<4>在Java Class中调用函数即可,,和正常的java 调用没区别。
Java代码如下:
package cn.itcast;public class TestNative {public native void sayHello();static{ System.loadLibrary("TestNative3");}/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stub TestNative test = new TestNative(); test.sayHello();}}/* * Hello World in JNI! */
<5>重启Eclipse,因为Eclipse会重新查找环境变量。
<6>成功运行,搞定!!!
0 0
- JNI调用(Java Native Interface)
- JNI(java native interface , java本地调用)
- JNI(Java Native Interface)调用非java类方法
- java native interface JNI 调用Java方法
- JNI(Java Native Interface)
- JNI(Java Native Interface)
- JNI(Java Native Interface)调用中考虑的问题
- JNI:Java Native Interface
- JNI(java native interface)
- JNI - Java Native Interface
- JNI:Java Native Interface
- Java Native Interface (JNI)
- Java Native Interface (JNI)
- JNI:Java Native Interface
- JNI:Java Native Interface
- Java JNI(Java Native Interface)
- java JNI(java native interface)
- JNI(Java Native Interface)的使用
- MFC ListBox控件小记(添加记录和获取记录)
- 强大的任务管理器-Process Hacker
- 手机丢失实验叫板支付宝 揭秘小米官网怎么抢手机
- Lua基础学习——关系运算符
- 内存对齐的规则以及作用
- JNI调用(Java Native Interface)
- Etag和断点续传
- android 启动系统app
- Unity3d 编译顺序及原理
- jquery获取标签里的值html,val,text
- 自己动手实现arm函数栈帧回溯
- 《追寻生命的意义》
- poj2057-树状dp
- android intent和intent action大全 android intent和intent action大全 android 中intent是经常要用到的。不管是页面牵转,还是传递数据