관리 메뉴

드럼치는 프로그래머

[JNI/NDK] 자바의 int 형과 같은 기본형 데이터 타입을 JNI에서 다루는 예 본문

★─Programing/☆─JNI | NDK

[JNI/NDK] 자바의 int 형과 같은 기본형 데이터 타입을 JNI에서 다루는 예

드럼치는한동이 2013. 4. 22. 09:24

JNITest.java

public class JNITest
{
static{
System.loadLibrary("my_dll");
}

public native int add(int a, int b);

public static void main(String[] args)
{
JNITest test = new JNITest();
int result = test.add(3, 5);
System.out.println("C 함수 리턴값: "+result);
}
}



JNITest.h

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class JNITest */

#ifndef _Included_JNITest
#define _Included_JNITest
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: JNITest
* Method: add
* Signature: (II)I
*/

JNIEXPORT jint JNICALL Java_JNITest_add
(JNIEnv *, jobject, jint, jint);

#ifdef __cplusplus
}
#endif
#endif




my_dll.c

#include <stdio.h>
#include "JNITest.h"

JNIEXPORT jint JNICALL Java_JNITest_add
(JNIEnv *env, jobject obj, jint a, jint b) {

jint result = a+b;
printf("%d + %d = %d \n", a, b, a+b);
return result;

}

 


[출처] http://micropilot.tistory.com/category/J%20N%20I?page=4

Comments