c++实现加载so动态库中的资源
实例如下:
#include<stdio.h>
#include<dlfcn.h>
#include<stdlib.h>
#include<iostream>
//编译命令g++-m32EncodeOrDecode.cpp-ldl-oedcode
//名字通过nm-Dxxxxxx.so获取
usingnamespacestd;
intmain(intargc,char**argv){
void*handle=dlopen("./libpub_com_service.so",RTLD_LAZY);
if(!handle){
printf("openlibpuberror,dlerror=%s\n",dlerror());
return-1;
}
stringsrc="05d7151349b7fe9b54306d90f9c938b3";
stringdesKey="pub.%?d5";//58
printf("start..src=[%s].....size=[%d].\n",src.c_str(),src.size());
//encode
typedefstring(*encode_t)(conststringencodeSrc,conststringencodeKey);
encode_tencode=(encode_t)dlsym(handle,"_ZN10NS_PUB_API9DesEncodeESsSs");
if(!encode){
printf("notfoundencodefunction,dlerror=%s\n",dlerror());
dlclose(handle);
return-1;
}
stringencodeStr=encode(src,desKey);
printf("gettheencodefunctionsuccess..encodeStr=[%s].....size=[%d]\n",encodeStr.c_str(),encodeStr.size());
//decode
typedefbool(*decode_t)(conststringdecodeSrc,conststringdecodeKey,string&outResult);
decode_tdecode=(decode_t)dlsym(handle,"_ZN10NS_PUB_API9DesDecodeESsSsRSs");
if(!decode){
printf("notfounddecodefunction,dlerror=%s\n",dlerror());
dlclose(handle);
return-1;
}
stringdecodeOut;
boolret=decode(encodeStr,desKey,decodeOut);
printf("getthedecodefunctionsuccess...ret=[%d]...decodeOut=[%s].....size=[%d]\n",ret,decodeOut.c_str(),decodeOut.size());
//end
dlclose(handle);
return0;
}
以上就是小编为大家带来的c++实现加载so动态库中的资源全部内容了,希望大家多多支持毛票票~
热门推荐
7 简短的二胎祝福语
10 简短霸气女儿生日 祝福语
11 祝福语高考小众诗句简短
12 元旦祝福语20秒简短
13 老师过年祝福语大全 简短
14 一生祝福语简短
15 产检祝福语简短霸气
16 朋友店开张祝福语简短
17 生日爱情祝福语大全简短
18 朋友女儿生日祝福语 简短