Re: plugin calling code in main app

"'Andreas Mohr' via wx-users" <[email protected]> Sun, 15 Feb 2026 12:44:58 +0100
Newsgroups gmane.comp.lib.wxwindows.general
Message-ID <[email protected]>
Hello Alessandro,

> Thank you Andreas for your answer. I find what you write too "theoretical".
> What I need is a practical example, possibly based on my mockup project,
> possibly using wxWidgets macros and idioms, to illustrate how plugin code
> can call any C++ class code from the main host application. This seems to
> happen "automagically" in Objective-C.

The relevant area appears to be:

+int SamplePlugin::filterImage(wxString & menuName)
+{
+    wxLogDebug("%s %s(%s)", __FILE__, __FUNCTION__, menuName);
+#if 1
+    gui_view2D *currentViewer = nullptr;
+#else
+    // FIXME: @@@ ISSUE 3 @@@
+
+    // How to make this work ?
+    //gui_view2D *currentViewer = new gui_view2D(nullptr);
+
+    // How to make this work ?
+    gui_view2D *currentViewer = this->duplicateCurrent2DViewerWindow();
+#endif
+    return 0;
+}


I am now ignoring the aspect that
this is consuming a whoppin' GUI toolkit dependency in plugin library scope
(===> SoC issue?).


So, given implementation status quo, the simplest way possibly is to
inject an interface [parameter] to pluginBase ctor *),
and that interface would provide a method to
get a view (perhaps existing, or created).

And that interface would then "of course" need to be
implemented for real somewhere (e.g. in app scope, as you said).

*) or, if need be, initPlugin() - but such handling would be awkward (instance-state-confusion-hampered) "two-stage construction" stuff




So (pseudo code):


struct IPluginGetCurrentViewer
{
public:
  virtual ~IPluginGetCurrentViewer() = 0;

  virtual gui_view2D *GetCurrentViewer() = 0;
};


class PluginGetCurrentViewer_App : public IPluginGetCurrentViewer
{
public:
  virtual gui_view2D *GetCurrentViewer() override
  {
    return new gui_view2D(nullptr);
  }
};



std::unique_ptr<IPluginGetCurrentViewer> GetIPluginGetCurrentViewer(App *SomeGlobalStateCraptasticsRefActivityIfOhSoNeedBe)
{
  return std::make_unique<PluginGetCurrentViewer>(SomeGlobalStateCraptasticsRefActivityIfOhSoNeedBe);
}



auto plugin = std::make_unique<PluginBase>(GetIPluginGetCurrentViewer(...));






Though this current implementation would do (thus, consume) a million things more than
ideally one would want to have done by
such plain/raw plugin interface mechanics, if one can help it.
(SoC)


HTH & HAND,

Andreas Mohr

-- 
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
--- 
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/wx-users/aZGxuhoFejMfj0Eq%40rhlx01.hs-esslingen.de.