## wxModule

The module system is a very simple mechanism to allow applications (and parts of wxWindows itself) to define initialization and cleanup functions that are automatically called on wxWindows 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, wxWindows will find all classes derived from wxModule, create an instance of each, and call each OnInit function. On exit, wxWindows 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
      {
      DECLARE_DYNAMIC_CLASS(wxDDEModule)
      public:
          wxDDEModule() {}
          bool OnInit() { wxDDEInitialize(); return TRUE; };
          void OnExit() { wxDDECleanUp(); };
      };

      IMPLEMENT_DYNAMIC_CLASS(wxDDEModule, wxModule)

Derived from

wxObject

Include files

<wx/module.h>

Members

wxModule::wxModule
wxModule::~wxModule
wxModule::CleanupModules
wxModule::Exit
wxModule::Init
wxModule::InitializeModules
wxModule::OnExit
wxModule::OnInit
wxModule::RegisterModule
wxModule::RegisterModules

### wxModule::wxModule

wxModule()

Constructs a wxModule object.

### wxModule::~wxModule

~wxModule()

Destructor.

### wxModule::CleanupModules

static void CleanupModules()

Calls Exit for each module instance. Called by wxWindows on exit, so there is no need for an application to call it.

### wxModule::Exit

void Exit()

Calls OnExit. This function is called by wxWindows and should not need to be called by an application.

### wxModule::Init

bool Init()

Calls OnInit. This function is called by wxWindows and should not need to be called by an application.

### wxModule::InitializeModules

static bool InitializeModules()

Calls Init for each module instance. Called by wxWindows on startup, so there is no need for an application to call it.

### 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, wxWindows will exit immediately.

### wxModule::RegisterModule

static void RegisterModule(wxModule* module)

Registers this module with wxWindows. Called by wxWindows on startup, so there is no need for an application to call it.

### wxModule::RegisterModules

static bool RegisterModules()

Creates instances of and registers all modules. Called by wxWindows on startup, so there is no need for an application to call it.