Ai
1 Star 1 Fork 1

py-zxj-free/dllload

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test.cpp 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
py-zxj-free 提交于 2021-05-22 09:48 +08:00 . 'V1.0'
#include "register.h"
#include <stdint.h>
#include <iostream>
#include <string>
//g++ -o test dlload.cpp register.cpp test.cpp -ldl
int main(int argc, char **argv) {
RegisterM *rm = new RegisterM();
int ret = rm->registerObject("test","./test.so");
if (ret>0)
{
std::cout<<"registerObject success"<<std::endl;
create_t* create_instance = rm->getInstance("test");
if (NULL!=create_instance)
{
std::cout<<"getInstance success"<<std::endl;
MetaObject* _instance = create_instance();
int _sum = _instance->add(7,8);
std::cout<<"sum="<<_sum<<std::endl;
_instance->setVal(15);
std::cout<<"_instance->val="<<_instance->getVal()<<std::endl;
void (*pa)(int a);
*(void**)(&pa) = rm->getFunc("test","testfunc01");
pa(6);
int (*fa)(int a);
*(void**)(&fa) = rm->getFunc("test","testfunc02");
std::cout<<"fa(5)="<<fa(5)<<std::endl;
destroy_t* destroy_instance = rm->rmInstance("test");
if (NULL!=destroy_instance)
{
std::cout<<"rmInstance success"<<std::endl;
destroy_instance(_instance);
}
}
bool re = rm->unregisterObject("test");
if (re)
{
std::cout<<"unregisterObject success"<<std::endl;
}
}
return 0;
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/pyzxjfree/dllload.git
git@gitee.com:pyzxjfree/dllload.git
pyzxjfree
dllload
dllload
master

搜索帮助