android jni 动态加载so动态库中函数

android jni 动态加载so动态库中函数。
思路:
1、懒加载so库。

void *handle=dlopen("libpboxcipher.so",RTLD_LAZY);//使用懒加载模式

2、定义函数指针。

typedef int (*Testfilelen)(unsigned char *filepath, int filepathlen,unsigned char *prikey, int prikeylen,int *fp,unsigned int *outlen,unsigned char*key,int *keylen);

定义返回类型和参数类型个数都要对应。

3、使用dlsym加载函数,强转函数指针为定义类型。

Testfilelen testfilelen=(Testfilelen)dlsym(handle, "testfilelen");

4、关闭so库调用handle。

dlclose(handle);

直接使用函数指针即可调用:

ret=testfilelen((unsigned char *) jmfile, filepathlen, (unsigned char *) priKey, prikeylen, &fp, &outlen, outkey, &outkeylen);

引用的头文件是:

#include <dlfcn.h>
发布了187 篇原创文章 · 获赞 65 · 访问量 26万+

猜你喜欢

转载自blog.csdn.net/mhhyoucom/article/details/104166396