Solved

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

Posted on 2014-03-17
1
465 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

749 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