c++实现加载so动态库中的资源
2016-12-31 10:12
711 查看
实例如下:
#include <stdio.h> #include <dlfcn.h> #include <stdlib.h> #include <iostream> //编译命令 g++ -m32 EncodeOrDecode.cpp -ldl -o edcode //名字通过nm -D xxxxxx.so获取 using namespace std; int main(int argc,char **argv){ void *handle = dlopen("./libpub_com_service.so",RTLD_LAZY); if(!handle){ printf("open libpub error ,dlerror=%s\n",dlerror()); return -1; } string src = "05d7151349b7fe9b54306d90f9c938b3"; string desKey = "pub.%?d5";//58 printf("start ..src=[%s].....size=[%d].\n",src.c_str(),src.size()); //encode typedef string (*encode_t)(const string encodeSrc,const string encodeKey); encode_t encode = (encode_t)dlsym(handle,"_ZN10NS_PUB_API9DesEncodeESsSs"); if(!encode){ printf("not found encode function ,dlerror= %s \n",dlerror()); dlclose(handle); return -1; } string encodeStr = encode(src,desKey); printf("get the encode function success ..encodeStr=[%s].....size=[%d]\n",encodeStr.c_str(),encodeStr.size()); //decode typedef bool (*decode_t)(const string decodeSrc,const string decodeKey,string &outResult); decode_t decode = (decode_t)dlsym(handle,"_ZN10NS_PUB_API9DesDecodeESsSsRSs"); if(!decode){ printf("not found decode function ,dlerror= %s \n",dlerror()); dlclose(handle); return -1; } string decodeOut; bool ret = decode(encodeStr,desKey,decodeOut); printf("get the decode function success ...ret=[%d]...decodeOut=[%s].....size=[%d]\n",ret,decodeOut.c_str(),decodeOut.size()); //end dlclose(handle); return 0; }
以上就是小编为大家带来的c++实现加载so动态库中的资源全部内容了,希望大家多多支持脚本之家~
相关文章推荐
- c++ 加载so动态库中的资源
- C++Linux平台动态加载类库实现类
- 在Unity3D的网络游戏中实现资源动态加载
- (转)在Unity3D的网络游戏中实现资源动态加载
- [转]在Unity3D的网络游戏中实现资源动态加载
- Unity3D的网络游戏中实现资源动态加载
- 在Unity3D的网络游戏中实现资源动态加载
- c++动态加载dll中的类(用于实现依据字符串类名创建对象)
- C++ 动态分配资源的自动释放 – auto_ptr的实现原理
- 在Unity3D的网络游戏中实现资源动态加载
- android动态加载.so,实现动态库升级
- 在Unity3D的网络游戏中实现资源动态加载
- ]Unity3D实现动态加载游戏资源(转)
- 【转】在Unity3D的网络游戏中实现资源动态加载
- [转]用C++面向对象的方式动态加载so
- 在Unity3D的网络游戏中实现资源动态加载
- Unity3D 网游中实现资源动态加载 。。手游消减内存必备。。。
- unity基础开发--实现动态加载资源
- Unity3D的网络游戏中实现资源动态加载
- 在Unity3D的网络游戏中实现资源动态加载