使用 ACE_Service_Object
我正在尝试使用 ACE_Service_Object 或 ACE_Shared_Object。我不确定哪一个适用。我试图将一些功能封装在 DLL 中,以便 DLL 的使用者打开该库,创建导出类的实例,调用该类的一些函数,然后销毁该类。某种基本的插件架构。使用 ACE 类来解决这个问题的最佳方法是什么?它们似乎封装了很多 DLL 加载、查找和加载的过程。卸载细节,这会很好用。
下面的代码基本上是我想使用 ACE 类来模拟的代码。
void* handle = dlopen("./libdllbaseclass.so", RTLD_LAZY);
DllBaseClass* (*create)();
void (*destroy)(DllBaseClass*);
create = (DllBaseClass* (*)())dlsym(handle, "create_object");
destroy = (void (*)(DllBaseClass*))dlsym(handle, "destroy_object");
DllBaseClass* myClass = (DllBaseClass*)create();
myClass->DoSomething();
destroy( myClass );
I'm trying to use the ACE_Service_Object or the ACE_Shared_Object. I'm not sure which one is applicable. I'm trying to encapsulate some functionality in a DLL so a consumer of the DLL would open the library, create an instance of the exported class, call some functions on the class, and then destroy the class. A basic plug-in architecture of sorts. What would be the best way to go about this using the ACE classes. They seem to wrap a lot of the DLL loading, lookup & unloading minutia, which would be nice to use.
The code below is basically what I want to mimic using the ACE classes.
void* handle = dlopen("./libdllbaseclass.so", RTLD_LAZY);
DllBaseClass* (*create)();
void (*destroy)(DllBaseClass*);
create = (DllBaseClass* (*)())dlsym(handle, "create_object");
destroy = (void (*)(DllBaseClass*))dlsym(handle, "destroy_object");
DllBaseClass* myClass = (DllBaseClass*)create();
myClass->DoSomething();
destroy( myClass );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只需要加载、卸载和调用共享库中的某些函数,则可以使用 ACE_DLL 类。这就是 ACE_Shared_Object 最终在幕后使用的内容。
If all you need is to load, unload, and call some functions in a shared library, you could use the ACE_DLL class instead. That's what ACE_Shared_Object ends up using under the covers.