• plugin design problem

    From alessio211734@21:1/5 to All on Thu Dec 16 03:24:29 2021
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paavo Helde@21:1/5 to All on Thu Dec 16 14:22:01 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)