referance array passing to c++

hi,

from what i know, it is not possible to return a whole array back to java program, as java supports no pointers

so for my method what i have done is passed a static array to the native code and updated it from the c++ code so that when native code alters it, it should be altered in java automatically

but in actual this does not happen, any one has any ideas on this one?

i am giving my code below:

class DGlove

{

public static int[] values = new int[7];

public static boolean status = false;

public static native void getValues(int[] array);

public static native void connectDG();

public static native void disconnectDG();

public static native boolean getStatus();

static

{

System.loadLibrary("dg5dt");

}

public static void main (String[] args)

{

connectDG();

getValues(values);

status = getStatus();

System.out.println(status);

for (int i =0; i<=6;i++)

{

System.out.println(values);

}

//if (status == true)

//disconnectDG();

status = getStatus();

System.out.println(status);

getValues(values);

for (int i =0; i<=6;i++)

{

System.out.println(values);

}

}

}

//cpp file (native code)

# include "conio.h"

# include "DataGlove.h"

# include "DGlove.h"

# include "jni.h"

unsigned short arraydg15[17];

int arraydg5[6];

bool status=0;

DataGlove glove;

JNIEXPORT void JNICALL Java_DGlove_getValues

(JNIEnv *env, jclass obj, jintArray arr)

{

jsize len = env->GetArrayLength(arr);

if (status == 1)

{

glove.GetSensorRawValues (arraydg15);

// conversion from the 15 sensor array to the 5 sensor array

arraydg5[0] = arraydg15[0];

arraydg5[1] = arraydg15[3];

arraydg5[2] = arraydg15[6];

arraydg5[3] = arraydg15[9];

arraydg5[4] = arraydg15[12];

arraydg5[5] = arraydg15[16];

arraydg5[6] = arraydg15[17];

jint *body = env->GetIntArrayElements(arr,0);

for (int i =0;i<=len;i++)

{

body = arraydg5;

}

}

}

JNIEXPORT void JNICALL Java_DGlove_connectDG

(JNIEnv *env, jclass obj)

{

status = glove.Connect("COM1");

printf("data glove status %d", status);

getch();

}

JNIEXPORT void JNICALL Java_DGlove_disconnectDG

(JNIEnv *env, jclass obj)

{

status = glove.DisConnect();

}

JNIEXPORT jboolean JNICALL Java_DGlove_getStatus

(JNIEnv *env, jclass obj)

{

return status;

}

what i need to do is pass the array by referance to native c++ code , have it modified and get the values back in java

[2944 byte] By [danish_sh] at [2007-9-26 2:52:32]
# 1
An array is a java object, and like any other object can be returned by a native (C) method. You just have to make the right JNI calls to create and populate the array.
bschauwe at 2007-6-29 10:40:42 > top of Java-index,Java HotSpot Virtual Machine,Specifications...