Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #82652 > unrolled thread

plugin design problem

Started byalessio211734 <alessio211734@yahoo.it>
First post2021-12-16 03:24 -0800
Last post2021-12-16 14:22 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.c++


Contents

  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

#82652 — plugin design problem

Fromalessio211734 <alessio211734@yahoo.it>
Date2021-12-16 03:24 -0800
Subjectplugin design problem
Message-ID<66035e91-eaab-45ca-b952-08de4857ca7an@googlegroups.com>
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?

[toc] | [next] | [standalone]


#82654

FromPaavo Helde <eesnimi@osa.pri.ee>
Date2021-12-16 14:22 +0200
Message-ID<spfb1a$llh$1@dont-email.me>
In reply to#82652
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.





[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web