Using ACE_Service_Object
I'm trying to use the ACE_S开发者_JS百科ervice_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 );
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.
精彩评论