Solved

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

Posted on 2014-03-17
1
455 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
This video teaches viewers about errors in exception handling.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now