F -X C h a n ge                                                                                                           ...
F -X C h a n ge                                                                                                  F -X C h ...
F -X C h a n ge                                                                                                       F -X...
F -X C h a n ge                                                                                                 F -X C h a...
F -X C h a n ge                                                                                                           ...
Upcoming SlideShare
Loading in...5
×

Jni+简介与实现

290

Published on

android jni的介绍

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
290
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Jni+简介与实现

  1. 1. F -X C h a n ge F -X C h a n ge PD PD ! ! W W O O N N y y bu bu to to k k lic lic C C w w m m w w w w o o .c .c JNI .d o .d o c u -tr a c k c u -tr a c k http://blog.chinaunix.net/u3/90973/index.html JNI JNI Java Native Interface , Java java jvm JAVA JNI WINDOWS DLL UNIX SO JAVA jvm Java Development Kit (JDK) 1.6.0 Microsoft Visual Studio2005 C dll JNI JNI Java Native Interface , Java java jvm JAVA JNI WINDOWS DLL UNIX SO JAVA jvm Java Development Kit (JDK) 1.6.0 Microsoft Visual Studio2005 C dll · native java · javac java · javah java h · C/C++ · java java
  2. 2. F -X C h a n ge F -X C h a n ge PD PD ! ! W W O O N N y y bu bu to to k k lic lic C C w w m m w w w w o o .d o .c .d o .c c u -tr a c k c u -tr a c k 1 java JAVA static { System.loadLibrary(“dllname”); } DLL SO native public native static void fn1(int i); public native static int fn2(void ); JAVA CLASS JAVAH JNI C/C++ java TestDel.java public class TestDel { static { System.loadLibrary("cjw"); // cjw } public native static void creFolder(); public native static void delFolder1(); public native static void delFolder2(); public static void main(String[] args) { TestDel test = new TestDel(); System.out.println("start create Folder..."); test.creFolder(); System.out.println("create Folder finished."); long stime = System.currentTimeMillis(); //test.delFolder1(); test.delFolder2(); long etime =System.currentTimeMillis(); System.out.println(etime-stime); } } javac TestDel.java TestDel.class javah TestDel TestDel.h C/C++ 2 .h C/C++ TestDel.h /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h>
  3. 3. F -X C h a n ge F -X C h a n ge PD PD ! ! W W O O N N y y bu bu to to k k lic lic C C w w m m w w w w o o .d o .c .d o .c c u -tr a c k c u -tr a c k /* Header for class TestDel */ #ifndef _Included_TestDel #define _Included_TestDel #ifdef __cplusplus extern "C" { #endif /* * Class: TestDel * Method: creFolder * Signature: ()V */ JNIEXPORT void JNICALL Java_TestDel_creFolder (JNIEnv *, jclass); /* * Class: TestDel * Method: delFolder1 * Signature: ()V */ JNIEXPORT void JNICALL Java_TestDel_delFolder1 (JNIEnv *, jclass); /* * Class: TestDel * Method: delFolder2 * Signature: ()V */ JNIEXPORT void JNICALL Java_TestDel_delFolder2 (JNIEnv *, jclass); #ifdef __cplusplus } #endif #endif JNIEXPORT void JNICALL Java_TestDel_creFolder (JNIEnv *, jclass); JNIEXPORT void JNICALL Java_TestDel_delFolder1 (JNIEnv *, jclass); JNIEXPORT void JNICALL Java_TestDel_delFolder2 (JNIEnv *, jclass); JNIEXPORT JNICALL JNI JNI java int jint JNI JAVA int int int JAVA_ java package JAVA JNIEnv* jclass dll VS2005 dll "WebDeploymentSetup.msi" New VC++ win32 project dll Empty project java
  4. 4. F -X C h a n ge F -X C h a n ge PD PD ! ! W W O O N N y y bu bu to to k k lic lic C C w w m m w w w w o o .d o .c .d o .c c u -tr a c k c u -tr a c k test.cpp( cpp c builder )test.cpp #include "TestDel.h"): #include <stdio.h> #include <direct.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <sys/stat.h> #include "TestDel.h" JNIEXPORT void JNICALL Java_TestDel_creFolder(JNIEnv *, jclass) { int i,j; char buf1[20]; char buf2[20]="./Folder/"; char buf3[20]; mkdir("Folder"); for(i=0;i<100;i++) { itoa(i,buf1,10); mkdir(strcat(buf2,buf1)); strcpy(buf3,strcat(buf2,"")); for(j=0;j<100;j++) { itoa(j,buf1,10); mkdir(strcat(buf2,buf1)); strcpy(buf2,buf3); } strcpy(buf2,"./Folder/"); } } JNIEXPORT void JNICALL Java_TestDel_delFolder1 (JNIEnv *, jclass) { int i,j; char buf1[20]; char buf2[20]=".Folder"; char buf3[20]; for(i=0;i<100;i++) { itoa(i,buf1,10); strcat(buf1,""); strcpy(buf3,strcat(buf2,buf1)); for(j=0;j<1000;j++) { itoa(j,buf1,10); rmdir(strcat(buf2,buf1)); strcpy(buf2,buf3); } rmdir(buf3);
  5. 5. F -X C h a n ge F -X C h a n ge PD PD ! ! W W O O N N y y bu bu to to k k lic lic C C w w m m w w w w o o .d o .c .d o .c c u -tr a c k c u -tr a c k strcpy(buf2,".Folder"); } } JNIEXPORT void JNICALL Java_TestDel_delFolder2 (JNIEnv *, jclass) { char cmd[50]; strcpy(cmd,"rmdir /s/q "); strcat(cmd,"Folder"); system(cmd); } SDK include ( win32 ) VC include VS toolsoptions - Projects and SolutionsVC++ Project Settings directories include ../sdk1.5.0/inlcude ../sdk1.5.0/include/win32 dll( debug JAVA cjw.dll 3 cjw.dll TestDel.class java TestDel

×