I have a server which takes some messages x and outputs some messages Y. Currently the x to y mapping is fixed. So x1 will always generate y1 with corresponding fields.
But now I want to be able to make it configurable such that the users can put their own dll which will generate x1 to y2, y3, or however they want. In case if they don't handle it then it should take a default mapping which is x1 to y1.
One more thing is most of my output messages y1, y2 , y3 are already existing objects which are all derived from a base class. And I want to be able to do the same thing the other way around...meaning y2(incoming message) to be converted to x1 depending on the user dll. Can w开发者_运维问答e accomplish this using DLLs? or is there a better way of doing this?? Is there a design pattern(factory pattern or something) to do this correctly so that it is flexible in future also. Thanks!!!
This is not too hard, but you will need to provide an interface header (.h file) to DLL writers. You'll also need to tell them which compiler to use, or use a COM-compatible interface.
A quick sketch would be an interface that provides
- A
queryTypesSupported
function, provided by the DLL and called by the EXE to determine the types supported - A
std::auto_ptr<Ybase> processMessage(Xbase&)
function, implemented by the DLL for the actual processing. - A
virtual std::string Ybase::serialize() const
function to turn the message into text.
COM and predefined interfaces should be your first direction of research. You define Interfaces and some kind of registering mechanism. The user creates his own COM Objects that use your interfaces. Then he registers his objects and your application can use them.
A different approach might be using .NET-dlls and C++/CLI for the interface in your application.
I don't know any other portable way for dlls and C++-Objects (portable across compilers).
精彩评论