日期:2014-05-17 浏览次数:20727 次
package Moniter.dictionary; public class mystruct { public int i1; public int i2; }
package Moniter.dictionary; public class TestStruct { static { System.loadLibrary("TestJni"); } public static native mystruct getMystruct(); }
/* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class Moniter_dictionary_TestStruct */ #ifndef _Included_Moniter_dictionary_TestStruct #define _Included_Moniter_dictionary_TestStruct #ifdef __cplusplus extern "C" { #endif /* * Class: Moniter_dictionary_TestStruct * Method: getMystruct * Signature: ()LMoniter/dictionary/mystruct; */ JNIEXPORT jobject JNICALL Java_Moniter_dictionary_TestStruct_getMystruct (JNIEnv *, jclass); #ifdef __cplusplus } #endif #endif
#include "stdafx.h" #include "Moniter_dictionary_TestStruct.h" JNIEXPORT jobject JNICALL Java_Moniter_dictionary_TestStruct_getMystruct(JNIEnv *env, jclass obj) { /**//* 下面为获取到Java中对应的实例类中的变量*/ OutputDebugString(("******0 setp")); jclass objectClass = (env)->FindClass("Moniter/dictionary/mystruct"); if (objectClass == NULL) { OutputDebugString(("******the object is null")); } //获取类中每一个变量的定义 //名字 //序列号 OutputDebugString(("******2 setp")); jfieldID ival1 = (env)->GetFieldID(objectClass,"i1","I"); jfieldID ival2 = (env)->GetFieldID(objectClass,"i2","I"); OutputDebugString(("******3 setp")); //给每一个实例的变量付值 (env)->SetShortField(obj,ival1,10); (env)->SetShortField(obj,ival2,10); OutputDebugString(("******5 setp")); return obj; }
mystruct ttMystruct = TestStruct.getMystruct();