Answer the question
In order to leave comments, you need to log in
Is it possible to make an object-oriented API through a DLL (GCC, C++)?
Good afternoon.
The question is the following - let there be an abstract application to which you want to add some API for plugins. Plugins will most likely be DLLs that are dynamically loaded by the main code.
In Java, you can make an IPlugin interface, and extend it in a plugin: public class MySuperPlugin implements IPlugin , after which you can easily load thousands of classes by name. Is it possible to do something similar in C++? I know that you can safely load regular functions (not class members) from a DLL. So far, only such crutches have been invented: we make many functions of “adapters”, each of which calls the corresponding member of the class. But this is horror.
How to decide? After all, it's probably possible.
Answer the question
In order to leave comments, you need to log in
Can. To do this, you need to write a regular function like:
extern "C" IPlugin * getPluginInterface()
{
return new Plugin();
}
Yes, that's exactly how it's done. We make an abstract class, we make a factory of these very classes, and she already creates them as she wants and from any libs.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question