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