|
Last change
on this file since 2 was 2, checked in by bird, 23 years ago |
|
Initial revision
|
-
Property cvs2svn:cvs-rev
set to
1.1
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
|
|
File size:
983 bytes
|
| Line | |
|---|
| 1 | #include <jni.h>
|
|---|
| 2 | #include "martin.h"
|
|---|
| 3 | #include <stdio.h>
|
|---|
| 4 |
|
|---|
| 5 | void Java_martin_myNative(JNIEnv* env, jobject this, jstring s)
|
|---|
| 6 | {
|
|---|
| 7 | jclass cls;
|
|---|
| 8 | jfieldID fid;
|
|---|
| 9 | jobject obj;
|
|---|
| 10 | jmethodID mid;
|
|---|
| 11 |
|
|---|
| 12 | printf("From C\n");
|
|---|
| 13 | fflush(stdout);
|
|---|
| 14 |
|
|---|
| 15 | cls = (*env)->FindClass(env, "java/lang/System");
|
|---|
| 16 | if (cls == 0) {
|
|---|
| 17 | printf("java/lang/System lookup failed\n");
|
|---|
| 18 | return;
|
|---|
| 19 | }
|
|---|
| 20 | fid = (*env)->GetStaticFieldID(env, cls, "out", "Ljava/io/PrintStream;");
|
|---|
| 21 | if (fid == 0) {
|
|---|
| 22 | printf("java/lang/System::out lookup failed\n");
|
|---|
| 23 | return;
|
|---|
| 24 | }
|
|---|
| 25 | obj = (*env)->GetStaticObjectField(env, cls, fid);
|
|---|
| 26 | if (obj == 0) {
|
|---|
| 27 | printf("GetStaticObjectField call failed\n");
|
|---|
| 28 | return;
|
|---|
| 29 | }
|
|---|
| 30 | cls = (*env)->GetObjectClass(env, obj);
|
|---|
| 31 | if (cls == 0) {
|
|---|
| 32 | printf("GetObjectClass(out) failed\n");
|
|---|
| 33 | return;
|
|---|
| 34 | }
|
|---|
| 35 | mid = (*env)->GetMethodID(env, cls, "println", "(Ljava/lang/String;)V");
|
|---|
| 36 | if (mid == 0) {
|
|---|
| 37 | printf("println method lookup failed\n");
|
|---|
| 38 | return;
|
|---|
| 39 | }
|
|---|
| 40 | (*env)->CallVoidMethod(env, obj, mid, s);
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.