Is it possible to do object-oriented API via a DLL (GCC, C++)?

0 like 0 dislike
7 views
Good afternoon.
The next question is, suppose there is an abstract application that wants to add some API for plugins. Plug-ins are likely to represent the DLL's that are dynamically loaded core code.
In Java you can make an interface IPlugin, and the plugin to extend it: public class MySuperPlugin implements IPlugin, and then quietly load thousands of classes by name. Is it possible to do something similar in C++? I know that you can safely load normal functions (not class members) from a DLL. While I think of only these crutches: make many functions of "adapters," each of which calls the appropriate member class. But it's terrible.
How to solve? In fact, probably possible.
by | 7 views

2 Answers

0 like 0 dislike
. To do this, write a normal function like:
\r
extern "C" IPlugin * getPluginInterface() { return new Plugin(); } 

\r
If the code for Windows you need to add __declspec (dllexport) after extern "C".
And that's all. You can now load the library dynamically, and ask the address of the function by name using dlsym( Linux ), for Windows I do not remember.
by
0 like 0 dislike
Yes, just done everything. Make an abstract class, make the most of these factory classes, and she already wants creates them and from any lib.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
28,758 users