69,373
社区成员
发帖
与我相关
我的任务
分享
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_test_read_Comm */
#ifndef _Included_com_test_read_Comm
#define _Included_com_test_read_Comm
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_test_read_Comm
* Method: getMsgOut
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_testread_Comm_getMsgOut
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
#include <stdio.h>
#include <string.h>
#include <jni.h>
#include "Comm.h"
//char* to jstring
jstring stoJstring(JNIEnv* env, const char* pat)
{
jclass strClass = (*env)->FindClass(env, "Ljava/lang/String;");
jmethodID ctorID = (*env)->GetMethodID(env, strClass, "<init>", "([BLjava/lang/String;)V");
jbyteArray bytes = (*env)->NewByteArray(env, strlen(pat));
(*env)->SetByteArrayRegion(env, bytes, 0, strlen(pat), (jbyte*)pat);
jstring encoding = (*env)->NewStringUTF(env, "utf-8");
return (jstring)(*env)->NewObject(env, strClass, ctorID, bytes, encoding);
}
JNIEXPORT jstring JNICALL _Java_com_test_read_Comm_getMsgOut
(JNIEnv *env, jobject obj)
{
unsigned char* msg = "this is SO file";
printf("%s\n", msg);
return stoJstring(env, msg);
}
class Comm
{
private native static String getMsgOut();
public static void main(String[] args)
{
try{
Comm test = new Comm();
System.out.println(test.getMsgOut());
}catch(Exception ex){
System.out.println("错了");
}
}
static
{
System.loadLibrary("Comm");
}
}