Game Development Reference
In-Depth Information
Listing 2-3. Native Library Implementation
#include <stdio.h>
#include <stdlib.h>
/* JNI Includes */
#include <jni.h>
#include "include/jni_Natives.h"
#define CB_CLASS "jni/Natives"
/**
* OnMessage callback
*/
#define CB_CLASS_MSG_CB "OnMessage"
#define CB_CLASS_MSG_SIG "(Ljava/lang/String;I)V"
// prototypes
// Lib main Sub
int lib_main(int argc, char **argv) ;
// Used to get the len of a Java Array
const int getArrayLen(JNIEnv * env, jobjectArray jarray);
// printf str messages back to java
void jni_printf(char *format, ...);
// Global env ref (for callbacks)
static JavaVM *g_VM;
// Global Reference to the native Java class jni.Natives.java
static jclass jNativesCls;
/*
* Class: jni_Natives
* Method: LibMain
* Signature: ([Ljava/lang/String;)V
*/
JNIEXPORT jint JNICALL Java_jni_Natives_LibMain
(JNIEnv * env, jclass class, jobjectArray jargv)
{
// Obtain a global ref to the caller jclass
(*env)->GetJavaVM(env, &g_VM);
// Extract char ** args from Java array
jsize clen = getArrayLen(env, jargv);
char * args[(int)clen];
Search WWH ::




Custom Search