Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #82654
| From | Paavo Helde <eesnimi@osa.pri.ee> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: plugin design problem |
| Date | 2021-12-16 14:22 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <spfb1a$llh$1@dont-email.me> (permalink) |
| References | <66035e91-eaab-45ca-b952-08de4857ca7an@googlegroups.com> |
16.12.2021 13:24 alessio211734 kirjutas:
> Hello,
> i would like store a single plugin for every dll.
> All plugin have a same interface.
>
> For example suppose that every plugin (dll) have two C style function:
> void mousePressed(int x, int y, OpenglContex * context)
> void mouseMove(int x, int y, OpenglContex * context)
>
> I would like remap c function extract from every dll on different class Plugin1 and Plugin2
>
> class Plugin
> {
> public:
> Plugin() {};
> virtual void mousePressEvent(GLWidget* widget, QMouseEvent *event)=0;
> virtual void mouseMoveEvent(GLWidget* widget, QMouseEvent *event)=0;
> ....
> };
>
> and other subclass as
>
> class Plugin1: public Plugin
> {
> // remap on dll 1
> }
>
> class Plugin2: public Plugin
> {
> // remap on dll2
> }
>
> Any idea how to solve my problem?
> It's possibile declare function pointer in the Plugin1 or Plugin2 class and
> call them from method?
Sure, but this is platform-specific. As you are speaking about DLL-s, I
assume Windows and MSVC. Also, the term "plugin" is normally used for
additional components loaded explicitly at run-time, so I also assume
this is what you want here.
In the plugin DLL, you need to define the function with extern "C" and
__declspec(dllexport):
extern "C" __declspec(dllexport) void mousePressed(int x, int y,
OpenglContex * context) {
/* ... */
}
Inside the function, one can still use C++, the extern "C" bit is just
needed to avoid name mangling, so that one can look up the function by
its simple name.
In the main app, you load the plugin DLL via LoadLibraryW() or
LoadLibraryExW(), then look up the function in it with GetProcAddress().
The result will need to be cast to a function pointer type with the
correct signature. And voila, now you can call this function via this
pointer.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
plugin design problem alessio211734 <alessio211734@yahoo.it> - 2021-12-16 03:24 -0800 Re: plugin design problem Paavo Helde <eesnimi@osa.pri.ee> - 2021-12-16 14:22 +0200
csiph-web