1
  void ProcedureParams_Initialize(ProcedureParams* pVal);
    flag ProcedureParams_IsConstraintValid(const ProcedureParams* val, int* pErrCode);
    flag ProcedureParams_XER_Encode(const ProcedureParams* val, ByteStream* pByteStrm, int* pErrCode, flag bCheckConstraints);
    flag ProcedureParams_XER_Decode(ProcedureParams* pVal, ByteStream* pByteStrm, int* pErrCode);
    flag ProcedureParams_BER_Encode(const ProcedureParams* val, ByteStream* pByteStrm, int* pErrCode, flag bCheckConstraints);
    flag ProcedureParams_BER_Decode(ProcedureParams* pVal, ByteStream* pByteStrm, int* pErrCode);

typedef struct {
    GeneralEvthParams g_params;
    DataParams d_params;
} EvtHandlerParams;

how i can add .h file directly into my .java file. i'm using NDk and .h file inside my jni folder.i want to use the functions of header file . how i can directly use functions in java activity? please help me

1
  • how i can add .h file directly into my .java file. i'm using NDk and .h file inside my jni folder.i want to use the functions of header file . how i can directly use functions in java activity? please help me Commented Feb 26, 2014 at 12:00

1 Answer 1

0

You cannot invoke the C/C++ functions directly. The C implementations of Java native functions all have a very specific set of parameters:

  JNIEXPORT jint JNICALL Java_com_mycompany_MyClassName_myfunc
    (JNIEnv * env, jobject obj, jint code) {
     ...
  }

So you will have to create wrapper functions.

A reasonable approach is to define a class including the Java versions of all your native functions (as either static or instance methods), and invoke them via that class.

To generate C headers from the Java (well, not source but the .class files), you can do:

cd bin/classes
javah com.mycompany.MyClassName com.mycompany.AnotherClassName
Sign up to request clarification or add additional context in comments.

19 Comments

i have already header file inside my jni folder, bt i have to only use the functions inside that header file? is it possible to call that methods directly?
Yaa one more thing can is use structure pointers in .java class? if its possible what are the methods, i want to use because inside c source header file i have structure to pointers methods.
Java cannot call C/C++ functions directly, the only way is to define native functions and call the C/C++ functions from them. Anyway, normal C/C++ functions cannot do anything useful with Java Objects or arrays.
then how we can access structure variables of .h file?
You can keep pointers to native structures as Java integers, but freeing them will be a bit schizophrenic. Java VM has no direct access to the C structures of the underlying system.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.