/* * HelloWorld.c * * Copyright (c) 1999 Karl Moss. All Rights Reserved. * * You may study, use, modify, and distribute this software for any * purpose provided that this copyright notice appears in all copies. * * This software is provided WITHOUT WARRANTY either expressed or * implied. * * author Karl Moss * version 1.0 * date 16Feb99 * * This module contains example methods that show how to write * Java applications using JNI (the Java Native Interface) */ #include #include #include "javaservlets_nativeCode_HelloWorld.h" #define HELLO "Hello World" /* * Class: javaservlets_nativeCode_HelloWorld * Method: getMessage * Signature: ()Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_javaservlets_nativeCode_HelloWorld_getMessage (JNIEnv *env, jobject caller) { return (*env)->NewStringUTF(env, HELLO); } /* * Class: javaservlets_nativeCode_HelloWorld * Method: printMessage * Signature: (Ljava/io/PrintWriter;)V */ JNIEXPORT void JNICALL Java_javaservlets_nativeCode_HelloWorld_printMessage (JNIEnv *env, jobject caller, jobject out) { jclass jcls; jmethodID jmid; // Get the PrintWriter class and find the println method jcls = (*env)->GetObjectClass(env, out); if (jcls) { jmid = (*env)->GetMethodID(env, jcls, "println", "(Ljava/lang/String;)V"); if (jmid == 0) { return; } // Invoke the println method on the PrintStream object (*env)->CallVoidMethod(env, out, jmid, (*env)->NewStringUTF(env, HELLO)); } }