• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 491
  • Last Modified:

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

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
jgdvishnu
Asked:
jgdvishnu
1 Solution
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now