wxPluginManager and wxPluginLibrary Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
farocam
Knows some wx things
Knows some wx things
Posts: 44
Joined: Mon Mar 13, 2006 7:07 pm
Location: Montevideo, Uruguay

wxPluginManager and wxPluginLibrary

Post by farocam »

I
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Post by New Pagodi »

Hello. I
Last edited by New Pagodi on Thu Jun 22, 2006 6:32 pm, edited 1 time in total.
farocam
Knows some wx things
Knows some wx things
Posts: 44
Joined: Mon Mar 13, 2006 7:07 pm
Location: Montevideo, Uruguay

Post by farocam »

1) What about the wxPluginLibrary and wxPluginManager classes? Where can I find the code for those?

2) Can I put this LoadPlugins() in the frame class (say, in a button) rather than in the wxApp class?

3)I'm developing with MVS6.0... where should I use the wxUSE_DYNLIB_CLASS ?

4)My dll is created out of a .h a .cpp and a .def files in a dll project... Should that be enough?
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE »

Hi!
farocam wrote:1) What about the wxPluginLibrary and wxPluginManager classes? Where can I find the code for those?
WXDIR/include/wx/dynload.h
WXDIR/src/common/dynload.cpp
farocam wrote:2) Can I put this LoadPlugins() in the frame class (say, in a button) rather than in the wxApp class?
Yes, there is nothing wxApp specific about this.
farocam wrote:3)I'm developing with MVS6.0... where should I use the wxUSE_DYNLIB_CLASS ?
Using the standard config you don't have to do anything, it's already defined. Have a look at WXDIR/include/wx/msw/setup.h.
By the way: For wxPlugin* wxUSE_DYNAMIC_LOADER has to be defined.
But apart from having a "simpler" interface I don't see why you should use these in favor of wxDynamicLibrary.
farocam wrote:4)My dll is created out of a .h a .cpp and a .def files in a dll project... Should that be enough?
In general, yes.
Your DLL will have to export the relevant functions. You will need to link your DLL with wxWidgets, if the DLL uses wxWidgets which I guess it does.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Post by New Pagodi »

upCASE wrote:
farocam wrote:3)I'm developing with MVS6.0... where should I use the wxUSE_DYNLIB_CLASS ?
Using the standard config you don't have to do anything, it's already defined. Have a look at WXDIR/include/wx/msw/setup.h.
Woops! I guess I misunderstood the comments in the documentation for wxDynamicLibrary here. The project compiles ok without that define. Sorry about that.

On another note, it seems that my LoadPlugins function wont work after all. I could have sworn it was working last night, but it
farocam
Knows some wx things
Knows some wx things
Posts: 44
Joined: Mon Mar 13, 2006 7:07 pm
Location: Montevideo, Uruguay

Post by farocam »

If I send you a brief summary of my classes and the hello world method I wish to load in the app ... will you have time to check it? The thing is that my library loads fine and so does the GetSymbol function ...but I don't know how to access the plugin class object nor its methods ...
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Re: wxPluginManager and wxPluginLibrary

Post by benedicte »

[quote="farocam"]...

I
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Post by New Pagodi »

farocam wrote:If I send you a brief summary of my classes and the hello world method I wish to load in the app ... will you have time to check it? The thing is that my library loads fine and so does the GetSymbol function ...but I don't know how to access the plugin class object nor its methods ...
Here is another sample (at this point very, very loosely based on the original) that will hopefully be more helpful to you. The plugin consists of a simple panel with one text control. There are three parts: the library header, the library body, and the main application body.

Here
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Post by New Pagodi »

farocam wrote:nor its methods ...
Since you brought this up, I might as well explain a curious part in the library header:

Code: Select all

 #include <wx/dynlib.h> 
#include <wx/dynload.h> 
#define ID_DEFAULT -1 // Default 

class PluginBase : public wxPanel{ 
  public: 
        virtual void SetParent(wxWindow* parent)=0; 
}; 

class PanelPlugin : public PluginBase{ 
  public: 
        DECLARE_DYNAMIC_CLASS(PanelPlugin) 
        void SetParent(wxWindow* parent); 

  protected: 
    wxTextCtrl *m_textCtrl1; 
};
Why do we have to define the PluginBase class? If we took that class out, then because of the
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE »

I think there might be even more to this topic. I can't get any example working and I suspect it's due to me linking to a static C runtime, nit the DLL one.

Anyway, when I find some time I'll see if I can create an example using a wxWidgets host and plugin that uses only wxDynamicLibrary and a simple general plugin interface that would allow the app the create an instance of the DLL classes without using the RTTI system.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
farocam
Knows some wx things
Knows some wx things
Posts: 44
Joined: Mon Mar 13, 2006 7:07 pm
Location: Montevideo, Uruguay

Post by farocam »

New Pagodi,

Thanks for your time and your code. I've tried to add it into my projects and I have some doubts. I've built the dll, but some details in you aplication make me thinks it's not a real plug in:


Code: Select all

#include //enter the name of the library header here
I wouldn't be able to do that if, say, for example I have my application working and I want to create a new plug in, would I? I mean that the host would already be compiled and I would not be able to modify it's code... That brings us to another detail:

Code: Select all

//constructor in other ways.
    PanelPlugin *object =(PanelPlugin*) wxCreateDynamicObject("PanelPlugin");

    //Now that we have our panel object, we set it's parent the be the main form.
that's part of the LoadPlugIn() method. Again, I would not be able to write
PanelPlugin since my app would already be compiled, so I must be able to create that object without writine in code the name of the class.
Do you know how can I do this ?

Thanks!
Fabian
farocam
Knows some wx things
Knows some wx things
Posts: 44
Joined: Mon Mar 13, 2006 7:07 pm
Location: Montevideo, Uruguay

Post by farocam »

Besides, the line

Code: Select all

object->SetParent(this);
causes my application to crash with a fatal error... :cry:
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Post by New Pagodi »

farocam wrote:New Pagodi,

Thanks for your time and your code. I've tried to add it into my projects and I have some doubts. I've built the dll, but some details in you aplication make me thinks it's not a real plug in:


Code: Select all

#include //enter the name of the library header here
I wouldn't be able to do that if, say, for example I have my application working and I want to create a new plug in, would I? I mean that the host would already be compiled and I would not be able to modify it's code... That brings us to another detail:

Code: Select all

//constructor in other ways.
    PanelPlugin *object =(PanelPlugin*) wxCreateDynamicObject("PanelPlugin");

    //Now that we have our panel object, we set it's parent the be the main form.
that's part of the LoadPlugIn() method. Again, I would not be able to write
PanelPlugin since my app would already be compiled, so I must be able to create that object without writine in code the name of the class.
Do you know how can I do this ?

Thanks!
Fabian
All good points. I was trying to keep the example as simple as possible (and simply made a few mistakes). Technically what we should do is split the library headers like this.

Generic plugin header:

Code: Select all

 #include <wx/dynlib.h> 
#include <wx/dynload.h> 

class PluginBase : public wxPanel{ 
  public: 
        virtual void SetParent(wxWindow* parent)=0; 
}; 
The specific header for this panel plugin:

Code: Select all

#include //enter the name of the generic plugin header here
#define ID_DEFAULT -1 // Default 

class PanelPlugin : public PluginBase{ 
  public: 
        DECLARE_DYNAMIC_CLASS(PanelPlugin) 
        void SetParent(wxWindow* parent); 

  protected: 
    wxTextCtrl *m_textCtrl1; 
};
Then make the following changes to the body for this panel plugin:

Code: Select all

change: #include //enter the name of the library header here
to:     #include //enter the name for header for the panel plugin 
finally make the following changes to the main application body:

Code: Select all

change: #include //enter the name of the library header here
to:     #include //enter the name of the genaric plugin header here

and 

change: PanelPlugin *object =(PanelPlugin*) wxCreateDynamicObject("PanelPlugin"); 
to:     PluginBase *object =(PluginBase*) wxCreateDynamicObject("PanelPlugin");
You should have the generic plugin header when you write the main application (even if you havn
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Post by New Pagodi »

farocam wrote:Besides, the line

Code: Select all

object->SetParent(this);
causes my application to crash with a fatal error... :cry:
Doh! It works for me. Try replacing all the code in the body of SetParent with

Code: Select all

wxLogWarning("The method can be called successfully.");
and rebuilding the dll. If you can get the message, when the main application is run, then there is something in the body that is causing the error. I can
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Post by New Pagodi »

upCASE wrote:I think there might be even more to this topic. I can't get any example working and I suspect it's due to me linking to a static C runtime, nit the DLL one.

Anyway, when I find some time I'll see if I can create an example using a wxWidgets host and plugin that uses only wxDynamicLibrary and a simple general plugin interface that would allow the app the create an instance of the DLL classes without using the RTTI system.
That would be great. I
Post Reply