-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
7,180 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <jni.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include "Main.h" | ||
|
||
JNIEXPORT void JNICALL Java_Main_native_1hello | ||
(JNIEnv * env, jclass cls) { | ||
printf("Hello JNI!\n"); | ||
} | ||
|
||
JNIEXPORT jint JNICALL Java_Main_add | ||
(JNIEnv * env, jobject instance, jint a, jint b) { | ||
return a + b; | ||
} | ||
|
||
JNIEXPORT jstring JNICALL Java_Main_hi | ||
(JNIEnv * env, jobject instance, jstring javaString) { | ||
char* hello = "Hello,"; | ||
const char* name = (*env)->GetStringUTFChars(env, javaString, 0); | ||
size_t len = strlen(hello) + strlen(name) + 1; | ||
char* result = (char*)malloc(len); | ||
strcpy(result, hello); | ||
strcat(result, name); | ||
(*env)->ReleaseStringUTFChars(env, javaString, name); | ||
return (*env)->NewStringUTF(env, result); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class Main { | ||
static { | ||
System.load("C:/Users/sunwu/Desktop/base/gateway/notebook/24.06/jni/libMyJNI.dll"); | ||
} | ||
|
||
public static native void native_hello(); | ||
public native int add(int a, int b); | ||
|
||
public native String hi(String name); | ||
|
||
public static void main(String[] args) { | ||
native_hello(); | ||
System.out.println(new Main().add(1, 1)); | ||
System.out.println(new Main().hi("frank")); | ||
} | ||
} |
Oops, something went wrong.