Solved

How to pass *FileData(pointer) from Java to C

Posted on 2014-03-17
1
461 Views
Last Modified: 2014-03-20
I have to get some useful response data from a native library written in C.

I am not able to see how to pass (* fileData i.e. (pointer to fileData )) from java to C.
//1) NameofFile.c
int pspLoadFiles(PSPlusFileData* fileData)


//1) Java native method :-
public native int pspLoadFiles(java.io.File file );

//2) Generated Header File:-
/*
 * Class:     JavaTestClass
 * Method:    pspLoadFiles
 * Signature: (Ljava/io/File;)I
 */
JNIEXPORT jint JNICALL Java_JavaTestClass_pspLoadFiles
  (JNIEnv *, jobject, jobject);

Open in new window


Error:-
java.lang.UnsatisfiedLinkError: pspLoadFiles
        at JavaTestClass.pspLoadFiles(Native Method)
        at JavaTestClass.main(JavaTestClass.java:30)

How could we pass this fileData to C function.

thanks
Vishnu
0
Comment
Question by:jgdvishnu
1 Comment
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39936105
I have to get some useful response data from a native library written in C.

I am not able to see how to pass (* fileData i.e. (pointer to fileData )) from java to C.
You can't do it directly! You can't create some arbitrary C/C++ object (ie. PSPlusFileData) in Java and pass it to the native function. Any C/C++ objects need to be created in your native code.

What you need to do, is implement the Java_JavaTestClass_pspLoadFiles function in you C code to convert the information obtained from the Java File object passed in (via the jobject parameter) into the required information in your PSPlusFileData object.

And then, once this is done, that C function can call the real pspLoadFiles function with the pointer to PSPlusFileData that you have just setup.

I can't really help you much further without knowing anything about this PSPlusFileData class?
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question