1、VC6(CPP)的DLL代码:

#include<stdio.h>
#include "jniZ_JNIjw06.h" // 全局变量
jfieldID g_propInt_id = ;
jfieldID g_propStr_id = ; JNIEXPORT void JNICALL Java_jniZ_JNIjw06_InitNativeIDs (JNIEnv * env, jclass clazz)
{
printf("Java_jniZ_JNIjw06_InitNativeIDs - 1\n"); g_propInt_id = env->GetFieldID(clazz, "propInt", "I");
g_propStr_id = env->GetFieldID(clazz, "propStr", "Ljava/lang/String;"); printf("Java_jniZ_JNIjw06_InitNativeIDs - 2\n");
} JNIEXPORT void JNICALL Java_jniZ_JNIjw06_OtherNative (JNIEnv * env, jobject obj)
{
printf("Java_jniZ_JNIjw06_OtherNative - 1\n"); // get field with g_propInt_id / g_propStr_id ... printf("Java_jniZ_JNIjw06_OtherNative - 2\n");
}

2、Java代码:

package jniZ;

public class JNIjw06
{
static
{
InitNativeIDs();
} static native void InitNativeIDs(); int propInt = 0;
String propStr = ""; public native void OtherNative(); public static void main(String[] args)
{
Object ll;
}
}

3、Java控制台输出:

4、

5、

05-11 09:24