## wxModule

The module system is a very simple mechanism to allow applications (and parts of wxWidgets itself) to define initialization and cleanup functions that are automatically called on wxWidgets startup and exit.

To define a new kind of module, derive a class from wxModule, override the OnInit and OnExit functions, and add the DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS to header and implementation files (which can be the same file). On initialization, wxWidgets will find all classes derived from wxModule, create an instance of each, and call each OnInit function. On exit, wxWidgets will call the OnExit function for each module instance.

Note that your module class does not have to be in a header file.

For example:

      // A module to allow DDE initialization/cleanup
      // without calling these functions from app.cpp or from
      // the user's application.
      class wxDDEModule: public wxModule
      {
      public:
          wxDDEModule() { }
          virtual bool OnInit() { wxDDEInitialize(); return true; };
          virtual void OnExit() { wxDDECleanUp(); };

      private:
          DECLARE_DYNAMIC_CLASS(wxDDEModule)
      };

      IMPLEMENT_DYNAMIC_CLASS(wxDDEModule, wxModule)

      // Another module which uses DDE in its OnInit()
      class MyModule: public wxModule
      {
      public:
          wxDDEModule() { AddDependency(CLASSINFO(wxDDEModule)); }
          virtual bool OnInit() { ... code using DDE ... }
          virtual void OnExit() { ... }

      private:
          DECLARE_DYNAMIC_CLASS(wxDDEModule)
      };

Derived from

wxObject

Include files

<wx/module.h>

Members

wxModule::wxModule
wxModule::~wxModule
wxModule::AddDependency
wxModule::OnExit
wxModule::OnInit

### wxModule::wxModule

wxModule()

Constructs a wxModule object.

### wxModule::~wxModule

~wxModule()

Destructor.

### wxModule::AddDependency

void AddDependency(wxClassInfo * dep)

Call this function from the constructor of the derived class. dep must be the CLASSINFO of a wxModule-derived class and the corresponding module will be loaded before and unloaded after this module.

Note that circular dependencies are detected and result in a fatal error.

Parameters

dep

The class information object for the dependent module.

### wxModule::OnExit

virtual void OnExit()

Provide this function with appropriate cleanup for your module.

### wxModule::OnInit

virtual bool OnInit()

Provide this function with appropriate initialization for your module. If the function returns false, wxWidgets will exit immediately.