开发者

Calling a pure C function from JNI method

I'm working on JNi example . I have a C file :

#include "test_lib.h"
#include <mobile_crypto.h>
#include <stdio.h>
int mainCrypto(void){
.
.
.
.
return 1 ;
}

Now i want to access the mainCrypto() method from another C file where my JNI methods are written :

#include "com_My_NativeLib.h"
#include "test_lib.h"
#include <stdio.h>
#include <jni.h>
JNIEXPORT jint JNICALL Java_com_My_NativeLib_crypt(JNIEnv * env, jobject obj){


    int status = 0; 
    status = mainCrypto();

    return status;
}

I want to know whether i can call pure C function mainCrypto() from another C file in the way i am doing in this example. I'm not getting any return value and therefore status variable value is not getting updated.

Thanks in advance开发者_开发百科.

Some errors that i'm getting : DEBUG/NDK_NativeLib(3640): [ 09-12 15:58:40.766 3640:0xe38 F//system/bin/app_process ] DEBUG/NDK_NativeLib(3640): stack corruption detected: aborted DEBUG/Zygote(33): Process 3640 terminated by signal (6) INFO/ActivityManager(41): Process com.crypto(pid 3640) has died.


create h file, for example maincrypto.h with follow text

int mainCrypto(void);

in your cpp file with Java_com_My_NativeLib_crypt add #include "maincrypto.h" and thats all


Why would you think you might not be able to call mainCrypto() from some other C function? It seems pretty obvious that there's no reason why you couldn't, however I don't think you would ask the question unless you had reason to think you couldn't. Barring some strange detail you're leaving out, yes, you can call it from other places too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜