File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes chaning array contents in java native function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "chaning array contents in java native function" Watch "chaning array contents in java native function" New topic
Author

chaning array contents in java native function

Shailesh Kendale
Greenhorn

Joined: Sep 27, 2001
Posts: 2
I have 2 classes as follows :
class JavaClass
{
public static native void changeArrayContents(Object obj);
static
{
System.loadLibrary ("DLL_FILE_NAME");
}
public static void main (String[] args)
{
TestClass test_class = new TestClass ();
JavaClass.changeArrayContents (test_class);
}
}
class TestClass
{
byte[] byteArr = new byte[3];
TestClass ()
{
byteArr[0] = 1;
byteArr[1] = 2;
byteArr[2] = 3;
}
}

Then what could be the native code (in c languages) that will mopdify contents of test_class.byteArr.
------------------
Shailesh Kendale
Greenhorn

Joined: Sep 27, 2001
Posts: 2
Got the sol.n
JNIEXPORT void JNICALL Java_PACEEncrypter_changeArrayContents
(JNIEnv *env, jclass cl, jobject obj)
{
int *intPtr;
int i;

jclass javaCl;
jfieldID javaCl_Fld_ID;
jintArray intArray;
//jintArray intArr = (int *)malloc(sizeof(jint) * 3);
javaCl = (*env)->GetObjectClass (env, obj);
javaCl_Fld_ID = (*env)->GetFieldID (env, javaCl, "arr", "[I");
intArray = (jintArray) (*env)->GetObjectField (env, obj, javaCl_Fld_ID);
intPtr = (*env)->GetIntArrayElements(env, intArray, NULL);

printf ("\n\n");
printf ("\nchanging in c program\n");
for (i = 0; i < (*env)->GetArrayLength(env, intArray); i++)
{
intPtr[i] = 55;
printf ("arr[%d] : %d\n", i, intPtr[i]);
}
(*env)->ReleaseIntArrayElements (env, intArray, intPtr, JNI_COMMIT);
printf ("\n\n");
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: chaning array contents in java native function
 
Similar Threads
what 's wrong?
Two thread slow on dual core?
Inner Class
Which method??
Threads